diff --git a/404.html b/404.html index 4dd45a5a..2ad3008a 100644 --- a/404.html +++ b/404.html @@ -15,7 +15,7 @@
Skip to content

404

PAGE NOT FOUND

But if you don't change your direction, and if you keep looking, you may end up where you are heading.

MIT Licensed

- + \ No newline at end of file diff --git a/assets/dev_test.md.bJiHCdLJ.js b/assets/dev_test.md.bJiHCdLJ.js new file mode 100644 index 00000000..03ff5fba --- /dev/null +++ b/assets/dev_test.md.bJiHCdLJ.js @@ -0,0 +1,9 @@ +import{_ as s,c as i,o as a,V as t}from"./chunks/framework.--NMbU3Q.js";const g=JSON.parse('{"title":"@liuli-util/test","description":"","frontmatter":{},"headers":[],"relativePath":"dev/test.md","filePath":"dev/test.md"}'),n={name:"dev/test.md"},e=t(`

@liuli-util/test

辅助其他模块测试的工具函数库

initTempPath

初始化一个临时目录,返回目录路径

ts
import { it } from 'vitest'
+import { initTempPath } from '@liuli-util/test'
+import fs from 'fs'
+
+const tempPath = initTempPath(__filename)
+
+it('Test initTempPath', () => {
+  expect(fs.existsSync(tempPath)).true
+})
`,5),l=[e];function h(p,k,r,d,E,o){return a(),i("div",null,l)}const y=s(n,[["render",h]]);export{g as __pageData,y as default}; diff --git a/assets/dev_test.md.bJiHCdLJ.lean.js b/assets/dev_test.md.bJiHCdLJ.lean.js new file mode 100644 index 00000000..b5c53ea7 --- /dev/null +++ b/assets/dev_test.md.bJiHCdLJ.lean.js @@ -0,0 +1 @@ +import{_ as s,c as i,o as a,V as t}from"./chunks/framework.--NMbU3Q.js";const g=JSON.parse('{"title":"@liuli-util/test","description":"","frontmatter":{},"headers":[],"relativePath":"dev/test.md","filePath":"dev/test.md"}'),n={name:"dev/test.md"},e=t("",5),l=[e];function h(p,k,r,d,E,o){return a(),i("div",null,l)}const y=s(n,[["render",h]]);export{g as __pageData,y as default}; diff --git a/assets/en_dev_test.md.zIYD7Ymp.js b/assets/en_dev_test.md.zIYD7Ymp.js new file mode 100644 index 00000000..14ba9df9 --- /dev/null +++ b/assets/en_dev_test.md.zIYD7Ymp.js @@ -0,0 +1,9 @@ +import{_ as s,c as i,o as a,V as t}from"./chunks/framework.--NMbU3Q.js";const g=JSON.parse('{"title":"@liuli-util/test","description":"","frontmatter":{},"headers":[],"relativePath":"en/dev/test.md","filePath":"en/dev/test.md"}'),n={name:"en/dev/test.md"},e=t(`

@liuli-util/test

Utility function library for assisting in testing other modules.

initTempPath

Initialize a temporary directory and return its path.

ts
import { it } from 'vitest'
+import { initTempPath } from '@liuli-util/test'
+import fs from 'fs'
+
+const tempPath = initTempPath(__filename)
+
+it('Test initTempPath', () => {
+  expect(fs.existsSync(tempPath)).true
+})
`,5),l=[e];function h(p,k,r,d,o,E){return a(),i("div",null,l)}const y=s(n,[["render",h]]);export{g as __pageData,y as default}; diff --git a/assets/en_dev_test.md.zIYD7Ymp.lean.js b/assets/en_dev_test.md.zIYD7Ymp.lean.js new file mode 100644 index 00000000..372338d1 --- /dev/null +++ b/assets/en_dev_test.md.zIYD7Ymp.lean.js @@ -0,0 +1 @@ +import{_ as s,c as i,o as a,V as t}from"./chunks/framework.--NMbU3Q.js";const g=JSON.parse('{"title":"@liuli-util/test","description":"","frontmatter":{},"headers":[],"relativePath":"en/dev/test.md","filePath":"en/dev/test.md"}'),n={name:"en/dev/test.md"},e=t("",5),l=[e];function h(p,k,r,d,o,E){return a(),i("div",null,l)}const y=s(n,[["render",h]]);export{g as __pageData,y as default}; diff --git a/assets/en_index.md.prNKhQEC.js b/assets/en_index.md.prNKhQEC.js new file mode 100644 index 00000000..f391ce13 --- /dev/null +++ b/assets/en_index.md.prNKhQEC.js @@ -0,0 +1 @@ +import{_ as e,c as t,o}from"./chunks/framework.--NMbU3Q.js";const m=JSON.parse(`{"title":"","description":"","frontmatter":{"layout":"home","hero":{"name":"liuli-tools","text":"Liuli's Development Toolkit","tagline":"A collection of libraries and developer tools developed as needed.","image":{"src":"/logo.png","alt":"liuli-tools"},"actions":[{"theme":"brand","text":"dev","link":"/en/dev/create-liuli"},{"theme":"alt","text":"lib","link":"/en/lib/tree"}]},"footer":"MIT Licensed | Copyright © 2021-present rxliuli"},"headers":[],"relativePath":"en/index.md","filePath":"en/index.md"}`),i={name:"en/index.md"};function n(l,a,r,s,d,c){return o(),t("div")}const x=e(i,[["render",n]]);export{m as __pageData,x as default}; diff --git a/assets/en_index.md.prNKhQEC.lean.js b/assets/en_index.md.prNKhQEC.lean.js new file mode 100644 index 00000000..f391ce13 --- /dev/null +++ b/assets/en_index.md.prNKhQEC.lean.js @@ -0,0 +1 @@ +import{_ as e,c as t,o}from"./chunks/framework.--NMbU3Q.js";const m=JSON.parse(`{"title":"","description":"","frontmatter":{"layout":"home","hero":{"name":"liuli-tools","text":"Liuli's Development Toolkit","tagline":"A collection of libraries and developer tools developed as needed.","image":{"src":"/logo.png","alt":"liuli-tools"},"actions":[{"theme":"brand","text":"dev","link":"/en/dev/create-liuli"},{"theme":"alt","text":"lib","link":"/en/lib/tree"}]},"footer":"MIT Licensed | Copyright © 2021-present rxliuli"},"headers":[],"relativePath":"en/index.md","filePath":"en/index.md"}`),i={name:"en/index.md"};function n(l,a,r,s,d,c){return o(),t("div")}const x=e(i,[["render",n]]);export{m as __pageData,x as default}; diff --git a/dev/create-liuli.html b/dev/create-liuli.html index f984934f..04365694 100644 --- a/dev/create-liuli.html +++ b/dev/create-liuli.html @@ -17,9 +17,9 @@ -
Skip to content

