nhanh-pure-function 1.3.2 → 1.3.4
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/lib/User/User.js +1 -1
- package/lib/Utility/Utility.d.ts +11 -0
- package/lib/Utility/Utility.js +21 -2
- package/package.json +1 -1
package/lib/User/User.js
CHANGED
package/lib/Utility/Utility.d.ts
CHANGED
|
@@ -192,6 +192,17 @@ export function _CopyToClipboard(text: string): Promise<void>;
|
|
|
192
192
|
*/
|
|
193
193
|
export function _FormatFileSize(size: number): string;
|
|
194
194
|
|
|
195
|
+
/**
|
|
196
|
+
* 根据路径初始化目标对象
|
|
197
|
+
* 如果路径中某个属性不存在,则会创建该属性及其所有父属性
|
|
198
|
+
* 最终返回路径的最后一个属性对应的值或undefined(如果路径不存在)
|
|
199
|
+
*
|
|
200
|
+
* @param {Object} model - 要初始化的模型对象
|
|
201
|
+
* @param {string} path - 属性路径,使用英文句点分隔
|
|
202
|
+
* @returns {any} 路径的最后一个属性对应的值或undefined
|
|
203
|
+
*/
|
|
204
|
+
export function _InitTargetByPath(model: any, path: string): any;
|
|
205
|
+
|
|
195
206
|
/**
|
|
196
207
|
* 根据路径获取目标对象
|
|
197
208
|
* 该函数用于在给定的模型中,通过路径字符串来获取深层嵌套的目标对象如果路径中的某一部分不存在,则会创建一个新的对象(除非已经是路径的最后一部分)
|
package/lib/Utility/Utility.js
CHANGED
|
@@ -426,6 +426,25 @@ export function _FormatFileSize(size) {
|
|
|
426
426
|
return `${Math.round(size * 100) / 100} ${units[unitIndex]}`;
|
|
427
427
|
}
|
|
428
428
|
|
|
429
|
+
/**
|
|
430
|
+
* 根据路径初始化目标对象
|
|
431
|
+
* 如果路径中某个属性不存在,则会创建该属性及其所有父属性
|
|
432
|
+
* 最终返回路径的最后一个属性对应的值或undefined(如果路径不存在)
|
|
433
|
+
*
|
|
434
|
+
* @param {Object} model - 要初始化的模型对象
|
|
435
|
+
* @param {string} path - 属性路径,使用英文句点分隔
|
|
436
|
+
* @returns {any} 路径的最后一个属性对应的值或undefined
|
|
437
|
+
*/
|
|
438
|
+
export function _InitTargetByPath(model, path) {
|
|
439
|
+
const arr = path.split(".");
|
|
440
|
+
return arr.reduce((prev, curr, index) => {
|
|
441
|
+
if (!(curr in prev)) {
|
|
442
|
+
if (index === arr.length - 1) prev[curr] = undefined;
|
|
443
|
+
else prev[curr] = {};
|
|
444
|
+
}
|
|
445
|
+
return prev[curr];
|
|
446
|
+
}, model);
|
|
447
|
+
}
|
|
429
448
|
/**
|
|
430
449
|
* 根据路径获取目标对象
|
|
431
450
|
* 该函数用于在给定的模型中,通过路径字符串来获取深层嵌套的目标对象如果路径中的某一部分不存在,则会创建一个新的对象(除非已经是路径的最后一部分)
|
|
@@ -439,7 +458,7 @@ export function _GetTargetByPath(model, path) {
|
|
|
439
458
|
return arr.reduce((prev, curr, index) => {
|
|
440
459
|
if (prev.hasOwnProperty(curr)) return prev[curr];
|
|
441
460
|
return (prev[curr] = index == arr.length - 1 ? undefined : {});
|
|
442
|
-
}, model
|
|
461
|
+
}, model);
|
|
443
462
|
}
|
|
444
463
|
/**
|
|
445
464
|
* 根据路径更新目标值
|
|
@@ -457,5 +476,5 @@ export function _UpdateTargetByPath(model, path, value) {
|
|
|
457
476
|
return arr.reduce((prev, curr, index) => {
|
|
458
477
|
if (index === arr.length - 1) prev[curr] = value;
|
|
459
478
|
return prev[curr];
|
|
460
|
-
}, model
|
|
479
|
+
}, model);
|
|
461
480
|
}
|