pen-it 1.0.6 → 1.0.8
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 +31 -2
- package/dist/array/index.d.ts +0 -39
- package/dist/browser/index.d.ts +0 -29
- package/dist/control/index.d.ts +0 -8
- package/dist/cookie/index.d.ts +0 -7
- package/dist/copy/index.d.ts +0 -12
- package/dist/format/index.d.ts +0 -69
- package/dist/index.cjs +0 -294
- package/dist/index.js +0 -294
- package/dist/is/index.d.ts +0 -121
- package/dist/storage/index.d.ts +0 -9
- package/package.json +8 -16
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# pen-it
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
用“笔”锚定记忆,一个轻量级前端工具库,覆盖类型检查、日期格式化、数字处理、深克隆、本地存储、Cookie 及浏览器 API。零依赖,支持 Tree-shaking,让常用函数信手拈来。
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
@@ -572,4 +572,33 @@ import { isArray, formatFull, deepClone, unique } from 'pen-it'
|
|
|
572
572
|
const fn = throttle((val: string) => console.log(val), 500)
|
|
573
573
|
fn('a'); fn('b'); fn('c')
|
|
574
574
|
// => 'a',500ms 后输出 'c'
|
|
575
|
-
```
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
---
|
|
578
|
+
|
|
579
|
+
## 更新日志
|
|
580
|
+
|
|
581
|
+
### v1.0.7
|
|
582
|
+
|
|
583
|
+
- **体积优化** — 移除JSDoc `@example` 示例注释(共 294 行),减少包体积
|
|
584
|
+
- **文档** — README 底部新增更新日志模块
|
|
585
|
+
|
|
586
|
+
### v1.0.6
|
|
587
|
+
|
|
588
|
+
- **数组模块** — 新增 `mergeArrays` 数组合并、`flatten` 数组扁平化(支持任意层级)、`arrFind` 数组项查询、`groupBy` JSON 数组分组、`filterEmptyValues` 对象移除空值属性、`createRange` 快速生成范围数组
|
|
589
|
+
- **浏览器模块** — 新增 `observeIntersection` 可视区域检测(基于 IntersectionObserver)
|
|
590
|
+
|
|
591
|
+
### v1.0.5
|
|
592
|
+
|
|
593
|
+
- **控制模块** — 新增 `debounce` 防抖与 `throttle` 节流
|
|
594
|
+
|
|
595
|
+
### v1.0.4
|
|
596
|
+
|
|
597
|
+
- 初始版本,包含以下模块:
|
|
598
|
+
- **类型判断** — `isArray` `isObject` `is` `isFunction` `isAsyncFunction` `isPromise` `isDate` `isNumber` `isInt` `isFloat` `isString` `isBoolean` `isSymbol` `isPrimitive` `isNull` `isDef` `isUnDef` `isNullOrUnDef` `isEmpty` `isEmptySv` `isEqual` `isHexColor` `isValidEmail` `isPC` `isWindow` `isElement` `isIOS` 共 27 个函数
|
|
599
|
+
- **格式化** — 日期时间(`formatFull` `formatFullReplace` `formatYMD` `formatWeek`)、数字货币(`formatRmb` `formatNum` `percentCN` `compactEN` `compactCN` `signed`)、字符串(`maskPhone` `spacePhone` `capitalize` `kebabToCamel` `camelToKebab` `toCamel` `firstUpper` `firstLower` `reverse` `trimAll` `truncate` `truncateByWords`)共 22 个函数
|
|
600
|
+
- **存储** — `localGet` `localSet` `localRm` `localClear` 共 4 个函数
|
|
601
|
+
- **拷贝** — `deepClone` `deepCloneWithJSON` `shallowClone` 共 3 个函数
|
|
602
|
+
- **数组** — `unique` `uniqueByKey` `sortNumAsc` `sortNumDesc` `sortByKey` `toArray` 共 6 个函数
|
|
603
|
+
- **Cookie** — `setCookie` `getCookie` `delCookie` 共 3 个函数
|
|
604
|
+
- **浏览器** — `getUrlParams` `getUrlParam` `toQueryString` `copyToClipboard` `downloadFile` `exportJSON` `scrollToTop` `scrollToBottom` `onScroll` 共 9 个函数
|
package/dist/array/index.d.ts
CHANGED
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
* Set 去重
|
|
3
3
|
* @param arr - 数组
|
|
4
4
|
* @returns 去重后的数组
|
|
5
|
-
* @example
|
|
6
|
-
* unique([1, 2, 2, 3])
|
|
7
|
-
* // => [1, 2, 3]
|
|
8
5
|
*/
|
|
9
6
|
export declare const unique: <T>(arr: T[]) => T[];
|
|
10
7
|
/**
|
|
@@ -12,27 +9,18 @@ export declare const unique: <T>(arr: T[]) => T[];
|
|
|
12
9
|
* @param arr - 对象数组
|
|
13
10
|
* @param key - 用于去重判定的键名
|
|
14
11
|
* @returns 去重后的数组
|
|
15
|
-
* @example
|
|
16
|
-
* uniqueByKey([{ id: 1, name: "a" }, { id: 1, name: "b" }], "id")
|
|
17
|
-
* // => [{ id: 1, name: "a" }]
|
|
18
12
|
*/
|
|
19
13
|
export declare const uniqueByKey: <T extends Record<string, any>>(arr: T[], key: keyof T) => T[];
|
|
20
14
|
/**
|
|
21
15
|
* 数值升序
|
|
22
16
|
* @param arr - 数值数组
|
|
23
17
|
* @returns 升序排序后的新数组
|
|
24
|
-
* @example
|
|
25
|
-
* sortNumAsc([3, 1, 2])
|
|
26
|
-
* // => [1, 2, 3]
|
|
27
18
|
*/
|
|
28
19
|
export declare const sortNumAsc: (arr: number[]) => number[];
|
|
29
20
|
/**
|
|
30
21
|
* 数值降序
|
|
31
22
|
* @param arr - 数值数组
|
|
32
23
|
* @returns 降序排序后的新数组
|
|
33
|
-
* @example
|
|
34
|
-
* sortNumDesc([1, 3, 2])
|
|
35
|
-
* // => [3, 2, 1]
|
|
36
24
|
*/
|
|
37
25
|
export declare const sortNumDesc: (arr: number[]) => number[];
|
|
38
26
|
/**
|
|
@@ -41,27 +29,18 @@ export declare const sortNumDesc: (arr: number[]) => number[];
|
|
|
41
29
|
* @param key - 用于排序的属性名
|
|
42
30
|
* @param order - 排序方向,"asc" 升序 / "desc" 降序,默认 "asc"
|
|
43
31
|
* @returns 排序后的新数组
|
|
44
|
-
* @example
|
|
45
|
-
* sortByKey([{ age: 30 }, { age: 20 }], "age", "asc")
|
|
46
|
-
* // => [{ age: 20 }, { age: 30 }]
|
|
47
32
|
*/
|
|
48
33
|
export declare const sortByKey: <T extends Record<string, any>>(arr: T[], key: keyof T, order?: "asc" | "desc") => T[];
|
|
49
34
|
/**
|
|
50
35
|
* 类数组转数组
|
|
51
36
|
* @param arrayLike - 类数组对象(如 NodeList、arguments)
|
|
52
37
|
* @returns 转换后的数组
|
|
53
|
-
* @example
|
|
54
|
-
* toArray(document.querySelectorAll("div"))
|
|
55
|
-
* // => [div, div, ...]
|
|
56
38
|
*/
|
|
57
39
|
export declare const toArray: <T>(arrayLike: ArrayLike<T>) => T[];
|
|
58
40
|
/**
|
|
59
41
|
* 合并多个数组
|
|
60
42
|
* @param arrays - 一个或多个数组
|
|
61
43
|
* @returns 合并后的新数组
|
|
62
|
-
* @example
|
|
63
|
-
* mergeArrays([1, 2], [3, 4], [5])
|
|
64
|
-
* // => [1, 2, 3, 4, 5]
|
|
65
44
|
*/
|
|
66
45
|
export declare const mergeArrays: <T>(...arrays: T[][]) => T[];
|
|
67
46
|
/**
|
|
@@ -69,12 +48,6 @@ export declare const mergeArrays: <T>(...arrays: T[][]) => T[];
|
|
|
69
48
|
* @param arr - 多维数组
|
|
70
49
|
* @param depth - 扁平化深度,默认 1(仅展开一层)。传 Infinity 可完全扁平化为一维
|
|
71
50
|
* @returns 扁平化后的数组
|
|
72
|
-
* @example
|
|
73
|
-
* flatten([1, [2, [3, 4]], 5])
|
|
74
|
-
* // => [1, 2, [3, 4], 5]
|
|
75
|
-
* @example
|
|
76
|
-
* flatten([1, [2, [3, 4]], 5], Infinity)
|
|
77
|
-
* // => [1, 2, 3, 4, 5]
|
|
78
51
|
*/
|
|
79
52
|
export declare const flatten: <T>(arr: any[], depth?: number) => T[];
|
|
80
53
|
/**
|
|
@@ -83,9 +56,6 @@ export declare const flatten: <T>(arr: any[], depth?: number) => T[];
|
|
|
83
56
|
* @param key - 要匹配的键名
|
|
84
57
|
* @param value - 要匹配的键值
|
|
85
58
|
* @returns 第一个匹配的对象,无匹配则返回 undefined
|
|
86
|
-
* @example
|
|
87
|
-
* arrFind([{ id: 1, name: "a" }, { id: 2, name: "b" }], "id", 2)
|
|
88
|
-
* // => { id: 2, name: "b" }
|
|
89
59
|
*/
|
|
90
60
|
export declare const arrFind: <T extends Record<string, any>>(arr: T[], key: keyof T, value: T[keyof T]) => T | undefined;
|
|
91
61
|
/**
|
|
@@ -93,18 +63,12 @@ export declare const arrFind: <T extends Record<string, any>>(arr: T[], key: key
|
|
|
93
63
|
* @param arr - 对象数组
|
|
94
64
|
* @param key - 用于分组的属性名
|
|
95
65
|
* @returns 以属性值为键、对应数组为值的对象
|
|
96
|
-
* @example
|
|
97
|
-
* groupBy([{ type: "fruit", name: "apple" }, { type: "vegetable", name: "carrot" }], "type")
|
|
98
|
-
* // => { fruit: [{ type: "fruit", name: "apple" }], vegetable: [{ type: "vegetable", name: "carrot" }] }
|
|
99
66
|
*/
|
|
100
67
|
export declare const groupBy: <T extends Record<string, any>>(arr: T[], key: keyof T) => Record<string, T[]>;
|
|
101
68
|
/**
|
|
102
69
|
* 移除对象中值为空(null / undefined / 空字符串)的属性
|
|
103
70
|
* @param obj - 待过滤的对象
|
|
104
71
|
* @returns 过滤后的新对象
|
|
105
|
-
* @example
|
|
106
|
-
* filterEmptyValues({ a: 1, b: "", c: null, d: 3 })
|
|
107
|
-
* // => { a: 1, d: 3 }
|
|
108
72
|
*/
|
|
109
73
|
export declare const filterEmptyValues: <T extends Record<string, any>>(obj: T) => Partial<T>;
|
|
110
74
|
/**
|
|
@@ -112,8 +76,5 @@ export declare const filterEmptyValues: <T extends Record<string, any>>(obj: T)
|
|
|
112
76
|
* @param length - 数组长度
|
|
113
77
|
* @param mapFn - 映射函数,接收索引返回元素值,默认为返回索引
|
|
114
78
|
* @returns 生成的数组
|
|
115
|
-
* @example
|
|
116
|
-
* createRange(5)
|
|
117
|
-
* // => [0, 1, 2, 3, 4]
|
|
118
79
|
*/
|
|
119
80
|
export declare const createRange: <T = number>(length: number, mapFn?: (index: number) => T) => T[];
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
* 获取 URL 参数对象
|
|
3
3
|
* @param url - URL 字符串,默认使用当前页面地址
|
|
4
4
|
* @returns 参数键值对对象
|
|
5
|
-
* @example
|
|
6
|
-
* getUrlParams("https://example.com?a=1&b=2")
|
|
7
|
-
* // => { a: "1", b: "2" }
|
|
8
5
|
*/
|
|
9
6
|
export declare const getUrlParams: (url?: string) => Record<string, string>;
|
|
10
7
|
/**
|
|
@@ -12,18 +9,12 @@ export declare const getUrlParams: (url?: string) => Record<string, string>;
|
|
|
12
9
|
* @param key - 参数名
|
|
13
10
|
* @param url - URL 字符串,默认使用当前页面地址
|
|
14
11
|
* @returns 参数值,不存在则返回 null
|
|
15
|
-
* @example
|
|
16
|
-
* getUrlParam("a", "https://example.com?a=1")
|
|
17
|
-
* // => "1"
|
|
18
12
|
*/
|
|
19
13
|
export declare const getUrlParam: (key: string, url?: string) => string | null;
|
|
20
14
|
/**
|
|
21
15
|
* 对象转 URL 参数字符串
|
|
22
16
|
* @param params - 参数键值对对象,值为 null/undefined 的项会被过滤
|
|
23
17
|
* @returns URL 参数字符串(不含 ? 前缀)
|
|
24
|
-
* @example
|
|
25
|
-
* toQueryString({ a: 1, b: "hello", c: null })
|
|
26
|
-
* // => "a=1&b=hello"
|
|
27
18
|
*/
|
|
28
19
|
export declare const toQueryString: (params: Record<string, any>) => string;
|
|
29
20
|
/**
|
|
@@ -31,9 +22,6 @@ export declare const toQueryString: (params: Record<string, any>) => string;
|
|
|
31
22
|
* 优先使用 Clipboard API,失败时降级为 execCommand
|
|
32
23
|
* @param text - 要复制的文本
|
|
33
24
|
* @returns 复制成功返回 true,失败返回 false
|
|
34
|
-
* @example
|
|
35
|
-
* await copyToClipboard("Hello World")
|
|
36
|
-
* // => true
|
|
37
25
|
*/
|
|
38
26
|
export declare const copyToClipboard: (text: string) => Promise<boolean>;
|
|
39
27
|
/**
|
|
@@ -41,39 +29,28 @@ export declare const copyToClipboard: (text: string) => Promise<boolean>;
|
|
|
41
29
|
* @param content - 文件内容
|
|
42
30
|
* @param filename - 文件名
|
|
43
31
|
* @param mimeType - MIME 类型,默认 "text/plain"
|
|
44
|
-
* @example
|
|
45
|
-
* downloadFile("Hello", "hello.txt")
|
|
46
32
|
*/
|
|
47
33
|
export declare const downloadFile: (content: string | BlobPart, filename: string, mimeType?: string) => void;
|
|
48
34
|
/**
|
|
49
35
|
* 导出 JSON 为文件
|
|
50
36
|
* @param data - 要导出的数据
|
|
51
37
|
* @param filename - 文件名,默认 "data.json"
|
|
52
|
-
* @example
|
|
53
|
-
* exportJSON({ name: "张三", age: 30 })
|
|
54
38
|
*/
|
|
55
39
|
export declare const exportJSON: (data: any, filename?: string) => void;
|
|
56
40
|
/**
|
|
57
41
|
* 滚动到顶部
|
|
58
42
|
* @param behavior - 滚动行为,"smooth" 平滑 / "auto" 瞬间,默认 "smooth"
|
|
59
|
-
* @example
|
|
60
|
-
* scrollToTop()
|
|
61
43
|
*/
|
|
62
44
|
export declare const scrollToTop: (behavior?: ScrollBehavior) => void;
|
|
63
45
|
/**
|
|
64
46
|
* 滚动到底部
|
|
65
47
|
* @param behavior - 滚动行为,"smooth" 平滑 / "auto" 瞬间,默认 "smooth"
|
|
66
|
-
* @example
|
|
67
|
-
* scrollToBottom()
|
|
68
48
|
*/
|
|
69
49
|
export declare const scrollToBottom: (behavior?: ScrollBehavior) => void;
|
|
70
50
|
/**
|
|
71
51
|
* 监听页面滚动(requestAnimationFrame 节流)
|
|
72
52
|
* @param callback - 滚动回调,接收当前 scrollY 值
|
|
73
53
|
* @returns 清理函数,调用后移除事件监听
|
|
74
|
-
* @example
|
|
75
|
-
* const cleanup = onScroll((y) => console.log(y));
|
|
76
|
-
* cleanup(); // 停止监听
|
|
77
54
|
*/
|
|
78
55
|
export declare const onScroll: (callback: (scrollY: number) => void) => () => void;
|
|
79
56
|
/**
|
|
@@ -83,11 +60,5 @@ export declare const onScroll: (callback: (scrollY: number) => void) => () => vo
|
|
|
83
60
|
* @param onLeave - 元素离开可视区域时的回调(可选)
|
|
84
61
|
* @param options - IntersectionObserver 配置项
|
|
85
62
|
* @returns 清理函数,调用后停止观察
|
|
86
|
-
* @example
|
|
87
|
-
* const cleanup = observeIntersection(
|
|
88
|
-
* document.querySelector(".footer")!,
|
|
89
|
-
* () => loadMore(10),
|
|
90
|
-
* );
|
|
91
|
-
* cleanup(); // 停止观察
|
|
92
63
|
*/
|
|
93
64
|
export declare const observeIntersection: (target: Element, onEnter: (entry: IntersectionObserverEntry) => void, onLeave?: (entry: IntersectionObserverEntry) => void, options?: IntersectionObserverInit) => () => void;
|
package/dist/control/index.d.ts
CHANGED
|
@@ -5,10 +5,6 @@
|
|
|
5
5
|
* @param options.leading - 首次调用是否立即执行,默认 false
|
|
6
6
|
* @param options.trailing - 停止调用后是否延迟执行,默认 true
|
|
7
7
|
* @returns 防抖后的函数,附带 cancel 方法
|
|
8
|
-
* @example
|
|
9
|
-
* const fn = debounce((val: string) => console.log(val), 500)
|
|
10
|
-
* fn("a"); fn("b"); fn("c")
|
|
11
|
-
* // => "c"
|
|
12
8
|
*/
|
|
13
9
|
export declare const debounce: <T extends (...args: any[]) => any>(fn: T, delay?: number, { leading, trailing }?: {
|
|
14
10
|
leading?: boolean;
|
|
@@ -23,10 +19,6 @@ export declare const debounce: <T extends (...args: any[]) => any>(fn: T, delay?
|
|
|
23
19
|
* @param options.leading - 首次调用是否立即执行,默认 true
|
|
24
20
|
* @param options.trailing - 最后一次调用后是否尾部执行,默认 true
|
|
25
21
|
* @returns 节流后的函数,附带 cancel 方法
|
|
26
|
-
* @example
|
|
27
|
-
* const fn = throttle((val: string) => console.log(val), 500)
|
|
28
|
-
* fn("a"); fn("b"); fn("c")
|
|
29
|
-
* // => "a",500ms 后输出 "c"
|
|
30
22
|
*/
|
|
31
23
|
export declare const throttle: <T extends (...args: any[]) => any>(fn: T, interval?: number, { leading, trailing }?: {
|
|
32
24
|
leading?: boolean;
|
package/dist/cookie/index.d.ts
CHANGED
|
@@ -3,23 +3,16 @@
|
|
|
3
3
|
* @param name - Cookie 名称
|
|
4
4
|
* @param value - Cookie 值
|
|
5
5
|
* @param days - 有效天数,默认 7 天
|
|
6
|
-
* @example
|
|
7
|
-
* setCookie("token", "abc123", 30)
|
|
8
6
|
*/
|
|
9
7
|
export declare const setCookie: (name: string, value: string, days?: number) => void;
|
|
10
8
|
/**
|
|
11
9
|
* 获取 Cookie
|
|
12
10
|
* @param name - Cookie 名称
|
|
13
11
|
* @returns Cookie 值,不存在则返回 null
|
|
14
|
-
* @example
|
|
15
|
-
* getCookie("token")
|
|
16
|
-
* // => "abc123"
|
|
17
12
|
*/
|
|
18
13
|
export declare const getCookie: (name: string) => string | null;
|
|
19
14
|
/**
|
|
20
15
|
* 删除 Cookie
|
|
21
16
|
* @param name - Cookie 名称
|
|
22
|
-
* @example
|
|
23
|
-
* delCookie("token")
|
|
24
17
|
*/
|
|
25
18
|
export declare const delCookie: (name: string) => void;
|
package/dist/copy/index.d.ts
CHANGED
|
@@ -4,11 +4,6 @@
|
|
|
4
4
|
* @param obj - 要拷贝的值
|
|
5
5
|
* @param hash - 内部 WeakMap 用于处理循环引用,调用方无需传入
|
|
6
6
|
* @returns 深拷贝后的值
|
|
7
|
-
* @example
|
|
8
|
-
* const obj = { a: 1, b: { c: 2 }, d: new Date() };
|
|
9
|
-
* const cloned = deepClone(obj);
|
|
10
|
-
* // cloned.b !== obj.b
|
|
11
|
-
* // cloned.d !== obj.d
|
|
12
7
|
*/
|
|
13
8
|
export declare function deepClone<T>(obj: T, hash?: WeakMap<any, any>): T;
|
|
14
9
|
/**
|
|
@@ -17,9 +12,6 @@ export declare function deepClone<T>(obj: T, hash?: WeakMap<any, any>): T;
|
|
|
17
12
|
* (不支持函数、undefined、Date、RegExp、Map、Set 等)
|
|
18
13
|
* @param obj - 要拷贝的 JSON 安全值
|
|
19
14
|
* @returns 深拷贝后的值
|
|
20
|
-
* @example
|
|
21
|
-
* deepCloneWithJSON({ a: 1, b: [2, 3] })
|
|
22
|
-
* // => { a: 1, b: [2, 3] }
|
|
23
15
|
*/
|
|
24
16
|
export declare function deepCloneWithJSON<T>(obj: T): T;
|
|
25
17
|
/**
|
|
@@ -27,9 +19,5 @@ export declare function deepCloneWithJSON<T>(obj: T): T;
|
|
|
27
19
|
* 仅拷贝第一层属性,嵌套对象仍共享引用
|
|
28
20
|
* @param obj - 要拷贝的对象或数组
|
|
29
21
|
* @returns 浅拷贝后的值
|
|
30
|
-
* @example
|
|
31
|
-
* const obj = { a: 1, b: { c: 2 } };
|
|
32
|
-
* const cloned = shallowClone(obj);
|
|
33
|
-
* // cloned.b === obj.b(共享引用)
|
|
34
22
|
*/
|
|
35
23
|
export declare function shallowClone<T>(obj: T): T;
|
package/dist/format/index.d.ts
CHANGED
|
@@ -2,36 +2,24 @@
|
|
|
2
2
|
* 完整日期时间(年/月/日 时分秒)_ 斜杠
|
|
3
3
|
* @param date - Date 对象
|
|
4
4
|
* @returns 格式化后的完整日期时间字符串,如 "2026/06/03 14:30:45"
|
|
5
|
-
* @example
|
|
6
|
-
* formatFull(new Date("2026-06-03T14:30:45"))
|
|
7
|
-
* // => "2026/06/03 14:30:45"
|
|
8
5
|
*/
|
|
9
6
|
export declare const formatFull: (date: Date) => string;
|
|
10
7
|
/**
|
|
11
8
|
* 完整日期时间(年-月-日 时分秒)_ 短横线
|
|
12
9
|
* @param date - Date 对象
|
|
13
10
|
* @returns 格式化后的完整日期时间字符串,如 "2026-06-03 14:30:45"
|
|
14
|
-
* @example
|
|
15
|
-
* formatFullReplace(new Date("2026-06-03T14:30:45"))
|
|
16
|
-
* // => "2026-06-03 14:30:45"
|
|
17
11
|
*/
|
|
18
12
|
export declare const formatFullReplace: (date: Date) => string;
|
|
19
13
|
/**
|
|
20
14
|
* 中文年月日
|
|
21
15
|
* @param date - Date 对象
|
|
22
16
|
* @returns 格式化后的中文日期字符串,如 "2026年6月3日"
|
|
23
|
-
* @example
|
|
24
|
-
* formatYMD(new Date("2026-06-03"))
|
|
25
|
-
* // => "2026年6月3日"
|
|
26
17
|
*/
|
|
27
18
|
export declare const formatYMD: (date: Date) => string;
|
|
28
19
|
/**
|
|
29
20
|
* 星期几
|
|
30
21
|
* @param date - Date 对象
|
|
31
22
|
* @returns 中文星期字符串,如 "星期三"
|
|
32
|
-
* @example
|
|
33
|
-
* formatWeek(new Date("2026-06-03"))
|
|
34
|
-
* // => "星期三"
|
|
35
23
|
*/
|
|
36
24
|
export declare const formatWeek: (date: Date) => string;
|
|
37
25
|
/**
|
|
@@ -39,9 +27,6 @@ export declare const formatWeek: (date: Date) => string;
|
|
|
39
27
|
* @param value - 数值
|
|
40
28
|
* @param options - 格式化选项
|
|
41
29
|
* @returns 格式化后的货币字符串
|
|
42
|
-
* @example
|
|
43
|
-
* formatRmb(1234.56, { type: "zh-CN", currency: "CNY" })
|
|
44
|
-
* // => "¥1,234.56"
|
|
45
30
|
*/
|
|
46
31
|
export declare const formatRmb: (value: number, options: {
|
|
47
32
|
type: "zh-CN";
|
|
@@ -51,9 +36,6 @@ export declare const formatRmb: (value: number, options: {
|
|
|
51
36
|
* 千位分隔符(数字格式化),中文(逗号分隔)
|
|
52
37
|
* @param value - 数值
|
|
53
38
|
* @returns 格式化后的千位分隔数字字符串
|
|
54
|
-
* @example
|
|
55
|
-
* formatNum(1234567)
|
|
56
|
-
* // => "1,234,567"
|
|
57
39
|
*/
|
|
58
40
|
export declare const formatNum: (value: number) => string;
|
|
59
41
|
/**
|
|
@@ -61,27 +43,18 @@ export declare const formatNum: (value: number) => string;
|
|
|
61
43
|
* @param value - 百分比数值
|
|
62
44
|
* @param digit - 保留的小数位数,默认为 0
|
|
63
45
|
* @returns 格式化后的百分比字符串
|
|
64
|
-
* @example
|
|
65
|
-
* percentCN(0.1234, 2)
|
|
66
|
-
* // => "12.34%"
|
|
67
46
|
*/
|
|
68
47
|
export declare const percentCN: (value: number, digit?: number) => string;
|
|
69
48
|
/**
|
|
70
49
|
* 紧凑计数法(大数简化)_ 英文缩写
|
|
71
50
|
* @param value - 数值
|
|
72
51
|
* @returns 格式化后的紧凑数字字符串(英文缩写)
|
|
73
|
-
* @example
|
|
74
|
-
* compactEN(12345)
|
|
75
|
-
* // => "12K"
|
|
76
52
|
*/
|
|
77
53
|
export declare const compactEN: (value: number) => string;
|
|
78
54
|
/**
|
|
79
55
|
* 紧凑计数法(大数简化)_ 中文缩写
|
|
80
56
|
* @param value - 数值
|
|
81
57
|
* @returns 格式化后的紧凑数字字符串(中文缩写)
|
|
82
|
-
* @example
|
|
83
|
-
* compactCN(12345)
|
|
84
|
-
* // => "1.2万"
|
|
85
58
|
*/
|
|
86
59
|
export declare const compactCN: (value: number) => string;
|
|
87
60
|
/**
|
|
@@ -89,57 +62,36 @@ export declare const compactCN: (value: number) => string;
|
|
|
89
62
|
* @param value - 数值
|
|
90
63
|
* @param digit - 保留的小数位数,默认为 0
|
|
91
64
|
* @returns 格式化后的带正负号的数值显示
|
|
92
|
-
* @example
|
|
93
|
-
* signed(42, 1)
|
|
94
|
-
* // => "+42.0"
|
|
95
|
-
* @example
|
|
96
|
-
* signed(-5)
|
|
97
|
-
* // => "-5"
|
|
98
65
|
*/
|
|
99
66
|
export declare const signed: (value: number, digit?: number) => string;
|
|
100
67
|
/**
|
|
101
68
|
* 手机号格式化脱敏 _ 隐藏中间 4 位数
|
|
102
69
|
* @param phone - 手机号码
|
|
103
70
|
* @returns 手机号格式化脱敏后的手机号
|
|
104
|
-
* @example
|
|
105
|
-
* maskPhone("13812345678")
|
|
106
|
-
* // => "138****5678"
|
|
107
71
|
*/
|
|
108
72
|
export declare const maskPhone: (phone: string) => string;
|
|
109
73
|
/**
|
|
110
74
|
* 手机号格式化 _ 空格分隔
|
|
111
75
|
* @param phone - 手机号
|
|
112
76
|
* @returns 手机号空格格式化的手机号
|
|
113
|
-
* @example
|
|
114
|
-
* spacePhone("13812345678")
|
|
115
|
-
* // => "138 1234 5678"
|
|
116
77
|
*/
|
|
117
78
|
export declare const spacePhone: (phone: string) => string;
|
|
118
79
|
/**
|
|
119
80
|
* 每个单词首字母大写
|
|
120
81
|
* @param str - 字符串
|
|
121
82
|
* @returns 每个单词首字母大写后的字符串
|
|
122
|
-
* @example
|
|
123
|
-
* capitalize("hello world")
|
|
124
|
-
* // => "Hello World"
|
|
125
83
|
*/
|
|
126
84
|
export declare const capitalize: (str: string) => string;
|
|
127
85
|
/**
|
|
128
86
|
* 短横线连接转小驼峰(kebab-case → camelCase)
|
|
129
87
|
* @param str - 字符串
|
|
130
88
|
* @returns 转换后的小驼峰字符串
|
|
131
|
-
* @example
|
|
132
|
-
* kebabToCamel("hello-world")
|
|
133
|
-
* // => "helloWorld"
|
|
134
89
|
*/
|
|
135
90
|
export declare const kebabToCamel: (str: string) => string;
|
|
136
91
|
/**
|
|
137
92
|
* 大驼峰或小驼峰 _ 转为 ‘-’ 短横线连接
|
|
138
93
|
* @param str - 字符串
|
|
139
94
|
* @returns 大驼峰或小驼峰命名格式化的字符串
|
|
140
|
-
* @example
|
|
141
|
-
* camelToKebab("helloWorld")
|
|
142
|
-
* // => "hello-world"
|
|
143
95
|
*/
|
|
144
96
|
export declare const camelToKebab: (str: string) => string;
|
|
145
97
|
/**
|
|
@@ -148,9 +100,6 @@ export declare const camelToKebab: (str: string) => string;
|
|
|
148
100
|
* @param maxLength - 截断位置
|
|
149
101
|
* @param suffix - 自定义的替换截断后的内容
|
|
150
102
|
* @returns 超长文本截断后内容
|
|
151
|
-
* @example
|
|
152
|
-
* truncate("Hello World", 8)
|
|
153
|
-
* // => "Hello..."
|
|
154
103
|
*/
|
|
155
104
|
export declare const truncate: (str: string, maxLength: number, suffix?: string) => string;
|
|
156
105
|
/**
|
|
@@ -159,53 +108,35 @@ export declare const truncate: (str: string, maxLength: number, suffix?: string)
|
|
|
159
108
|
* @param maxWords - 截断位置
|
|
160
109
|
* @param suffix - 自定义的替换截断后的内容
|
|
161
110
|
* @returns 超长文本截断后内容
|
|
162
|
-
* @example
|
|
163
|
-
* truncateByWords("你好世界欢迎你", 4)
|
|
164
|
-
* // => "你好世界..."
|
|
165
111
|
*/
|
|
166
112
|
export declare const truncateByWords: (str: string, maxWords: number, suffix?: string) => string;
|
|
167
113
|
/**
|
|
168
114
|
* 去除所有空格 _ 前后中间
|
|
169
115
|
* @param str - 内容
|
|
170
116
|
* @returns 去除空格后的内容
|
|
171
|
-
* @example
|
|
172
|
-
* trimAll(" hello world ")
|
|
173
|
-
* // => "helloworld"
|
|
174
117
|
*/
|
|
175
118
|
export declare const trimAll: (str: string) => string;
|
|
176
119
|
/**
|
|
177
120
|
* 下划线转驼峰(snake_case → camelCase)
|
|
178
121
|
* @param str - 字符串
|
|
179
122
|
* @returns 转换后的驼峰字符串
|
|
180
|
-
* @example
|
|
181
|
-
* toCamel("hello_world")
|
|
182
|
-
* // => "helloWorld"
|
|
183
123
|
*/
|
|
184
124
|
export declare const toCamel: (str: string) => string;
|
|
185
125
|
/**
|
|
186
126
|
* 首字母大写
|
|
187
127
|
* @param str - 字符串
|
|
188
128
|
* @returns 首字母大写后的字符串
|
|
189
|
-
* @example
|
|
190
|
-
* firstUpper("hello")
|
|
191
|
-
* // => "Hello"
|
|
192
129
|
*/
|
|
193
130
|
export declare const firstUpper: (str: string) => string;
|
|
194
131
|
/**
|
|
195
132
|
* 首字母小写
|
|
196
133
|
* @param str - 字符串
|
|
197
134
|
* @returns 首字母小写后的字符串
|
|
198
|
-
* @example
|
|
199
|
-
* firstLower("Hello")
|
|
200
|
-
* // => "hello"
|
|
201
135
|
*/
|
|
202
136
|
export declare const firstLower: (str: string) => string;
|
|
203
137
|
/**
|
|
204
138
|
* 反转字符串
|
|
205
139
|
* @param str - 字符串
|
|
206
140
|
* @returns 反转后的字符串
|
|
207
|
-
* @example
|
|
208
|
-
* reverse("hello")
|
|
209
|
-
* // => "olleh"
|
|
210
141
|
*/
|
|
211
142
|
export declare const reverse: (str: string) => string;
|