create-liuli

个人使用的创建 lib/cli 的模版应用创建程序,使用方法

bash
pnpm create liuli
+    
Skip to content

create-liuli

个人使用的创建 lib/cli 的模版应用创建程序,使用方法

bash
pnpm create liuli
 # 然后根据提示输入项目名称和类型就好了

目前支持的类型包括

  • lib: 创建一个 lib 模版,基于 vite/vitest 构建,提供正确的 exports 配置,默认仅支持 esm
  • cli: 创建一个 cli 模版,基于 vite/vitest/vite-node 构建,默认支持 esm

计划支持的模版

  • [ ] preact web 应用
  • [ ] vscode 插件
  • [ ] chrome 插件
  • [ ] nodejs 服务
  • [ ] userscript
  • [ ] electron 应用

MIT Licensed

- + \ No newline at end of file diff --git a/dev/rollup-plugin-i18next-dts-gen.html b/dev/rollup-plugin-i18next-dts-gen.html index f32dd83b..dd2f9551 100644 --- a/dev/rollup-plugin-i18next-dts-gen.html +++ b/dev/rollup-plugin-i18next-dts-gen.html @@ -17,7 +17,7 @@ -
Skip to content

@liuli-util/rollup-plugin-i18next-dts-gen

场景

吾辈有一些项目需要使用 i18next 来处理国际化,但是使用 typescript 需要有类型定义,所以实现了 @liuli-util/i18next-dts-gen 用来自动生成 .d.ts 文件。但之后吾辈发现可以将这个过程集成到构建中,不再需要额外单独启动一个终端命令,目前支持直接集成到 rollup/vite 的构建流程中。

安装

sh
pnpm i -D i18next @liuli-util/rollup-plugin-i18next-dts-gen

添加翻译文件

src/i18n/ 下添加翻译的 json 文件,下面添加两个示例

json
// src/i18n/en-US.json
+    
Skip to content

@liuli-util/rollup-plugin-i18next-dts-gen

场景

吾辈有一些项目需要使用 i18next 来处理国际化,但是使用 typescript 需要有类型定义,所以实现了 @liuli-util/i18next-dts-gen 用来自动生成 .d.ts 文件。但之后吾辈发现可以将这个过程集成到构建中,不再需要额外单独启动一个终端命令,目前支持直接集成到 rollup/vite 的构建流程中。

安装

sh
pnpm i -D i18next @liuli-util/rollup-plugin-i18next-dts-gen

