@syzlm/function 1.0.0 → 1.0.1
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/dist/arrays/arrayUtils.d.ts +13 -1
- package/dist/arrays/arrayUtils.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/objects/objectUtils.d.ts +7 -0
- package/dist/objects/objectUtils.d.ts.map +1 -1
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/storage.d.ts +13 -0
- package/dist/storage/storage.d.ts.map +1 -0
- package/dist/strings/stringUtils.d.ts.map +1 -1
- package/docs/README.md +32 -0
- package/docs/functions/capitalize.md +27 -0
- package/docs/functions/chunk.md +39 -0
- package/docs/functions/clamp.md +39 -0
- package/docs/functions/debounce.md +49 -0
- package/docs/functions/deepClone.md +33 -0
- package/docs/functions/delay.md +27 -0
- package/docs/functions/get.md +39 -0
- package/docs/functions/getFontLength.md +27 -0
- package/docs/functions/getFontWidth.md +33 -0
- package/docs/functions/isPlainObject.md +27 -0
- package/docs/functions/merge.md +39 -0
- package/docs/functions/parseStrEmpty.md +27 -0
- package/docs/functions/randomString.md +27 -0
- package/docs/functions/range.md +39 -0
- package/docs/functions/round.md +33 -0
- package/docs/functions/set.md +45 -0
- package/docs/functions/shuffle.md +33 -0
- package/docs/functions/simpleUnique.md +40 -0
- package/docs/functions/thousandSign.md +27 -0
- package/docs/functions/thousandSignZero.md +33 -0
- package/docs/functions/throttle.md +49 -0
- package/docs/functions/toCamelCase.md +27 -0
- package/docs/functions/toFixed.md +33 -0
- package/docs/functions/unique.md +39 -0
- package/package.json +22 -4
- package/src/arrays/arrayUtils.ts +33 -3
- package/src/arrays/index.ts +1 -1
- package/src/numbers/index.ts +1 -1
- package/src/numbers/numberUtils.ts +7 -7
- package/src/objects/index.ts +1 -1
- package/src/objects/objectUtils.ts +18 -13
- package/src/storage/storage.ts +5 -4
- package/src/strings/index.ts +1 -1
- package/src/strings/stringUtils.ts +11 -9
- package/src/utils/index.ts +1 -1
- package/src/utils/utilFunctions.ts +3 -3
- package/README.md +0 -111
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -85
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1633
- package/docs/functions/capitalize.html +0 -4
- package/docs/functions/chunk.html +0 -5
- package/docs/functions/clamp.html +0 -6
- package/docs/functions/debounce.html +0 -5
- package/docs/functions/deepClone.html +0 -4
- package/docs/functions/delay.html +0 -4
- package/docs/functions/get.html +0 -6
- package/docs/functions/getFontLength.html +0 -4
- package/docs/functions/getFontWidth.html +0 -5
- package/docs/functions/isPlainObject.html +0 -4
- package/docs/functions/merge.html +0 -5
- package/docs/functions/parseStrEmpty.html +0 -4
- package/docs/functions/randomString.html +0 -4
- package/docs/functions/range.html +0 -6
- package/docs/functions/round.html +0 -5
- package/docs/functions/set.html +0 -6
- package/docs/functions/shuffle.html +0 -4
- package/docs/functions/thousandSign.html +0 -4
- package/docs/functions/thousandSignZero.html +0 -5
- package/docs/functions/throttle.html +0 -5
- package/docs/functions/toCamelCase.html +0 -4
- package/docs/functions/toFixed.html +0 -5
- package/docs/functions/unique.html +0 -4
- package/docs/hierarchy.html +0 -1
- package/docs/index.html +0 -53
- package/docs/modules.html +0 -1
- package/jest.config.js +0 -8
- package/rollup.config.js +0 -29
- package/scripts/deploy-docs.sh +0 -40
- package/test-output.txt +0 -23
- package/test-tofixed.js +0 -36
- package/tests/arrays.test.ts +0 -89
- package/tests/numbers.test.ts +0 -140
- package/tests/objects.test.ts +0 -189
- package/tests/strings.test.ts +0 -197
- package/tests/utils.test.ts +0 -121
- package/tsconfig.json +0 -21
- package/typedoc.json +0 -15
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / parseStrEmpty
|
|
6
|
+
|
|
7
|
+
# Function: parseStrEmpty()
|
|
8
|
+
|
|
9
|
+
> **parseStrEmpty**(`str`): `string`
|
|
10
|
+
|
|
11
|
+
Defined in: strings/stringUtils.ts:42
|
|
12
|
+
|
|
13
|
+
转换字符串,undefined,null等转化为""
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### str
|
|
18
|
+
|
|
19
|
+
`string`
|
|
20
|
+
|
|
21
|
+
需要转换的字符串
|
|
22
|
+
|
|
23
|
+
## Returns
|
|
24
|
+
|
|
25
|
+
`string`
|
|
26
|
+
|
|
27
|
+
转换后的字符串
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / randomString
|
|
6
|
+
|
|
7
|
+
# Function: randomString()
|
|
8
|
+
|
|
9
|
+
> **randomString**(`length`): `string`
|
|
10
|
+
|
|
11
|
+
Defined in: strings/stringUtils.ts:27
|
|
12
|
+
|
|
13
|
+
生成随机字符串函数
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### length
|
|
18
|
+
|
|
19
|
+
`number`
|
|
20
|
+
|
|
21
|
+
字符串长度
|
|
22
|
+
|
|
23
|
+
## Returns
|
|
24
|
+
|
|
25
|
+
`string`
|
|
26
|
+
|
|
27
|
+
随机字符串
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / range
|
|
6
|
+
|
|
7
|
+
# Function: range()
|
|
8
|
+
|
|
9
|
+
> **range**(`start`, `end`, `step`): `number`[]
|
|
10
|
+
|
|
11
|
+
Defined in: numbers/numberUtils.ts:8
|
|
12
|
+
|
|
13
|
+
数字范围生成函数
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### start
|
|
18
|
+
|
|
19
|
+
`number`
|
|
20
|
+
|
|
21
|
+
起始数字
|
|
22
|
+
|
|
23
|
+
### end
|
|
24
|
+
|
|
25
|
+
`number`
|
|
26
|
+
|
|
27
|
+
结束数字
|
|
28
|
+
|
|
29
|
+
### step
|
|
30
|
+
|
|
31
|
+
`number` = `1`
|
|
32
|
+
|
|
33
|
+
步长
|
|
34
|
+
|
|
35
|
+
## Returns
|
|
36
|
+
|
|
37
|
+
`number`[]
|
|
38
|
+
|
|
39
|
+
生成的数字数组
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / round
|
|
6
|
+
|
|
7
|
+
# Function: round()
|
|
8
|
+
|
|
9
|
+
> **round**(`num`, `decimals`): `number`
|
|
10
|
+
|
|
11
|
+
Defined in: numbers/numberUtils.ts:22
|
|
12
|
+
|
|
13
|
+
数字四舍五入函数
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### num
|
|
18
|
+
|
|
19
|
+
`number`
|
|
20
|
+
|
|
21
|
+
需要四舍五入的数字
|
|
22
|
+
|
|
23
|
+
### decimals
|
|
24
|
+
|
|
25
|
+
`number` = `0`
|
|
26
|
+
|
|
27
|
+
保留小数位数
|
|
28
|
+
|
|
29
|
+
## Returns
|
|
30
|
+
|
|
31
|
+
`number`
|
|
32
|
+
|
|
33
|
+
四舍五入后的数字
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / set
|
|
6
|
+
|
|
7
|
+
# Function: set()
|
|
8
|
+
|
|
9
|
+
> **set**\<`T`\>(`obj`, `path`, `value`): `T`
|
|
10
|
+
|
|
11
|
+
Defined in: objects/objectUtils.ts:70
|
|
12
|
+
|
|
13
|
+
设置对象属性值(支持路径访问)
|
|
14
|
+
|
|
15
|
+
## Type Parameters
|
|
16
|
+
|
|
17
|
+
### T
|
|
18
|
+
|
|
19
|
+
`T` *extends* `Record`\<`string`, `any`\>
|
|
20
|
+
|
|
21
|
+
## Parameters
|
|
22
|
+
|
|
23
|
+
### obj
|
|
24
|
+
|
|
25
|
+
`T`
|
|
26
|
+
|
|
27
|
+
目标对象
|
|
28
|
+
|
|
29
|
+
### path
|
|
30
|
+
|
|
31
|
+
`string`
|
|
32
|
+
|
|
33
|
+
属性路径,如 'a.b.c'
|
|
34
|
+
|
|
35
|
+
### value
|
|
36
|
+
|
|
37
|
+
`any`
|
|
38
|
+
|
|
39
|
+
要设置的值
|
|
40
|
+
|
|
41
|
+
## Returns
|
|
42
|
+
|
|
43
|
+
`T`
|
|
44
|
+
|
|
45
|
+
设置后的对象
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / shuffle
|
|
6
|
+
|
|
7
|
+
# Function: shuffle()
|
|
8
|
+
|
|
9
|
+
> **shuffle**\<`T`\>(`arr`): `T`[]
|
|
10
|
+
|
|
11
|
+
Defined in: arrays/arrayUtils.ts:45
|
|
12
|
+
|
|
13
|
+
数组随机打乱函数
|
|
14
|
+
|
|
15
|
+
## Type Parameters
|
|
16
|
+
|
|
17
|
+
### T
|
|
18
|
+
|
|
19
|
+
`T`
|
|
20
|
+
|
|
21
|
+
## Parameters
|
|
22
|
+
|
|
23
|
+
### arr
|
|
24
|
+
|
|
25
|
+
`T`[]
|
|
26
|
+
|
|
27
|
+
需要打乱的数组
|
|
28
|
+
|
|
29
|
+
## Returns
|
|
30
|
+
|
|
31
|
+
`T`[]
|
|
32
|
+
|
|
33
|
+
打乱后的新数组
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / simpleUnique
|
|
6
|
+
|
|
7
|
+
# Function: simpleUnique()
|
|
8
|
+
|
|
9
|
+
> **simpleUnique**\<`T`\>(`arr`): `T`[]
|
|
10
|
+
|
|
11
|
+
Defined in: arrays/arrayUtils.ts:11
|
|
12
|
+
|
|
13
|
+
简单数组去重函数
|
|
14
|
+
|
|
15
|
+
## Type Parameters
|
|
16
|
+
|
|
17
|
+
### T
|
|
18
|
+
|
|
19
|
+
`T`
|
|
20
|
+
|
|
21
|
+
## Parameters
|
|
22
|
+
|
|
23
|
+
### arr
|
|
24
|
+
|
|
25
|
+
`T`[]
|
|
26
|
+
|
|
27
|
+
需要去重的数组
|
|
28
|
+
|
|
29
|
+
## Returns
|
|
30
|
+
|
|
31
|
+
`T`[]
|
|
32
|
+
|
|
33
|
+
去重后的新数组
|
|
34
|
+
|
|
35
|
+
## Example
|
|
36
|
+
|
|
37
|
+
``` javascript
|
|
38
|
+
import {simpleUnique} from '@syzlm/function/arrays';
|
|
39
|
+
console.log(simpleUnique([1,3,4,56,1,3]))
|
|
40
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / thousandSign
|
|
6
|
+
|
|
7
|
+
# Function: thousandSign()
|
|
8
|
+
|
|
9
|
+
> **thousandSign**(`num`): `string`
|
|
10
|
+
|
|
11
|
+
Defined in: strings/stringUtils.ts:90
|
|
12
|
+
|
|
13
|
+
千分位格式化
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### num
|
|
18
|
+
|
|
19
|
+
需要格式化的数字或字符串
|
|
20
|
+
|
|
21
|
+
`string` | `number`
|
|
22
|
+
|
|
23
|
+
## Returns
|
|
24
|
+
|
|
25
|
+
`string`
|
|
26
|
+
|
|
27
|
+
千分位格式化后的字符串
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / thousandSignZero
|
|
6
|
+
|
|
7
|
+
# Function: thousandSignZero()
|
|
8
|
+
|
|
9
|
+
> **thousandSignZero**(`num`, `fixed?`): `string`
|
|
10
|
+
|
|
11
|
+
Defined in: strings/stringUtils.ts:110
|
|
12
|
+
|
|
13
|
+
千分位格式化 自动补零
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### num
|
|
18
|
+
|
|
19
|
+
需要格式化的数字或字符串
|
|
20
|
+
|
|
21
|
+
`string` | `number`
|
|
22
|
+
|
|
23
|
+
### fixed?
|
|
24
|
+
|
|
25
|
+
`number`
|
|
26
|
+
|
|
27
|
+
保留的小数位数,默认2位
|
|
28
|
+
|
|
29
|
+
## Returns
|
|
30
|
+
|
|
31
|
+
`string`
|
|
32
|
+
|
|
33
|
+
千分位格式化后的字符串
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / throttle
|
|
6
|
+
|
|
7
|
+
# Function: throttle()
|
|
8
|
+
|
|
9
|
+
> **throttle**\<`T`\>(`func`, `limit`): (...`args`) => `void`
|
|
10
|
+
|
|
11
|
+
Defined in: utils/utilFunctions.ts:24
|
|
12
|
+
|
|
13
|
+
节流函数
|
|
14
|
+
|
|
15
|
+
## Type Parameters
|
|
16
|
+
|
|
17
|
+
### T
|
|
18
|
+
|
|
19
|
+
`T` *extends* (...`args`) => `any`
|
|
20
|
+
|
|
21
|
+
## Parameters
|
|
22
|
+
|
|
23
|
+
### func
|
|
24
|
+
|
|
25
|
+
`T`
|
|
26
|
+
|
|
27
|
+
需要节流的函数
|
|
28
|
+
|
|
29
|
+
### limit
|
|
30
|
+
|
|
31
|
+
`number`
|
|
32
|
+
|
|
33
|
+
限制时间(毫秒)
|
|
34
|
+
|
|
35
|
+
## Returns
|
|
36
|
+
|
|
37
|
+
节流后的函数
|
|
38
|
+
|
|
39
|
+
> (...`args`): `void`
|
|
40
|
+
|
|
41
|
+
### Parameters
|
|
42
|
+
|
|
43
|
+
#### args
|
|
44
|
+
|
|
45
|
+
...`Parameters`\<`T`\>
|
|
46
|
+
|
|
47
|
+
### Returns
|
|
48
|
+
|
|
49
|
+
`void`
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / toCamelCase
|
|
6
|
+
|
|
7
|
+
# Function: toCamelCase()
|
|
8
|
+
|
|
9
|
+
> **toCamelCase**(`str`): `string`
|
|
10
|
+
|
|
11
|
+
Defined in: strings/stringUtils.ts:8
|
|
12
|
+
|
|
13
|
+
字符串驼峰命名转换函数
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### str
|
|
18
|
+
|
|
19
|
+
`string`
|
|
20
|
+
|
|
21
|
+
需要转换的字符串
|
|
22
|
+
|
|
23
|
+
## Returns
|
|
24
|
+
|
|
25
|
+
`string`
|
|
26
|
+
|
|
27
|
+
驼峰命名的字符串
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / toFixed
|
|
6
|
+
|
|
7
|
+
# Function: toFixed()
|
|
8
|
+
|
|
9
|
+
> **toFixed**(`num`, `digits`): `string`
|
|
10
|
+
|
|
11
|
+
Defined in: numbers/numberUtils.ts:44
|
|
12
|
+
|
|
13
|
+
精确的数字toFixed函数
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### num
|
|
18
|
+
|
|
19
|
+
`number`
|
|
20
|
+
|
|
21
|
+
需要处理的数字
|
|
22
|
+
|
|
23
|
+
### digits
|
|
24
|
+
|
|
25
|
+
`number` = `0`
|
|
26
|
+
|
|
27
|
+
保留小数位数
|
|
28
|
+
|
|
29
|
+
## Returns
|
|
30
|
+
|
|
31
|
+
`string`
|
|
32
|
+
|
|
33
|
+
格式化后的字符串
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / unique
|
|
6
|
+
|
|
7
|
+
# Function: unique()
|
|
8
|
+
|
|
9
|
+
> **unique**\<`T`\>(`arr`, `field?`): `T`[]
|
|
10
|
+
|
|
11
|
+
Defined in: arrays/arrayUtils.ts:21
|
|
12
|
+
|
|
13
|
+
数组去重函数
|
|
14
|
+
|
|
15
|
+
## Type Parameters
|
|
16
|
+
|
|
17
|
+
### T
|
|
18
|
+
|
|
19
|
+
`T` *extends* `Record`\<`string`, `any`\>
|
|
20
|
+
|
|
21
|
+
## Parameters
|
|
22
|
+
|
|
23
|
+
### arr
|
|
24
|
+
|
|
25
|
+
`T`[]
|
|
26
|
+
|
|
27
|
+
需要去重的数组
|
|
28
|
+
|
|
29
|
+
### field?
|
|
30
|
+
|
|
31
|
+
`string`
|
|
32
|
+
|
|
33
|
+
对象数组去重需要传,对象数组去重对比字段
|
|
34
|
+
|
|
35
|
+
## Returns
|
|
36
|
+
|
|
37
|
+
`T`[]
|
|
38
|
+
|
|
39
|
+
去重后的新数组
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syzlm/function",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": {
|
|
9
10
|
"import": "./dist/index.js",
|
|
@@ -11,14 +12,23 @@
|
|
|
11
12
|
"types": "./dist/index.d.ts"
|
|
12
13
|
}
|
|
13
14
|
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"docs",
|
|
18
|
+
"src"
|
|
19
|
+
],
|
|
14
20
|
"scripts": {
|
|
15
21
|
"build": "rollup -c && tsc --emitDeclarationOnly",
|
|
16
22
|
"watch": "rollup -c -w",
|
|
17
|
-
"docs": "typedoc",
|
|
23
|
+
"docs": "typedoc ",
|
|
18
24
|
"docs:serve": "typedoc && npx serve docs",
|
|
19
25
|
"docs:update": "typedoc",
|
|
20
26
|
"build:with-docs": "rollup -c && tsc --emitDeclarationOnly && typedoc",
|
|
21
|
-
"test": "jest --verbose"
|
|
27
|
+
"test": "jest --verbose",
|
|
28
|
+
"lint": "eslint src/**/*.ts",
|
|
29
|
+
"lint:fix": "eslint src/**/*.ts --fix",
|
|
30
|
+
"format": "prettier --write src/**/*.ts",
|
|
31
|
+
"format:check": "prettier --check src/**/*.ts"
|
|
22
32
|
},
|
|
23
33
|
"keywords": [],
|
|
24
34
|
"author": "",
|
|
@@ -31,13 +41,21 @@
|
|
|
31
41
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
32
42
|
"@types/jest": "^30.0.0",
|
|
33
43
|
"@types/node": "^24.10.1",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^8.49.0",
|
|
45
|
+
"@typescript-eslint/parser": "^8.49.0",
|
|
46
|
+
"eslint": "^9.39.1",
|
|
47
|
+
"eslint-config-prettier": "^10.1.8",
|
|
48
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
34
49
|
"jest": "^30.2.0",
|
|
50
|
+
"prettier": "^3.7.4",
|
|
35
51
|
"rollup": "^2.79.2",
|
|
36
52
|
"serve": "^14.2.5",
|
|
37
53
|
"ts-jest": "^29.4.6",
|
|
38
54
|
"ts-node": "^10.9.2",
|
|
39
55
|
"tslib": "^2.8.1",
|
|
40
56
|
"typedoc": "^0.28.15",
|
|
57
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
41
58
|
"typescript": "^5.9.3"
|
|
42
|
-
}
|
|
59
|
+
},
|
|
60
|
+
"homepage": "https://gitee.com/unemployed-company/function/tree/master/docs"
|
|
43
61
|
}
|
package/src/arrays/arrayUtils.ts
CHANGED
|
@@ -1,12 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 简单数组去重函数
|
|
3
3
|
* @param arr 需要去重的数组
|
|
4
4
|
* @returns 去重后的新数组
|
|
5
|
+
* @example
|
|
6
|
+
* ``` javascript
|
|
7
|
+
* import {simpleUnique} from '@syzlm/function/arrays';
|
|
8
|
+
* console.log(simpleUnique([1,3,4,56,1,3]))
|
|
9
|
+
* ```
|
|
5
10
|
*/
|
|
6
|
-
export function
|
|
11
|
+
export function simpleUnique<T>(arr: T[]): T[] {
|
|
7
12
|
return [...new Set(arr)];
|
|
8
13
|
}
|
|
9
14
|
|
|
15
|
+
/**
|
|
16
|
+
* 数组去重函数
|
|
17
|
+
* @param arr 需要去重的数组
|
|
18
|
+
* @param field 对象数组去重需要传,对象数组去重对比字段
|
|
19
|
+
* @returns 去重后的新数组
|
|
20
|
+
*/
|
|
21
|
+
export function unique<T extends Record<string, any>>(
|
|
22
|
+
arr: T[],
|
|
23
|
+
field?: string
|
|
24
|
+
): T[] {
|
|
25
|
+
if (field && arr?.length) {
|
|
26
|
+
const map = new Map();
|
|
27
|
+
return arr.reduce<T[]>((res, cur) => {
|
|
28
|
+
const uniqueKey = field ? cur[field] : JSON.stringify(cur);
|
|
29
|
+
if (!map.has(uniqueKey)) {
|
|
30
|
+
map.set(uniqueKey, true);
|
|
31
|
+
res.push(cur);
|
|
32
|
+
}
|
|
33
|
+
return res;
|
|
34
|
+
}, []);
|
|
35
|
+
} else {
|
|
36
|
+
return [...new Set(arr)];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
10
40
|
/**
|
|
11
41
|
* 数组随机打乱函数
|
|
12
42
|
* @param arr 需要打乱的数组
|
|
@@ -33,4 +63,4 @@ export function chunk<T>(arr: T[], size: number): T[][] {
|
|
|
33
63
|
result.push(arr.slice(i, i + size));
|
|
34
64
|
}
|
|
35
65
|
return result;
|
|
36
|
-
}
|
|
66
|
+
}
|
package/src/arrays/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// 数组工具函数目录入口
|
|
2
|
-
export * from './arrayUtils';
|
|
2
|
+
export * from './arrayUtils';
|
package/src/numbers/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// 数字工具函数目录入口
|
|
2
|
-
export * from './numberUtils';
|
|
2
|
+
export * from './numberUtils';
|
|
@@ -55,7 +55,7 @@ export function toFixed(num: number, digits: number = 0): string {
|
|
|
55
55
|
let exp = parseInt(exponent);
|
|
56
56
|
let [intPart, decPart] = base.split('.');
|
|
57
57
|
decPart = decPart || '';
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
if (exp >= 0) {
|
|
60
60
|
// 科学计数法表示的是整数
|
|
61
61
|
numStr = intPart + decPart.padEnd(exp, '0');
|
|
@@ -79,13 +79,13 @@ export function toFixed(num: number, digits: number = 0): string {
|
|
|
79
79
|
// 需要四舍五入
|
|
80
80
|
let roundDigit = parseInt(decimalPart[digits]);
|
|
81
81
|
let newDecimalPart = decimalPart.slice(0, digits);
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
// 如果下一位大于等于5,则进位
|
|
84
84
|
if (roundDigit >= 5) {
|
|
85
85
|
// 将小数部分转换为数字加1
|
|
86
86
|
let carry = 1;
|
|
87
87
|
const newDecimalArray = newDecimalPart.split('');
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
// 从小数部分的最后一位开始处理进位
|
|
90
90
|
for (let i = newDecimalArray.length - 1; i >= 0 && carry > 0; i--) {
|
|
91
91
|
let digit = parseInt(newDecimalArray[i]) + carry;
|
|
@@ -97,15 +97,15 @@ export function toFixed(num: number, digits: number = 0): string {
|
|
|
97
97
|
carry = 0;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
|
|
101
101
|
newDecimalPart = newDecimalArray.join('');
|
|
102
|
-
|
|
102
|
+
|
|
103
103
|
// 如果小数部分全部进位了,则整数部分加1
|
|
104
104
|
if (carry > 0) {
|
|
105
105
|
integerPart = (parseInt(integerPart) + 1).toString();
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
|
|
108
|
+
|
|
109
109
|
decimalPart = newDecimalPart;
|
|
110
110
|
} else {
|
|
111
111
|
// 不足位数补零
|
|
@@ -118,4 +118,4 @@ export function toFixed(num: number, digits: number = 0): string {
|
|
|
118
118
|
} else {
|
|
119
119
|
return (isNegative ? '-' : '') + integerPart + '.' + decimalPart;
|
|
120
120
|
}
|
|
121
|
-
}
|
|
121
|
+
}
|
package/src/objects/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// 对象工具函数目录入口
|
|
2
|
-
export * from './objectUtils';
|
|
2
|
+
export * from './objectUtils';
|