@nickyzj2023/utils 1.0.55 → 1.0.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/dist/index.d.ts +446 -9
- package/dist/index.js +2 -3
- package/package.json +15 -4
- package/AGENTS.md +0 -167
- package/biome.json +0 -37
- package/dist/dom/index.d.ts +0 -1
- package/dist/dom/log.d.ts +0 -28
- package/dist/dom/timeLog.d.ts +0 -8
- package/dist/function/index.d.ts +0 -1
- package/dist/function/loop-until.d.ts +0 -36
- package/dist/function/loopUntil.d.ts +0 -22
- package/dist/hoc/index.d.ts +0 -1
- package/dist/hoc/with-cache.d.ts +0 -42
- package/dist/hoc/withCache.d.ts +0 -42
- package/dist/is/index.d.ts +0 -4
- package/dist/is/is-falsy.d.ts +0 -9
- package/dist/is/is-nil.d.ts +0 -9
- package/dist/is/is-object.d.ts +0 -8
- package/dist/is/is-primitive.d.ts +0 -9
- package/dist/is/isFalsy.d.ts +0 -9
- package/dist/is/isNil.d.ts +0 -9
- package/dist/is/isObject.d.ts +0 -8
- package/dist/is/isPrimitive.d.ts +0 -9
- package/dist/is/isTruthy.d.ts +0 -8
- package/dist/lru-cache.d.ts +0 -18
- package/dist/network/fetcher.d.ts +0 -56
- package/dist/network/get-real-url.d.ts +0 -2
- package/dist/network/getRealURL.d.ts +0 -2
- package/dist/network/image.d.ts +0 -59
- package/dist/network/index.d.ts +0 -4
- package/dist/network/to.d.ts +0 -9
- package/dist/number/index.d.ts +0 -1
- package/dist/number/random-int.d.ts +0 -7
- package/dist/number/randomInt.d.ts +0 -7
- package/dist/object/index.d.ts +0 -3
- package/dist/object/map-keys.d.ts +0 -17
- package/dist/object/map-values.d.ts +0 -21
- package/dist/object/mapKeys.d.ts +0 -17
- package/dist/object/mapValues.d.ts +0 -21
- package/dist/object/merge-objects.d.ts +0 -12
- package/dist/object/mergeObjects.d.ts +0 -12
- package/dist/string/case.d.ts +0 -32
- package/dist/string/compact.d.ts +0 -22
- package/dist/string/index.d.ts +0 -2
- package/dist/time/debounce.d.ts +0 -20
- package/dist/time/index.d.ts +0 -3
- package/dist/time/sleep.d.ts +0 -7
- package/dist/time/throttle.d.ts +0 -20
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -92
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/material-style.css +0 -262
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1633
- package/docs/functions/camelToSnake.html +0 -178
- package/docs/functions/capitalize.html +0 -178
- package/docs/functions/compactStr.html +0 -182
- package/docs/functions/debounce.html +0 -187
- package/docs/functions/decapitalize.html +0 -178
- package/docs/functions/fetcher.html +0 -189
- package/docs/functions/getRealURL.html +0 -175
- package/docs/functions/imageUrlToBase64.html +0 -191
- package/docs/functions/isFalsy.html +0 -178
- package/docs/functions/isNil.html +0 -178
- package/docs/functions/isObject.html +0 -178
- package/docs/functions/isPrimitive.html +0 -178
- package/docs/functions/log.html +0 -180
- package/docs/functions/loopUntil.html +0 -186
- package/docs/functions/mapKeys.html +0 -180
- package/docs/functions/mapValues.html +0 -182
- package/docs/functions/mergeObjects.html +0 -184
- package/docs/functions/randomInt.html +0 -178
- package/docs/functions/sleep.html +0 -179
- package/docs/functions/snakeToCamel.html +0 -178
- package/docs/functions/throttle.html +0 -187
- package/docs/functions/to.html +0 -180
- package/docs/functions/withCache.html +0 -185
- package/docs/hierarchy.html +0 -174
- package/docs/index.html +0 -184
- package/docs/interfaces/LogOptions.html +0 -185
- package/docs/modules.html +0 -174
- package/docs/types/BunFetchOptions.html +0 -176
- package/docs/types/CamelToSnake.html +0 -174
- package/docs/types/Capitalize.html +0 -174
- package/docs/types/Decapitalize.html +0 -174
- package/docs/types/DeepMapKeys.html +0 -174
- package/docs/types/DeepMapValues.html +0 -174
- package/docs/types/Falsy.html +0 -174
- package/docs/types/ImageCompressionOptions.html +0 -188
- package/docs/types/Primitive.html +0 -174
- package/docs/types/RequestInit.html +0 -174
- package/docs/types/SetTtl.html +0 -174
- package/docs/types/SnakeToCamel.html +0 -174
- package/src/dom/index.ts +0 -1
- package/src/dom/log.ts +0 -72
- package/src/function/index.ts +0 -1
- package/src/function/loop-until.ts +0 -58
- package/src/hoc/index.ts +0 -1
- package/src/hoc/with-cache.ts +0 -117
- package/src/index.ts +0 -9
- package/src/is/index.ts +0 -4
- package/src/is/is-falsy.ts +0 -12
- package/src/is/is-nil.ts +0 -11
- package/src/is/is-object.ts +0 -10
- package/src/is/is-primitive.ts +0 -23
- package/src/network/fetcher.ts +0 -124
- package/src/network/get-real-url.ts +0 -18
- package/src/network/image.ts +0 -202
- package/src/network/index.ts +0 -4
- package/src/network/to.ts +0 -17
- package/src/number/index.ts +0 -1
- package/src/number/random-int.ts +0 -9
- package/src/object/index.ts +0 -3
- package/src/object/map-keys.ts +0 -50
- package/src/object/map-values.ts +0 -77
- package/src/object/merge-objects.ts +0 -50
- package/src/string/case.ts +0 -71
- package/src/string/compact.ts +0 -56
- package/src/string/index.ts +0 -2
- package/src/time/debounce.ts +0 -34
- package/src/time/index.ts +0 -3
- package/src/time/sleep.ts +0 -11
- package/src/time/throttle.ts +0 -34
- package/tsconfig.json +0 -32
package/src/string/compact.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 将字符串压缩为单行精简格式
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* // "Hello, world."
|
|
6
|
-
* compactStr(`
|
|
7
|
-
* Hello,
|
|
8
|
-
* world!
|
|
9
|
-
* `, {
|
|
10
|
-
* disableNewLineReplace: false,
|
|
11
|
-
* });
|
|
12
|
-
*/
|
|
13
|
-
export const compactStr = (
|
|
14
|
-
text: string = "",
|
|
15
|
-
options?: {
|
|
16
|
-
/** 最大保留长度,设为 0 或 Infinity 则不截断,默认 Infinity */
|
|
17
|
-
maxLength?: number;
|
|
18
|
-
/** 是否将换行符替换为字面量 \n,默认开启 */
|
|
19
|
-
disableNewLineReplace?: boolean;
|
|
20
|
-
/** 是否合并连续的空格/制表符为一个空格,默认开启 */
|
|
21
|
-
disableWhitespaceCollapse?: boolean;
|
|
22
|
-
/** 截断后的后缀,默认为 "..." */
|
|
23
|
-
omission?: string;
|
|
24
|
-
},
|
|
25
|
-
): string => {
|
|
26
|
-
if (!text) return "";
|
|
27
|
-
|
|
28
|
-
const {
|
|
29
|
-
maxLength = Infinity,
|
|
30
|
-
disableNewLineReplace = false,
|
|
31
|
-
disableWhitespaceCollapse = false,
|
|
32
|
-
omission = "...",
|
|
33
|
-
} = options ?? {};
|
|
34
|
-
|
|
35
|
-
let result = text;
|
|
36
|
-
|
|
37
|
-
// 处理换行符
|
|
38
|
-
if (!disableNewLineReplace) {
|
|
39
|
-
result = result.replace(/\r?\n/g, "\\n");
|
|
40
|
-
} else {
|
|
41
|
-
result = result.replace(/\r?\n/g, " ");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// 合并连续空格
|
|
45
|
-
if (!disableWhitespaceCollapse) {
|
|
46
|
-
result = result.replace(/\s+/g, " ");
|
|
47
|
-
}
|
|
48
|
-
result = result.trim();
|
|
49
|
-
|
|
50
|
-
// 截断多出来的文字
|
|
51
|
-
if (maxLength > 0 && result.length > maxLength) {
|
|
52
|
-
return result.slice(0, maxLength) + omission;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return result;
|
|
56
|
-
};
|
package/src/string/index.ts
DELETED
package/src/time/debounce.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 防抖:在指定时间内只执行最后一次调用
|
|
3
|
-
* @param fn 要防抖的函数
|
|
4
|
-
* @param delay 延迟时间,默认 300ms
|
|
5
|
-
*
|
|
6
|
-
* @remarks
|
|
7
|
-
* 连续触发时,只有最后一次会执行。适合用于搜索框输入、窗口大小调整等场景。
|
|
8
|
-
* 例如:用户输入"hello"过程中,不会触发搜索,只有停下来时才执行。
|
|
9
|
-
*
|
|
10
|
-
* 防抖 vs 节流:
|
|
11
|
-
* - 防抖:等待触发停止后才执行(最后一次)
|
|
12
|
-
* - 节流:按固定节奏执行(每隔多久执行一次)
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* const search = debounce((keyword: string) => {
|
|
16
|
-
* console.log('搜索:', keyword);
|
|
17
|
-
* });
|
|
18
|
-
* search('hello'); // 300ms 后执行
|
|
19
|
-
*/
|
|
20
|
-
export const debounce = <T extends (...args: any[]) => any>(
|
|
21
|
-
fn: T,
|
|
22
|
-
delay = 300,
|
|
23
|
-
) => {
|
|
24
|
-
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
25
|
-
|
|
26
|
-
return (...args: Parameters<T>) => {
|
|
27
|
-
if (timer) {
|
|
28
|
-
clearTimeout(timer);
|
|
29
|
-
}
|
|
30
|
-
timer = setTimeout(() => {
|
|
31
|
-
fn(...args);
|
|
32
|
-
}, delay);
|
|
33
|
-
};
|
|
34
|
-
};
|
package/src/time/index.ts
DELETED
package/src/time/sleep.ts
DELETED
package/src/time/throttle.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 节流函数 - 在指定时间间隔内最多执行一次调用
|
|
3
|
-
* @param fn 要节流的函数
|
|
4
|
-
* @param delay 间隔时间,默认 300ms
|
|
5
|
-
*
|
|
6
|
-
* @remarks
|
|
7
|
-
* 节流:连续触发时,按照固定间隔执行。适合用于滚动、拖拽等高频触发场景。
|
|
8
|
-
* 例如:滚动页面时,每300ms最多执行一次回调,而不是每次滚动都执行。
|
|
9
|
-
*
|
|
10
|
-
* 防抖 vs 节流:
|
|
11
|
-
* - 防抖:等待触发停止后才执行(最后一次)
|
|
12
|
-
* - 节流:按固定节奏执行(每隔多久执行一次)
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* const handleScroll = throttle(() => {
|
|
16
|
-
* console.log('滚动位置:', window.scrollY);
|
|
17
|
-
* }, 200);
|
|
18
|
-
* window.addEventListener('scroll', handleScroll);
|
|
19
|
-
*/
|
|
20
|
-
export const throttle = <T extends (...args: any[]) => any>(
|
|
21
|
-
fn: T,
|
|
22
|
-
delay = 300,
|
|
23
|
-
) => {
|
|
24
|
-
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
25
|
-
|
|
26
|
-
return function (this: any, ...args: Parameters<T>) {
|
|
27
|
-
if (!timer) {
|
|
28
|
-
timer = setTimeout(() => {
|
|
29
|
-
timer = null;
|
|
30
|
-
fn.apply(this, args);
|
|
31
|
-
}, delay);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
// Environment setup & latest features
|
|
4
|
-
"lib": ["ESNext", "DOM"],
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"module": "Preserve",
|
|
7
|
-
"moduleDetection": "force",
|
|
8
|
-
"jsx": "react-jsx",
|
|
9
|
-
"allowJs": true,
|
|
10
|
-
|
|
11
|
-
// Bundler mode
|
|
12
|
-
"moduleResolution": "bundler",
|
|
13
|
-
"allowImportingTsExtensions": true,
|
|
14
|
-
"verbatimModuleSyntax": true,
|
|
15
|
-
"outDir": "dist",
|
|
16
|
-
"declaration": true,
|
|
17
|
-
"emitDeclarationOnly": true,
|
|
18
|
-
|
|
19
|
-
// Best practices
|
|
20
|
-
"strict": true,
|
|
21
|
-
"skipLibCheck": true,
|
|
22
|
-
"noFallthroughCasesInSwitch": true,
|
|
23
|
-
"noUncheckedIndexedAccess": true,
|
|
24
|
-
"noImplicitOverride": true,
|
|
25
|
-
|
|
26
|
-
// Some stricter flags (disabled by default)
|
|
27
|
-
"noUnusedLocals": false,
|
|
28
|
-
"noUnusedParameters": false,
|
|
29
|
-
"noPropertyAccessFromIndexSignature": false,
|
|
30
|
-
},
|
|
31
|
-
"include": ["src"],
|
|
32
|
-
}
|