添加翻译文件

src/i18n/ 下添加翻译的 json 文件,下面添加两个示例

json
// src/i18n/en-US.json
 {
   "hello": "hello world",
   "toggle": "Switch language"
@@ -55,8 +55,8 @@
 console.log(t('hello'))

配置

ts
export interface GenerateOptions {
   // i18n 的目录,可以指定多个,会在每一个子目录下扫描 json 文件并生成对应的 .d.ts
   dirs: string[]
-}

MIT Licensed

- +}

MIT Licensed

+ \ No newline at end of file diff --git a/dev/test.html b/dev/test.html new file mode 100644 index 00000000..3c27ac5b --- /dev/null +++ b/dev/test.html @@ -0,0 +1,32 @@ + + + + + + @liuli-util/test | liuli-tools + + + + + + + + + + + + + +
Skip to content

@liuli-util/test

辅助其他模块测试的工具函数库

initTempPath

初始化一个临时目录,返回目录路径

ts
import { it } from 'vitest'
+import { initTempPath } from '@liuli-util/test'
+import fs from 'fs'
+
+const tempPath = initTempPath(__filename)
+
+it('Test initTempPath', () => {
+  expect(fs.existsSync(tempPath)).true
+})

MIT Licensed

+ + + + \ No newline at end of file diff --git a/dev/vite-plugin-dist-firefox.html b/dev/vite-plugin-dist-firefox.html index 6f7c5d5a..6ed62f55 100644 --- a/dev/vite-plugin-dist-firefox.html +++ b/dev/vite-plugin-dist-firefox.html @@ -17,7 +17,7 @@ -
Skip to content

@liuli-util/vite-plugin-dist-firefox

将构建的 chrome 扩展转换为 firefox 扩展,仅允许支持 manifest v3 的 firefox 版本。参考:firefox manifest v3 迁移指南

使用

在 vite.config.ts 中配置

ts
import { defineConfig } from 'vite'
+    
Skip to content

@liuli-util/vite-plugin-dist-firefox

将构建的 chrome 扩展转换为 firefox 扩展,仅允许支持 manifest v3 的 firefox 版本。参考:firefox manifest v3 迁移指南

使用

在 vite.config.ts 中配置

ts
import { defineConfig } from 'vite'
 import { crx } from '@crxjs/vite-plugin'
 import manifest from './manifest.json'
 import { firefox } from '@liuli-util/vite-plugin-dist-firefox'
@@ -29,8 +29,8 @@
     }),
     firefox(),
   ],
-})

这个扩展会将 dist 目录下的 chrome 扩展的 manifest.json 做一些转换,并将转换后的文件放在 dist-firefox 目录下,稍后可以使用 web-ext 打包 zip 并提交。

MIT Licensed

- +})

这个扩展会将 dist 目录下的 chrome 扩展的 manifest.json 做一些转换,并将转换后的文件放在 dist-firefox 目录下,稍后可以使用 web-ext 打包 zip 并提交。

MIT Licensed

+ \ No newline at end of file diff --git a/dev/vite-plugin-node.html b/dev/vite-plugin-node.html index cbd18582..5f9c4869 100644 --- a/dev/vite-plugin-node.html +++ b/dev/vite-plugin-node.html @@ -17,7 +17,7 @@ -
Skip to content

@liuli-util/vite-plugin-node

使用 vite 构建 nodejs app/lib 所需的一切,希望在构建 node 应用时,能够像使用 vite 构建 web 应用一样简单。

目前支持以下功能:

  • [x] 支持根据 dependencies 自动 bundle 依赖
  • [x] 支持 bundle 时生成 dts 类型定义
  • [x] 支持填充 __dirname 等 cjs 特性
  • [x] 支持开箱即用的配置,但也支持自定义配置
  • [x] 支持 bundle 为 cjs 模块 -- 目前也支持,但需要修改 vite 的配置
  • [x] 支持多入口的构建
  • [x] 支持 dts 类型捆绑

特别是支持在以下场景使用

  • lib
  • cli
  • nodejs server
  • vscode plugin

使用

安装

bash
pnpm i -D @liuli-util/vite-plugin-node

创建入口文件 src/index.ts

ts
import { createServer } from 'http'
+    
Skip to content

@liuli-util/vite-plugin-node

使用 vite 构建 nodejs app/lib 所需的一切,希望在构建 node 应用时,能够像使用 vite 构建 web 应用一样简单。

目前支持以下功能:

  • [x] 支持根据 dependencies 自动 bundle 依赖
  • [x] 支持 bundle 时生成 dts 类型定义
  • [x] 支持填充 __dirname 等 cjs 特性
  • [x] 支持开箱即用的配置,但也支持自定义配置
  • [x] 支持 bundle 为 cjs 模块 -- 目前也支持,但需要修改 vite 的配置
  • [x] 支持多入口的构建
  • [x] 支持 dts 类型捆绑

