@syzlm/function 1.0.5 → 1.0.6
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/docs/README.md +7 -2
- package/docs/functions/capitalize.md +1 -1
- package/docs/functions/chunk.md +2 -2
- package/docs/functions/clamp.md +1 -1
- package/docs/functions/debounce.md +1 -1
- package/docs/functions/deepClone.md +1 -1
- package/docs/functions/delay.md +1 -1
- package/docs/functions/get.md +1 -1
- package/docs/functions/getFontLength.md +1 -1
- package/docs/functions/getFontWidth.md +1 -1
- package/docs/functions/hasOwnProperty.md +1 -1
- package/docs/functions/isPlainObject.md +1 -1
- package/docs/functions/merge.md +1 -1
- package/docs/functions/parseQrcode.md +1 -1
- package/docs/functions/parseStrEmpty.md +1 -1
- package/docs/functions/randomString.md +1 -1
- package/docs/functions/range.md +1 -1
- package/docs/functions/round.md +1 -1
- package/docs/functions/set.md +1 -1
- package/docs/functions/shuffle.md +2 -2
- package/docs/functions/simpleUnique.md +1 -1
- package/docs/functions/thousandSign.md +1 -1
- package/docs/functions/thousandSignZero.md +1 -1
- package/docs/functions/throttle.md +1 -1
- package/docs/functions/toCamelCase.md +1 -1
- package/docs/functions/toFixed.md +1 -1
- package/docs/functions/unique.md +3 -3
- package/docs/variables/localStorage.md +71 -0
- package/docs/variables/sessionStorage.md +71 -0
- package/package.json +1 -1
- package/src/arrays/arrayUtils.ts +7 -2
package/docs/README.md
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
**Function - TypeScript 工具函数库 v1.0.
|
|
1
|
+
**Function - TypeScript 工具函数库 v1.0.5**
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
5
|
-
# Function - TypeScript 工具函数库 v1.0.
|
|
5
|
+
# Function - TypeScript 工具函数库 v1.0.5
|
|
6
|
+
|
|
7
|
+
## Variables
|
|
8
|
+
|
|
9
|
+
- [sessionStorage](variables/sessionStorage.md)
|
|
10
|
+
- [localStorage](variables/localStorage.md)
|
|
6
11
|
|
|
7
12
|
## Functions
|
|
8
13
|
|
package/docs/functions/chunk.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[**Function - TypeScript 工具函数库 v1.0.
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.5**](../README.md)
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
> **chunk**\<`T`\>(`arr`, `size`): `T`[][]
|
|
10
10
|
|
|
11
|
-
Defined in: arrays/arrayUtils.ts:
|
|
11
|
+
Defined in: arrays/arrayUtils.ts:65
|
|
12
12
|
|
|
13
13
|
数组分块函数
|
|
14
14
|
|
package/docs/functions/clamp.md
CHANGED
package/docs/functions/delay.md
CHANGED
package/docs/functions/get.md
CHANGED
package/docs/functions/merge.md
CHANGED
package/docs/functions/range.md
CHANGED
package/docs/functions/round.md
CHANGED
package/docs/functions/set.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[**Function - TypeScript 工具函数库 v1.0.
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.5**](../README.md)
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
> **shuffle**\<`T`\>(`arr`): `T`[]
|
|
10
10
|
|
|
11
|
-
Defined in: arrays/arrayUtils.ts:
|
|
11
|
+
Defined in: arrays/arrayUtils.ts:50
|
|
12
12
|
|
|
13
13
|
数组随机打乱函数
|
|
14
14
|
|
package/docs/functions/unique.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[**Function - TypeScript 工具函数库 v1.0.
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.5**](../README.md)
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
@@ -28,10 +28,10 @@ Defined in: arrays/arrayUtils.ts:21
|
|
|
28
28
|
|
|
29
29
|
### field?
|
|
30
30
|
|
|
31
|
-
`string`
|
|
32
|
-
|
|
33
31
|
对象数组去重需要传,对象数组去重对比字段
|
|
34
32
|
|
|
33
|
+
`string` | (`s`) => `string` \| `number`
|
|
34
|
+
|
|
35
35
|
## Returns
|
|
36
36
|
|
|
37
37
|
`T`[]
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.5**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / localStorage
|
|
6
|
+
|
|
7
|
+
# Variable: localStorage
|
|
8
|
+
|
|
9
|
+
> `const` **localStorage**: `object`
|
|
10
|
+
|
|
11
|
+
Defined in: storage/storage.ts:78
|
|
12
|
+
|
|
13
|
+
## Type Declaration
|
|
14
|
+
|
|
15
|
+
### setItem()
|
|
16
|
+
|
|
17
|
+
> **setItem**: (`k`, `a`) => `void`
|
|
18
|
+
|
|
19
|
+
#### Parameters
|
|
20
|
+
|
|
21
|
+
##### k
|
|
22
|
+
|
|
23
|
+
`string`
|
|
24
|
+
|
|
25
|
+
##### a
|
|
26
|
+
|
|
27
|
+
`any`
|
|
28
|
+
|
|
29
|
+
#### Returns
|
|
30
|
+
|
|
31
|
+
`void`
|
|
32
|
+
|
|
33
|
+
### getItem()
|
|
34
|
+
|
|
35
|
+
> **getItem**: (`k`, `needParse`) => `any`
|
|
36
|
+
|
|
37
|
+
#### Parameters
|
|
38
|
+
|
|
39
|
+
##### k
|
|
40
|
+
|
|
41
|
+
`string`
|
|
42
|
+
|
|
43
|
+
##### needParse
|
|
44
|
+
|
|
45
|
+
`boolean` = `true`
|
|
46
|
+
|
|
47
|
+
#### Returns
|
|
48
|
+
|
|
49
|
+
`any`
|
|
50
|
+
|
|
51
|
+
### removeItem()
|
|
52
|
+
|
|
53
|
+
> **removeItem**: (`k`) => `void`
|
|
54
|
+
|
|
55
|
+
#### Parameters
|
|
56
|
+
|
|
57
|
+
##### k
|
|
58
|
+
|
|
59
|
+
`string`
|
|
60
|
+
|
|
61
|
+
#### Returns
|
|
62
|
+
|
|
63
|
+
`void`
|
|
64
|
+
|
|
65
|
+
### clear()
|
|
66
|
+
|
|
67
|
+
> **clear**: () => `void`
|
|
68
|
+
|
|
69
|
+
#### Returns
|
|
70
|
+
|
|
71
|
+
`void`
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
[**Function - TypeScript 工具函数库 v1.0.5**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Function - TypeScript 工具函数库](../README.md) / sessionStorage
|
|
6
|
+
|
|
7
|
+
# Variable: sessionStorage
|
|
8
|
+
|
|
9
|
+
> `const` **sessionStorage**: `object`
|
|
10
|
+
|
|
11
|
+
Defined in: storage/storage.ts:70
|
|
12
|
+
|
|
13
|
+
## Type Declaration
|
|
14
|
+
|
|
15
|
+
### setItem()
|
|
16
|
+
|
|
17
|
+
> **setItem**: (`k`, `a`) => `void`
|
|
18
|
+
|
|
19
|
+
#### Parameters
|
|
20
|
+
|
|
21
|
+
##### k
|
|
22
|
+
|
|
23
|
+
`string`
|
|
24
|
+
|
|
25
|
+
##### a
|
|
26
|
+
|
|
27
|
+
`any`
|
|
28
|
+
|
|
29
|
+
#### Returns
|
|
30
|
+
|
|
31
|
+
`void`
|
|
32
|
+
|
|
33
|
+
### getItem()
|
|
34
|
+
|
|
35
|
+
> **getItem**: (`k`, `needParse`) => `any`
|
|
36
|
+
|
|
37
|
+
#### Parameters
|
|
38
|
+
|
|
39
|
+
##### k
|
|
40
|
+
|
|
41
|
+
`string`
|
|
42
|
+
|
|
43
|
+
##### needParse
|
|
44
|
+
|
|
45
|
+
`boolean` = `true`
|
|
46
|
+
|
|
47
|
+
#### Returns
|
|
48
|
+
|
|
49
|
+
`any`
|
|
50
|
+
|
|
51
|
+
### removeItem()
|
|
52
|
+
|
|
53
|
+
> **removeItem**: (`k`) => `void`
|
|
54
|
+
|
|
55
|
+
#### Parameters
|
|
56
|
+
|
|
57
|
+
##### k
|
|
58
|
+
|
|
59
|
+
`string`
|
|
60
|
+
|
|
61
|
+
#### Returns
|
|
62
|
+
|
|
63
|
+
`void`
|
|
64
|
+
|
|
65
|
+
### clear()
|
|
66
|
+
|
|
67
|
+
> **clear**: () => `void`
|
|
68
|
+
|
|
69
|
+
#### Returns
|
|
70
|
+
|
|
71
|
+
`void`
|
package/package.json
CHANGED
package/src/arrays/arrayUtils.ts
CHANGED
|
@@ -20,12 +20,17 @@ export function simpleUnique<T>(arr: T[]): T[] {
|
|
|
20
20
|
*/
|
|
21
21
|
export function unique<T extends Record<string, any>>(
|
|
22
22
|
arr: T[],
|
|
23
|
-
field?: string
|
|
23
|
+
field?: string | ((s: T) => string | number)
|
|
24
24
|
): T[] {
|
|
25
25
|
if (field && arr?.length) {
|
|
26
26
|
const map = new Map();
|
|
27
27
|
return arr.reduce<T[]>((res, cur) => {
|
|
28
|
-
|
|
28
|
+
let uniqueKey;
|
|
29
|
+
if (typeof field === 'string') {
|
|
30
|
+
uniqueKey = cur[field];
|
|
31
|
+
} else if (typeof field === 'function') {
|
|
32
|
+
uniqueKey = field(cur);
|
|
33
|
+
}
|
|
29
34
|
if (!map.has(uniqueKey)) {
|
|
30
35
|
map.set(uniqueKey, true);
|
|
31
36
|
res.push(cur);
|