@tmagic/utils 1.4.5 → 1.4.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/dist/tmagic-utils.js +2 -2
- package/dist/tmagic-utils.js.map +1 -1
- package/dist/tmagic-utils.umd.cjs +2 -2
- package/dist/tmagic-utils.umd.cjs.map +1 -1
- package/package.json +10 -5
- package/src/index.ts +7 -5
- package/types/index.d.ts +2 -2
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.4.
|
|
2
|
+
"version": "1.4.7",
|
|
3
3
|
"name": "@tmagic/utils",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/tmagic-utils.umd.cjs",
|
|
@@ -28,16 +28,21 @@
|
|
|
28
28
|
"dayjs": "^1.11.11",
|
|
29
29
|
"lodash-es": "^4.17.21"
|
|
30
30
|
},
|
|
31
|
-
"peerDependencies": {
|
|
32
|
-
"@tmagic/schema": "1.4.5"
|
|
33
|
-
},
|
|
34
31
|
"devDependencies": {
|
|
35
32
|
"@types/lodash-es": "^4.17.4",
|
|
36
33
|
"@types/node": "^18.19.0",
|
|
37
34
|
"rimraf": "^3.0.2",
|
|
38
|
-
"typescript": "^5.4.2",
|
|
39
35
|
"vite": "^5.2.11"
|
|
40
36
|
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"typescript": "*",
|
|
39
|
+
"@tmagic/schema": "1.4.7"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"typescript": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
45
|
+
},
|
|
41
46
|
"scripts": {
|
|
42
47
|
"build": "rimraf ./dist && npm run build:type && vite build --mode=es && vite build --mode=umd",
|
|
43
48
|
"build:type": "npm run clear:type && tsc --declaration --emitDeclarationOnly --project tsconfig.build.json",
|
package/src/index.ts
CHANGED
|
@@ -25,8 +25,6 @@ import { NodeType } from '@tmagic/schema';
|
|
|
25
25
|
|
|
26
26
|
export * from './dom';
|
|
27
27
|
|
|
28
|
-
dayjs.extend(utc);
|
|
29
|
-
|
|
30
28
|
export const sleep = (ms: number): Promise<void> =>
|
|
31
29
|
new Promise((resolve) => {
|
|
32
30
|
const timer = setTimeout(() => {
|
|
@@ -45,6 +43,7 @@ export const datetimeFormatter = (
|
|
|
45
43
|
if (['x', 'timestamp'].includes(format)) {
|
|
46
44
|
time = dayjs(v).valueOf();
|
|
47
45
|
} else if ((typeof v === 'string' && v.includes('Z')) || v.constructor === Date) {
|
|
46
|
+
dayjs.extend(utc);
|
|
48
47
|
// UTC字符串时间或Date对象格式化为北京时间
|
|
49
48
|
time = dayjs(v).utcOffset(8).format(format);
|
|
50
49
|
} else {
|
|
@@ -165,9 +164,12 @@ export const guid = (digit = 8): string =>
|
|
|
165
164
|
return v.toString(16);
|
|
166
165
|
});
|
|
167
166
|
|
|
168
|
-
export const getValueByKeyPath
|
|
167
|
+
export const getValueByKeyPath = (
|
|
168
|
+
keys: number | string | string[] = '',
|
|
169
|
+
data: Record<string | number, any> = {},
|
|
170
|
+
): any => {
|
|
169
171
|
// 将 array[0] 转成 array.0
|
|
170
|
-
const keyArray = Array.isArray(keys) ? keys : keys
|
|
172
|
+
const keyArray = Array.isArray(keys) ? keys : `${keys}`.replaceAll(/\[(\d+)\]/g, '.$1').split('.');
|
|
171
173
|
return keyArray.reduce((accumulator, currentValue: any) => {
|
|
172
174
|
if (isObject(accumulator) || Array.isArray(accumulator)) {
|
|
173
175
|
return accumulator[currentValue];
|
|
@@ -177,7 +179,7 @@ export const getValueByKeyPath: any = (keys: string | string[] = '', data: Recor
|
|
|
177
179
|
}, data);
|
|
178
180
|
};
|
|
179
181
|
|
|
180
|
-
export const setValueByKeyPath
|
|
182
|
+
export const setValueByKeyPath = (keys: string | number, value: any, data: Record<string | number, any> = {}): any =>
|
|
181
183
|
objectSet(data, keys, value);
|
|
182
184
|
|
|
183
185
|
export const getNodes = (ids: Id[], data: MNode[] = []): MNode[] => {
|
package/types/index.d.ts
CHANGED
|
@@ -27,8 +27,8 @@ export declare const isSameDomain: (targetUrl?: string, source?: string) => bool
|
|
|
27
27
|
* @returns
|
|
28
28
|
*/
|
|
29
29
|
export declare const guid: (digit?: number) => string;
|
|
30
|
-
export declare const getValueByKeyPath: any;
|
|
31
|
-
export declare const setValueByKeyPath: any;
|
|
30
|
+
export declare const getValueByKeyPath: (keys?: number | string | string[], data?: Record<string | number, any>) => any;
|
|
31
|
+
export declare const setValueByKeyPath: (keys: string | number, value: any, data?: Record<string | number, any>) => any;
|
|
32
32
|
export declare const getNodes: (ids: Id[], data?: MNode[]) => MNode[];
|
|
33
33
|
export declare const getDepKeys: (dataSourceDeps: DataSourceDeps | undefined, nodeId: Id) => Id[];
|
|
34
34
|
export declare const getDepNodeIds: (dataSourceDeps?: DataSourceDeps) => string[];
|