特别是支持在以下场景使用

  • lib
  • cli
  • nodejs server
  • vscode plugin

使用

安装

bash
pnpm i -D @liuli-util/vite-plugin-node

创建入口文件 src/index.ts

ts
import { createServer } from 'http'
 
 const server = createServer((req, res) => {
   res.end('hello world')
@@ -31,7 +31,7 @@
 export default defineConfig({
   plugins: [node()],
 })

然后构建

bash
pnpm vite build

事实上,这个 lib 本身也使用这个插件构建!

配置

名称类型默认值说明
entrystring, string[]src/index.ts入口文件
formats('es', 'cjs')[][es]输出格式
shimsbooleanfalse是否填充 __dirname/require 等 cjs 特性
dtsboolean, { bundle?: boolean }false是否生成 dts 类型定义
outDirstringdist输出目录

其他

环境变量

vite 天然支持环境变量,但目前包含两类环境变量,编译时和运行时

  • 编译时环境变量 import.meta.env.*
  • 运行时环境变量 process.env.*

编译时环境变量在项目编译时就已经被替换为静态字符串,一般适用于 web 应用。而运行时环境变量适合在项目运行时动态指定值,一般适用于 node 应用。

MIT Licensed

- + \ No newline at end of file diff --git a/en/dev/create-liuli.html b/en/dev/create-liuli.html index 65c264a4..1012aca5 100644 --- a/en/dev/create-liuli.html +++ b/en/dev/create-liuli.html @@ -17,9 +17,9 @@ -
Skip to content

create-liuli

Template application for creating lib/cli that I use personally. Instructions for usage:

bash
pnpm create liuli
+    
Skip to content

create-liuli

Template application for creating lib/cli that I use personally. Instructions for usage:

bash
pnpm create liuli
 # Then enter the project name and type according to the prompts

Currently supported types are:

  • lib: Create a lib template based on vite/vitest, providing the correct exports configuration and default support for esm.
  • cli: Create a cli template based on vite/vitest/vite-node, with default support for esm.

Planned supported templates:

  • [ ] preact web application
  • [ ] vscode plugin
  • [ ] chrome plugin
  • [ ] nodejs service
  • [ ] userscript
  • [ ] electron application

MIT Licensed

- + \ No newline at end of file diff --git a/en/dev/rollup-plugin-i18next-dts-gen.html b/en/dev/rollup-plugin-i18next-dts-gen.html index 5c0af562..5d3a1455 100644 --- a/en/dev/rollup-plugin-i18next-dts-gen.html +++ b/en/dev/rollup-plugin-i18next-dts-gen.html @@ -17,7 +17,7 @@ -
Skip to content

@liuli-util/rollup-plugin-i18next-dts-gen

Scenario

We have some projects that need to use i18next to handle internationalization. However, when using TypeScript, we need type definitions. Therefore, we have implemented @liuli-util/i18next-dts-gen to automatically generate .d.ts files. Later, we found that this process can be integrated into the build process, eliminating the need to start a separate terminal command. Currently, it supports direct integration into the rollup/vite build process.

Installation

sh
pnpm i -D i18next @liuli-util/rollup-plugin-i18next-dts-gen

Add translation files

Add the translation JSON files under src/i18n/. Here are two examples:

json
// src/i18n/en-US.json
+    
Skip to content

@liuli-util/rollup-plugin-i18next-dts-gen

Scenario

We have some projects that need to use i18next to handle internationalization. However, when using TypeScript, we need type definitions. Therefore, we have implemented @liuli-util/i18next-dts-gen to automatically generate .d.ts files. Later, we found that this process can be integrated into the build process, eliminating the need to start a separate terminal command. Currently, it supports direct integration into the rollup/vite build process.

Installation

sh
pnpm i -D i18next @liuli-util/rollup-plugin-i18next-dts-gen

Add translation files

Add the translation JSON files under src/i18n/. Here are two examples:

json
// src/i18n/en-US.json
 {
   "hello": "hello world",
   "toggle": "Switch language"
@@ -55,8 +55,8 @@
 console.log(t('hello'))

Configuration

ts
export interface GenerateOptions {
   // List of directories for i18n. Multiple directories can be specified. JSON files will be scanned in each subdirectory to generate the corresponding .d.ts file.
   dirs: string[]
-}

MIT Licensed

- +}

MIT Licensed

+ \ No newline at end of file diff --git a/en/dev/test.html b/en/dev/test.html new file mode 100644 index 00000000..c2cdd606 --- /dev/null +++ b/en/dev/test.html @@ -0,0 +1,32 @@ + + + + + + @liuli-util/test | liuli-tools + + + + + + + + + + + + + +
Skip to content

@liuli-util/test

Utility function library for assisting in testing other modules.

initTempPath

Initialize a temporary directory and return its path.

ts
import { it } from 'vitest'
+import { initTempPath } from '@liuli-util/test'
+import fs from 'fs'
+
+const tempPath = initTempPath(__filename)
+
+it('Test initTempPath', () => {
+  expect(fs.existsSync(tempPath)).true
+})

MIT Licensed

+ + + + \ No newline at end of file diff --git a/en/dev/vite-plugin-dist-firefox.html b/en/dev/vite-plugin-dist-firefox.html index 7f1a9736..03ef1d93 100644 --- a/en/dev/vite-plugin-dist-firefox.html +++ b/en/dev/vite-plugin-dist-firefox.html @@ -17,7 +17,7 @@ -
Skip to content

@liuli-util/vite-plugin-dist-firefox

Converts a built Chrome extension into a Firefox extension, only allowing Firefox versions that support manifest v3. Refer to the Firefox Manifest v3 Migration Guide.

Usage

Configure in vite.config.ts:

ts
import { defineConfig } from 'vite'
+    
Skip to content

@liuli-util/vite-plugin-dist-firefox

Converts a built Chrome extension into a Firefox extension, only allowing Firefox versions that support manifest v3. Refer to the Firefox Manifest v3 Migration Guide.

Usage

Configure in vite.config.ts:

ts
import { defineConfig } from 'vite'
 import { crx } from '@crxjs/vite-plugin'
 import manifest from './manifest.json'
 import { firefox } from '@liuli-util/vite-plugin-dist-firefox'
@@ -29,8 +29,8 @@
     }),
     firefox(),
   ],
