@base-web-kits/base-tools-ts 0.9.99 → 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/base-tools-ts.umd.global.js +265 -0
- package/dist/base-tools-ts.umd.global.js.map +1 -1
- package/dist/index.cjs +267 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +265 -0
- package/dist/index.js.map +1 -1
- package/dist/object/index.d.ts +24 -0
- package/dist/object/index.d.ts.map +1 -1
- package/package.json +36 -37
- package/src/ts/object/index.ts +27 -0
package/dist/object/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { get, set } from 'es-toolkit/compat';
|
|
1
2
|
/**
|
|
2
3
|
* 获取对象键名数组(类型安全)。
|
|
3
4
|
* 注:内置 `Object.keys` 与 `es-toolkit` 的 `keys` 在 TS 中通常返回 `string[]`,无法精确到 `keyof T`。
|
|
@@ -8,4 +9,27 @@
|
|
|
8
9
|
* const keys = getObjectKeys(o); // type: ('a' | 'b')[], value: ['a','b']
|
|
9
10
|
*/
|
|
10
11
|
export declare function getObjectKeys<T extends object>(obj: T): Array<keyof T>;
|
|
12
|
+
/**
|
|
13
|
+
* 获取对象值。
|
|
14
|
+
* @param obj 目标对象
|
|
15
|
+
* @param path 路径。(点路径:'a.b'、'a[0].b';数组路径:['a',0,'b'])
|
|
16
|
+
* @returns 值
|
|
17
|
+
* @example
|
|
18
|
+
* const o = { b: { c: 'x' }, users: [{ name: 'john' }, { name: 'jane' }] };
|
|
19
|
+
* const c = getObjectValue(o, 'b.c'); // 点路径: 'x'
|
|
20
|
+
* const name0 = getObjectValue(o, 'users[0].name'); // 数组字符: 'john'
|
|
21
|
+
* const name1 = getObjectValue(o, ['users', 1, 'name']); // 数组路径: 'jane'
|
|
22
|
+
*/
|
|
23
|
+
export declare const getObjectValue: typeof get;
|
|
24
|
+
/**
|
|
25
|
+
* 设置对象值。
|
|
26
|
+
* @param obj 目标对象
|
|
27
|
+
* @param path 路径。(点路径:'a.b'、'a[0].b';数组路径:['a',0,'b'])
|
|
28
|
+
* @param value 值
|
|
29
|
+
* @example
|
|
30
|
+
* const o = { b: { c: 'x' }, users: [{ name: 'john' }, { name: 'jane' }] };
|
|
31
|
+
* setObjectValue(o, 'b.c', 'y'); // 点路径
|
|
32
|
+
* setObjectValue(o, ['users', 1, 'name'], 'jane-doe'); // 数组路径
|
|
33
|
+
*/
|
|
34
|
+
export declare const setObjectValue: typeof set;
|
|
11
35
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ts/object/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAEtE"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ts/object/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAEtE;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,YAAM,CAAC;AAElC;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,YAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,37 +1,36 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@base-web-kits/base-tools-ts",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"sideEffects": false,
|
|
5
|
-
"description": "Independent TS utilities package built from src/ts.",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"base-tools",
|
|
8
|
-
"ts",
|
|
9
|
-
"utilities"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@base-web-kits/base-tools-ts",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"description": "Independent TS utilities package built from src/ts.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"base-tools",
|
|
8
|
+
"ts",
|
|
9
|
+
"utilities"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist/index.cjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"README.md",
|
|
25
|
+
"src"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"es-toolkit": "^1.42.0",
|
|
29
|
+
"bignumber.js": "^9.1.2",
|
|
30
|
+
"dayjs": "^1.11.19",
|
|
31
|
+
"mitt": "^3.0.1"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"registry": "https://registry.npmjs.org"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/ts/object/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { get, set } from 'es-toolkit/compat';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* 获取对象键名数组(类型安全)。
|
|
3
5
|
* 注:内置 `Object.keys` 与 `es-toolkit` 的 `keys` 在 TS 中通常返回 `string[]`,无法精确到 `keyof T`。
|
|
@@ -10,3 +12,28 @@
|
|
|
10
12
|
export function getObjectKeys<T extends object>(obj: T): Array<keyof T> {
|
|
11
13
|
return Object.keys(obj) as (keyof T)[];
|
|
12
14
|
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 获取对象值。
|
|
18
|
+
* @param obj 目标对象
|
|
19
|
+
* @param path 路径。(点路径:'a.b'、'a[0].b';数组路径:['a',0,'b'])
|
|
20
|
+
* @returns 值
|
|
21
|
+
* @example
|
|
22
|
+
* const o = { b: { c: 'x' }, users: [{ name: 'john' }, { name: 'jane' }] };
|
|
23
|
+
* const c = getObjectValue(o, 'b.c'); // 点路径: 'x'
|
|
24
|
+
* const name0 = getObjectValue(o, 'users[0].name'); // 数组字符: 'john'
|
|
25
|
+
* const name1 = getObjectValue(o, ['users', 1, 'name']); // 数组路径: 'jane'
|
|
26
|
+
*/
|
|
27
|
+
export const getObjectValue = get;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 设置对象值。
|
|
31
|
+
* @param obj 目标对象
|
|
32
|
+
* @param path 路径。(点路径:'a.b'、'a[0].b';数组路径:['a',0,'b'])
|
|
33
|
+
* @param value 值
|
|
34
|
+
* @example
|
|
35
|
+
* const o = { b: { c: 'x' }, users: [{ name: 'john' }, { name: 'jane' }] };
|
|
36
|
+
* setObjectValue(o, 'b.c', 'y'); // 点路径
|
|
37
|
+
* setObjectValue(o, ['users', 1, 'name'], 'jane-doe'); // 数组路径
|
|
38
|
+
*/
|
|
39
|
+
export const setObjectValue = set;
|