nhanh-pure-function 3.0.6-beta.5 → 3.0.6-beta.7
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/LICENSE +21 -21
- package/README.md +18 -18
- package/dist/Format/index.d.ts +36 -0
- package/dist/Types/index.d.ts +14 -2
- package/dist/index.cjs.js +3 -3
- package/dist/index.es.js +458 -406
- package/package.json +46 -46
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 ADMINnhanh
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 ADMINnhanh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
# nhanh-pure-function
|
|
2
|
-
|
|
3
|
-
纯函数工具库,提供了一些常用的纯函数工具,帮助您在 JavaScript/TypeScript 项目中更高效地处理数据。
|
|
4
|
-
|
|
5
|
-
## 安装
|
|
6
|
-
|
|
7
|
-
您可以通过 npm 安装该库:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install nhanh-pure-function
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## 功能介绍
|
|
14
|
-
|
|
15
|
-
`nhanh-pure-function` 库旨在提供一系列纯函数,这些函数在处理数据时不会产生副作用,确保函数的输入和输出之间的映射关系是确定的。这使得代码更易于测试、维护和复用。
|
|
16
|
-
|
|
17
|
-
## 许可证
|
|
18
|
-
|
|
1
|
+
# nhanh-pure-function
|
|
2
|
+
|
|
3
|
+
纯函数工具库,提供了一些常用的纯函数工具,帮助您在 JavaScript/TypeScript 项目中更高效地处理数据。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
您可以通过 npm 安装该库:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install nhanh-pure-function
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 功能介绍
|
|
14
|
+
|
|
15
|
+
`nhanh-pure-function` 库旨在提供一系列纯函数,这些函数在处理数据时不会产生副作用,确保函数的输入和输出之间的映射关系是确定的。这使得代码更易于测试、维护和复用。
|
|
16
|
+
|
|
17
|
+
## 许可证
|
|
18
|
+
|
|
19
19
|
[MIT](https://opensource.org/licenses/MIT)
|
package/dist/Format/index.d.ts
CHANGED
|
@@ -73,3 +73,39 @@ export declare function _Format_CamelCase(str: string, isRemoveDelimiter?: boole
|
|
|
73
73
|
* @returns 裁减后的字符串
|
|
74
74
|
*/
|
|
75
75
|
export declare function _Format_ExcludeSubstring(inputString: string, substringToDelete: string, delimiter?: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* 处理不可见字符的转义和还原
|
|
78
|
+
* @param {string} str - 要处理的字符串
|
|
79
|
+
* @param {boolean} escape - true表示转义(默认),false表示还原
|
|
80
|
+
* @returns {string} 处理后的字符串
|
|
81
|
+
*/
|
|
82
|
+
export declare function _Format_ToggleInvisibleChars(str: string, escape?: boolean): string;
|
|
83
|
+
declare const UnitConfigs: readonly [readonly ["年", number], readonly ["月", number], readonly ["周", number], readonly ["天", number], readonly ["时", number], readonly ["分", number], readonly ["秒", 1000], readonly ["毫秒", 1]];
|
|
84
|
+
type UnitName = (typeof UnitConfigs)[number][0];
|
|
85
|
+
/**
|
|
86
|
+
* 格式化毫秒数为易读的时间单位(基于固定换算规则)
|
|
87
|
+
* @param ms 待格式化的毫秒数(需为非负整数)
|
|
88
|
+
* @param maxUnit 最大单位限制(可选,如传入"天"则最大只显示到天,不显示年/月/周)
|
|
89
|
+
* 可选值:"年"|"月"|"周"|"天"|"时"|"分"|"秒"|"毫秒"
|
|
90
|
+
* @returns 格式化后的时间字符串(如 1.3秒、300毫秒、1,234年)
|
|
91
|
+
* @description
|
|
92
|
+
* 1. 单位换算规则(固定值,非自然时间):
|
|
93
|
+
* - 1年 = 365天(忽略闰年差异)
|
|
94
|
+
* - 1月 = 30天(忽略实际月份天数差异)
|
|
95
|
+
* - 1周 = 7天,1天 = 24小时,1小时 = 60分钟,1分钟 = 60秒,1秒 = 1000毫秒
|
|
96
|
+
* 2. 格式化逻辑:
|
|
97
|
+
* - 自动匹配不超过最大单位限制的最优单位(数值≥单位阈值时使用该单位)
|
|
98
|
+
* - 非整数数值保留1位小数(如1.3秒),整数自动去除末尾.0(如1秒而非1.0秒)
|
|
99
|
+
* - "年"单位数值会自动应用千分位格式化(如1,234年)
|
|
100
|
+
* 3. 输入校验:非整数或负数会返回"0毫秒"
|
|
101
|
+
*/
|
|
102
|
+
export declare function _Format_MillisecondToReadable(ms: number, maxUnit?: UnitName): string;
|
|
103
|
+
/**
|
|
104
|
+
* 将数组按指定长度分割成多个子数组
|
|
105
|
+
* @param arr 要分割的原始数组
|
|
106
|
+
* @param size 每个子数组的长度
|
|
107
|
+
* @returns 分割后的二维数组
|
|
108
|
+
* @throws 当size小于1时抛出错误
|
|
109
|
+
*/
|
|
110
|
+
export declare function _Format_ChunkArray<T>(arr: T[], size: number): T[][];
|
|
111
|
+
export {};
|
package/dist/Types/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* type RequiredName = RequiredBy<User, 'name'>
|
|
9
9
|
* // 结果:{ name: string; age?: number; id: string }
|
|
10
10
|
*/
|
|
11
|
-
export type
|
|
11
|
+
export type _Type_RequiredBy<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>;
|
|
12
12
|
/**
|
|
13
13
|
* 将类型 T 中指定的属性 K 改为可选,其他属性保持原有状态(必填/可选)
|
|
14
14
|
* @template T - 原始类型
|
|
@@ -19,4 +19,16 @@ export type RequiredBy<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>
|
|
|
19
19
|
* type OptionalAge = PartialBy<User, 'age'>
|
|
20
20
|
* // 结果:{ name: string; age?: number; id?: string }
|
|
21
21
|
*/
|
|
22
|
-
export type
|
|
22
|
+
export type _Type_PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
23
|
+
/**
|
|
24
|
+
* 递归将类型T的所有属性(包括嵌套对象的属性)转为可选
|
|
25
|
+
* @template T - 要处理的基础类型
|
|
26
|
+
* @description 与TypeScript内置的Partial不同,DeepPartial会对嵌套对象进行递归处理,
|
|
27
|
+
* 使所有层级的属性都变为可选。适用于需要部分更新对象且允许深层属性缺失的场景
|
|
28
|
+
*/
|
|
29
|
+
export type _Type_DeepPartial<T> = {
|
|
30
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
31
|
+
};
|
|
32
|
+
export type _Type_Mutable<T> = {
|
|
33
|
+
-readonly [P in keyof T]: T[P];
|
|
34
|
+
};
|