-})

This extension will perform some transformations on the manifest.json of the Chrome extension located in the dist directory, and place the converted files in the dist-firefox directory. Later, you can use web-ext to package them into a zip file and submit it.

MIT Licensed

- +})

This extension will perform some transformations on the manifest.json of the Chrome extension located in the dist directory, and place the converted files in the dist-firefox directory. Later, you can use web-ext to package them into a zip file and submit it.

MIT Licensed

+ \ No newline at end of file diff --git a/en/dev/vite-plugin-node.html b/en/dev/vite-plugin-node.html index 5582fa4a..58507d3b 100644 --- a/en/dev/vite-plugin-node.html +++ b/en/dev/vite-plugin-node.html @@ -17,7 +17,7 @@ -
Skip to content

@liuli-util/vite-plugin-node

Everything you need to build a nodejs app/lib with vite, with the simplicity of building web apps with vite.

Currently supports the following features:

  • [x] Automatically bundling dependencies based on dependencies
  • [x] Generate dts type definitions when bundling
  • [x] Support filling in cjs features such as __dirname
  • [x] Out-of-the-box configuration, but also supports custom configuration
  • [x] Support bundling as cjs modules - currently supported, but requires modifying vite's configuration
  • [x] Support for multi-entry builds
  • [x] Support for bundling dts types

Especially useful in the following scenarios

  • lib
  • cli
  • nodejs server
  • vscode plugin

Usage

Install

bash
pnpm i -D @liuli-util/vite-plugin-node

Create an entry file src/index.ts

ts
import { createServer } from 'http'
+    
Skip to content

@liuli-util/vite-plugin-node

Everything you need to build a nodejs app/lib with vite, with the simplicity of building web apps with vite.

Currently supports the following features:

  • [x] Automatically bundling dependencies based on dependencies
  • [x] Generate dts type definitions when bundling
  • [x] Support filling in cjs features such as __dirname
  • [x] Out-of-the-box configuration, but also supports custom configuration
  • [x] Support bundling as cjs modules - currently supported, but requires modifying vite's configuration
  • [x] Support for multi-entry builds
  • [x] Support for bundling dts types

Especially useful in the following scenarios

  • lib
  • cli
  • nodejs server
  • vscode plugin

Usage

Install

bash
pnpm i -D @liuli-util/vite-plugin-node

Create an entry file src/index.ts

ts
import { createServer } from 'http'
 
 const server = createServer((req, res) => {
   res.end('hello world')
@@ -31,7 +31,7 @@
 export default defineConfig({
   plugins: [node()],
 })

Then build

bash
pnpm vite build

In fact, this lib itself is also built using this plugin!

Configuration

NameTypeDefaultDescription
entrystring, string[]src/index.tsEntry file
formats('es', 'cjs')[][es]Output formats
shimsbooleanfalseWhether to fill in cjs features like __dirname/require
dtsboolean, { bundle?: boolean }falseWhether to generate dts type definitions
outDirstringdistOutput directory

Others

Environment Variables

Vite naturally supports environment variables, but currently includes two types of variables, compile-time and run-time

  • Compile-time environment variables import.meta.env.*
  • Run-time environment variables process.env.*

Compile-time environment variables are replaced with static strings during project compilation and are generally suitable for web applications. Runtime environment variables are suitable for dynamically specifying values during project runtime and are generally used for node applications.

MIT Licensed

- + \ No newline at end of file diff --git a/en/index.html b/en/index.html index 30a992c7..38a7897b 100644 --- a/en/index.html +++ b/en/index.html @@ -12,13 +12,13 @@ - + -
Skip to content

liuli-tools

Liuli's Development Toolkit

A collection of libraries and developer tools developed as needed.

liuli-tools

MIT Licensed

- +
Skip to content

liuli-tools

Liuli's Development Toolkit

A collection of libraries and developer tools developed as needed.

liuli-tools

MIT Licensed

+ \ No newline at end of file diff --git a/en/lib/async.html b/en/lib/async.html index c68576e4..492e5d6b 100644 --- a/en/lib/async.html +++ b/en/lib/async.html @@ -17,7 +17,7 @@ -
Skip to content

@liuli-util/async

Library of functions related to asynchronous operations.

Main features

  • wait: Wait for a certain amount of time or for a specific condition to be met.
  • AsyncArray: Asynchronous array that supports methods like map, filter, reduce, etc. with asynchronous callbacks, and also supports chaining.
  • asyncLimiting: Limit the concurrent invocations of an asynchronous function.
  • once: Ensure that an asynchronous function is only called once and handle concurrency correctly.
  • concatMap: Equivalent to the concatMap operator in RxJS.
  • exhaustMap: Equivalent to the exhaustMap operator in RxJS.
  • mergeMap: Equivalent to the mergeMap operator in RxJS.
  • switchMap: Equivalent to the switchMap operator in RxJS.
  • debounce: Previously implemented debounce function, recommended to use lodash-es.
  • throttle: Previously implemented throttle function, recommended to use lodash-es.

Installation

sh
pnpm i @liuli-util/async

Usage

wait

Wait for a certain amount of time.

ts
import { wait } from '@liuli-util/async'
+    
Skip to content

@liuli-util/async

Library of functions related to asynchronous operations.

Main features

  • wait: Wait for a certain amount of time or for a specific condition to be met.
  • AsyncArray: Asynchronous array that supports methods like map, filter, reduce, etc. with asynchronous callbacks, and also supports chaining.
  • asyncLimiting: Limit the concurrent invocations of an asynchronous function.
  • once: Ensure that an asynchronous function is only called once and handle concurrency correctly.
  • concatMap: Equivalent to the concatMap operator in RxJS.
  • exhaustMap: Equivalent to the exhaustMap operator in RxJS.
  • mergeMap: Equivalent to the mergeMap operator in RxJS.
  • switchMap: Equivalent to the switchMap operator in RxJS.
  • debounce: Previously implemented debounce function, recommended to use lodash-es.
  • throttle: Previously implemented throttle function, recommended to use lodash-es.

Installation

sh
pnpm i @liuli-util/async

Usage

wait

Wait for a certain amount of time.

ts
import { wait } from '@liuli-util/async'
 
 await wait(1000)

Wait until a condition is met.

ts
import { wait } from '@liuli-util/async'
 
@@ -48,7 +48,7 @@
   return 1
 })
 const r = await Promise.all([f(), f(), f()]) // Only outputs 'init' once

MIT Licensed

- + \ No newline at end of file diff --git a/en/lib/markdown-util.html b/en/lib/markdown-util.html index a54ad761..bda8f654 100644 --- a/en/lib/markdown-util.html +++ b/en/lib/markdown-util.html @@ -17,7 +17,7 @@ -
Skip to content

@liuli-util/markdown-util

Markdown encapsulation tool that provides all the functions needed to process Markdown based on mdast. It is recommended to use astexplorer to view the structure of mdast.

fromMarkdown

Converts Markdown to mdast, supports automatic parsing of YAML metadata.

ts
import { fromMarkdown } from '@liuli-util/markdown-util'
+    
Skip to content

@liuli-util/markdown-util

Markdown encapsulation tool that provides all the functions needed to process Markdown based on mdast. It is recommended to use astexplorer to view the structure of mdast.

fromMarkdown

Converts Markdown to mdast, supports automatic parsing of YAML metadata.

ts
import { fromMarkdown } from '@liuli-util/markdown-util'
 
 const md = `
 # Title
@@ -221,7 +221,7 @@
 }
 const res = selectAll(mdast, 'heading')
 console.log(res)

MIT Licensed

- + \ No newline at end of file diff --git a/en/lib/tree.html b/en/lib/tree.html index cf58f0f7..504b63ce 100644 --- a/en/lib/tree.html +++ b/en/lib/tree.html @@ -17,7 +17,7 @@ -
Skip to content

@liuli-util/tree

Tree-related functions, including tree traversal, mapping, filtering, and reduction. All methods perform depth-first traversal.

Main features

  • treeMap: Mapping
  • treeFilter: Filtering
  • treeEach: Traversal
  • treeToList: Tree to list conversion
  • listToTree: List to tree conversion
  • treeReduce: Reduction

Installation

bash
pnpm i @liuli-util/tree

treeMap - Mapping

Convert nested menus to JSX element rendering

tsx
import { Menu } from 'antd'
+    
Skip to content

@liuli-util/tree

Tree-related functions, including tree traversal, mapping, filtering, and reduction. All methods perform depth-first traversal.

Main features

  • treeMap: Mapping
  • treeFilter: Filtering
  • treeEach: Traversal
  • treeToList: Tree to list conversion
  • listToTree: List to tree conversion
  • treeReduce: Reduction

Installation

bash
pnpm i @liuli-util/tree

treeMap - Mapping

Convert nested menus to JSX element rendering

tsx
import { Menu } from 'antd'
 import { treeMap } from '@liuli-util/tree'
 
 const menus = [
@@ -199,8 +199,8 @@
     id: 'chapterId',
     children: 'children',
   },
-)

MIT Licensed

- +)

MIT Licensed

+ \ No newline at end of file diff --git a/hashmap.json b/hashmap.json index f40f466c..94dee1c9 100644 --- a/hashmap.json +++ b/hashmap.json @@ -1 +1 @@ -{"en_dev_vite-plugin-dist-firefox.md":"coMIuf5k","en_dev_create-liuli.md":"01vOrYsW","dev_vite-plugin-node.md":"YpwHH_OC","en_index.md":"YNPna48s","dev_vite-plugin-dist-firefox.md":"sUk-DJB6","dev_rollup-plugin-i18next-dts-gen.md":"iOBJfbca","dev_create-liuli.md":"SE8IHmwN","lib_async.md":"gYp14w1a","en_dev_vite-plugin-node.md":"lhc3ogr6","index.md":"o7ifCqGm","en_lib_tree.md":"-iIyixuE","en_dev_rollup-plugin-i18next-dts-gen.md":"uojgHvgX","en_lib_markdown-util.md":"JF8UAdyg","en_lib_async.md":"kGPYWfZv","lib_markdown-util.md":"MLIOIFQj","lib_tree.md":"kzm5j3ml"} +{"en_index.md":"prNKhQEC","dev_create-liuli.md":"SE8IHmwN","dev_vite-plugin-dist-firefox.md":"sUk-DJB6","dev_vite-plugin-node.md":"YpwHH_OC","index.md":"o7ifCqGm","lib_async.md":"gYp14w1a","en_dev_vite-plugin-node.md":"lhc3ogr6","dev_rollup-plugin-i18next-dts-gen.md":"iOBJfbca","en_lib_async.md":"kGPYWfZv","en_lib_tree.md":"-iIyixuE","en_dev_create-liuli.md":"01vOrYsW","en_dev_test.md":"zIYD7Ymp","en_dev_rollup-plugin-i18next-dts-gen.md":"uojgHvgX","dev_test.md":"bJiHCdLJ","lib_tree.md":"kzm5j3ml","lib_markdown-util.md":"MLIOIFQj","en_lib_markdown-util.md":"JF8UAdyg","en_dev_vite-plugin-dist-firefox.md":"coMIuf5k"} diff --git a/index.html b/index.html index 7abe7c90..9c4a57b8 100644 --- a/index.html +++ b/index.html @@ -18,7 +18,7 @@
Skip to content

liuli-tools

琉璃的开发工具集

一些根据需要自行开发的函数库和开发者工具。

liuli-tools

MIT Licensed

- + \ No newline at end of file diff --git a/lib/async.html b/lib/async.html index 41b6129c..13e074ee 100644 --- a/lib/async.html +++ b/lib/async.html @@ -17,7 +17,7 @@ -
Skip to content

@liuli-util/async

异步相关功能的函数库

主要功能

  • wait: 等待一段时间或满足特定条件
  • AsyncArray: 异步数组,支持 mapfilterreduce 等方法,但均支持异步回调,还同时支持链式调用
  • asyncLimiting: 限制一个异步函数的并发调用数量
  • once: 保证一个异步函数只会被调用一次,并且正确处理了并发的情况
  • concatMap: 等同于 rxjs 中的 concatMap 操作符
  • exhaustMap: 等同于 rxjs 中的 exhaustMap 操作符
  • mergeMap: 等同于 rxjs 中的 mergeMap 操作符
  • switchMap: 等同于 rxjs 中的 switchMap 操作符
  • debounce: 之前实现的函数去抖,推荐使用 lodash-es
  • throttle: 之前实现的函数节流,推荐使用 lodash-es

安装

sh
pnpm i @liuli-util/async

使用

wait

等待一段时间

ts
import { wait } from '@liuli-util/async'
+    
Skip to content

@liuli-util/async

异步相关功能的函数库

主要功能

  • wait: 等待一段时间或满足特定条件
  • AsyncArray: 异步数组,支持 mapfilterreduce 等方法,但均支持异步回调,还同时支持链式调用
  • asyncLimiting: 限制一个异步函数的并发调用数量
  • once: 保证一个异步函数只会被调用一次,并且正确处理了并发的情况
  • concatMap: 等同于 rxjs 中的 concatMap 操作符
  • exhaustMap: 等同于 rxjs 中的 exhaustMap 操作符
  • mergeMap: 等同于 rxjs 中的 mergeMap 操作符
  • switchMap: 等同于 rxjs 中的 switchMap 操作符
  • debounce: 之前实现的函数去抖,推荐使用 lodash-es
  • throttle: 之前实现的函数节流,推荐使用 lodash-es

安装

sh
pnpm i @liuli-util/async

使用

wait

等待一段时间

ts
import { wait } from '@liuli-util/async'
 
 await wait(1000)

等待满足条件

ts
import { wait } from '@liuli-util/async'
 
@@ -48,7 +48,7 @@
   return 1
 })
 const r = await Promise.all([f(), f(), f()]) // 只会输出一次 init

MIT Licensed

- + \ No newline at end of file diff --git a/lib/markdown-util.html b/lib/markdown-util.html index bff58d07..9f089d46 100644 --- a/lib/markdown-util.html +++ b/lib/markdown-util.html @@ -17,7 +17,7 @@ -
Skip to content

@liuli-util/markdown-util

markdown 封装工具,基于 mdast 提供所有在处理 markdown 中需要用到的函数。建议使用 astexplorer 来查看 mdast 的结构。

fromMarkdown

将 markdown 转换为 mdast,支持自动解析 yaml 元数据。

ts
import { fromMarkdown } from '@liuli-util/markdown-util'
+    
Skip to content

@liuli-util/markdown-util

markdown 封装工具,基于 mdast 提供所有在处理 markdown 中需要用到的函数。建议使用 astexplorer 来查看 mdast 的结构。

fromMarkdown

将 markdown 转换为 mdast,支持自动解析 yaml 元数据。

ts
import { fromMarkdown } from '@liuli-util/markdown-util'
 
 const md = `
 # 标题
@@ -220,8 +220,8 @@
   ],
 }
 const res = selectAll(mdast, 'heading')
-console.log(res)

MIT Licensed

- +console.log(res)

MIT Licensed

+ \ No newline at end of file diff --git a/lib/tree.html b/lib/tree.html index d5a349a5..38f4ed3f 100644 --- a/lib/tree.html +++ b/lib/tree.html @@ -17,7 +17,7 @@ -
Skip to content

@liuli-util/tree

树结构相关功能,包括树结构的遍历、映射、过滤、归并等,所有方法均为深度优先遍历。

主要功能

  • treeMap: 映射
  • treeFilter: 过滤
  • treeEach: 遍历
  • treeToList: 树转为列表
  • listToTree: 列表转为树
  • treeReduce: 归并

安装

bash
pnpm i @liuli-util/tree

treeMap 映射

将嵌套菜单转换为 JSX 元素渲染

tsx
import { Menu } from 'antd'
+    
Skip to content

@liuli-util/tree

树结构相关功能,包括树结构的遍历、映射、过滤、归并等,所有方法均为深度优先遍历。

主要功能

  • treeMap: 映射
  • treeFilter: 过滤
  • treeEach: 遍历
  • treeToList: 树转为列表
  • listToTree: 列表转为树
  • treeReduce: 归并

安装

bash
pnpm i @liuli-util/tree

treeMap 映射

将嵌套菜单转换为 JSX 元素渲染

tsx
import { Menu } from 'antd'
 import { treeMap } from '@liuli-util/tree'
 
 const menus = [
@@ -199,8 +199,8 @@
     id: 'chapterId',
     children: 'children',
   },
-)

MIT Licensed

- +)

MIT Licensed

+ \ No newline at end of file