@aimidy/util 1.0.4 → 1.0.5
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/index.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -37,13 +37,29 @@ declare function gettype<T = any>(obj: T): "string" | "number" | "bigint" | "boo
|
|
|
37
37
|
*/
|
|
38
38
|
declare function parameterMerge(value1?: any, value2?: any): any;
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* 回傳物件的第一個值或者空值
|
|
42
|
+
* @param arr
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
declare function head<T = any>(arr: Array<T>): T | null;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 透過 JSON 複製物件
|
|
49
|
+
* @param obj 要複製的物件
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
declare function deepCloneWithJson<T>(obj: T): any;
|
|
53
|
+
|
|
40
54
|
declare const index_data_set: typeof data_set;
|
|
55
|
+
declare const index_deepCloneWithJson: typeof deepCloneWithJson;
|
|
41
56
|
declare const index_emptyData: typeof emptyData;
|
|
42
57
|
declare const index_gettype: typeof gettype;
|
|
58
|
+
declare const index_head: typeof head;
|
|
43
59
|
declare const index_parameterMerge: typeof parameterMerge;
|
|
44
60
|
declare const index_recursiveDeepCopy: typeof recursiveDeepCopy;
|
|
45
61
|
declare namespace index {
|
|
46
|
-
export { index_data_set as data_set, index_emptyData as emptyData, index_gettype as gettype, index_parameterMerge as parameterMerge, index_recursiveDeepCopy as recursiveDeepCopy };
|
|
62
|
+
export { index_data_set as data_set, index_deepCloneWithJson as deepCloneWithJson, index_emptyData as emptyData, index_gettype as gettype, index_head as head, index_parameterMerge as parameterMerge, index_recursiveDeepCopy as recursiveDeepCopy };
|
|
47
63
|
}
|
|
48
64
|
|
|
49
65
|
export { index as help };
|
package/dist/index.d.ts
CHANGED
|
@@ -37,13 +37,29 @@ declare function gettype<T = any>(obj: T): "string" | "number" | "bigint" | "boo
|
|
|
37
37
|
*/
|
|
38
38
|
declare function parameterMerge(value1?: any, value2?: any): any;
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* 回傳物件的第一個值或者空值
|
|
42
|
+
* @param arr
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
declare function head<T = any>(arr: Array<T>): T | null;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 透過 JSON 複製物件
|
|
49
|
+
* @param obj 要複製的物件
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
declare function deepCloneWithJson<T>(obj: T): any;
|
|
53
|
+
|
|
40
54
|
declare const index_data_set: typeof data_set;
|
|
55
|
+
declare const index_deepCloneWithJson: typeof deepCloneWithJson;
|
|
41
56
|
declare const index_emptyData: typeof emptyData;
|
|
42
57
|
declare const index_gettype: typeof gettype;
|
|
58
|
+
declare const index_head: typeof head;
|
|
43
59
|
declare const index_parameterMerge: typeof parameterMerge;
|
|
44
60
|
declare const index_recursiveDeepCopy: typeof recursiveDeepCopy;
|
|
45
61
|
declare namespace index {
|
|
46
|
-
export { index_data_set as data_set, index_emptyData as emptyData, index_gettype as gettype, index_parameterMerge as parameterMerge, index_recursiveDeepCopy as recursiveDeepCopy };
|
|
62
|
+
export { index_data_set as data_set, index_deepCloneWithJson as deepCloneWithJson, index_emptyData as emptyData, index_gettype as gettype, index_head as head, index_parameterMerge as parameterMerge, index_recursiveDeepCopy as recursiveDeepCopy };
|
|
47
63
|
}
|
|
48
64
|
|
|
49
65
|
export { index as help };
|
package/dist/index.js
CHANGED
|
@@ -28,8 +28,10 @@ module.exports = __toCommonJS(src_exports);
|
|
|
28
28
|
var help_exports = {};
|
|
29
29
|
__export(help_exports, {
|
|
30
30
|
data_set: () => data_set,
|
|
31
|
+
deepCloneWithJson: () => deepCloneWithJson,
|
|
31
32
|
emptyData: () => emptyData,
|
|
32
33
|
gettype: () => gettype,
|
|
34
|
+
head: () => head,
|
|
33
35
|
parameterMerge: () => parameterMerge,
|
|
34
36
|
recursiveDeepCopy: () => recursiveDeepCopy
|
|
35
37
|
});
|
|
@@ -106,6 +108,18 @@ function parameterMerge(value1, value2) {
|
|
|
106
108
|
return {};
|
|
107
109
|
}
|
|
108
110
|
}
|
|
111
|
+
|
|
112
|
+
// src/help/head/head.ts
|
|
113
|
+
function head(arr) {
|
|
114
|
+
if (gettype(arr) !== "array")
|
|
115
|
+
return null;
|
|
116
|
+
return arr.length > 0 ? arr[0] : null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/help/deepCloneWithJson/deepCloneWithJson.ts
|
|
120
|
+
function deepCloneWithJson(obj) {
|
|
121
|
+
return JSON.parse(JSON.stringify(obj));
|
|
122
|
+
}
|
|
109
123
|
// Annotate the CommonJS export names for ESM import in node:
|
|
110
124
|
0 && (module.exports = {
|
|
111
125
|
help
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/help/index.ts","../src/help/data_set/data_set.ts","../src/help/recursiveDeepCopy/recursiveDeepCopy.ts","../src/help/emptyData/emptyData.ts","../src/help/gettype/gettype.ts","../src/help/parameterMerge/parameterMerge.ts"],"sourcesContent":["export * as help from './help';","export * from './data_set/data_set';\r\nexport * from './recursiveDeepCopy/recursiveDeepCopy';\r\nexport * from './emptyData/emptyData';\r\nexport * from './gettype/gettype';\r\nexport * from './parameterMerge/parameterMerge';","/**\r\n * 動態設定多層物件的參數\r\n * @param data 被設定的物件\r\n * @param key 位置\r\n * @param value 參數\r\n * @returns \r\n */\r\nexport function data_set(data: any, key: string, value: any) {\r\n const keys = key.split(\".\");\r\n const firstKey = keys.shift();\r\n if (!firstKey) return;\r\n\r\n if (!(firstKey in data))\r\n data[firstKey] = {};\r\n\r\n if (keys.length < 1) {\r\n data[firstKey] = value;\r\n return\r\n }\r\n data_set(data[firstKey], keys.join(\".\"), value);\r\n}","/**\r\n* 透過遞迴複製物件\r\n* @param o \r\n* @returns \r\n*/\r\nexport function recursiveDeepCopy<T = any>(o: T): T {\r\n switch (Object.prototype.toString.apply(o)) {\r\n case \"[object Array]\":\r\n const tempArry: any = [];\r\n (o as Array<any>).forEach(value => {\r\n (tempArry as Array<any>).push(recursiveDeepCopy(value));\r\n })\r\n return tempArry;\r\n case \"[object Object]\":\r\n const tempO: any = {};\r\n Object.keys(o as Object).forEach(key => {\r\n if (Object.prototype.hasOwnProperty.call(o, key))\r\n tempO[key] = recursiveDeepCopy((o as { [_: string]: any })[key]);\r\n })\r\n return tempO;\r\n default:\r\n return o;\r\n }\r\n}","/**\r\n * 判斷資料是否為空值\r\n * @param data \r\n * @returns \r\n */\r\nexport function emptyData(data: any) {\r\n return typeof data === \"undefined\" || data === null\r\n}","/**\r\n * 回傳物體的型態\r\n * @param obj \r\n * @returns \r\n */\r\nexport function gettype<T = any>(obj: T) {\r\n switch (true) {\r\n case obj instanceof Array:\r\n return 'array';\r\n case obj instanceof Date:\r\n return 'date';\r\n case obj === null:\r\n return 'null';\r\n default:\r\n return typeof obj;\r\n }\r\n}","import { gettype, recursiveDeepCopy } from \"..\";\r\n\r\n/**\r\n * 兩個參數的合併(只能是物件或者陣列)\r\n * 如果是空值就回傳空物件\r\n * @param value1 \r\n * @param value2 \r\n * @returns \r\n */\r\nexport function parameterMerge(value1?: any, value2?: any) {\r\n const type1 = gettype(value1);\r\n const type2 = gettype(value2);\r\n\r\n switch (true) {\r\n case (type1 === \"undefined\" || type1 === \"null\") && !!value2:\r\n return value2;\r\n case (type2 === \"undefined\" || type2 === \"null\") && !!value1:\r\n return value1;\r\n case type1 === \"array\" && type1 === type2:\r\n return [...value1, ...value2];\r\n case type1 === \"object\" && type1 === type2:\r\n return Object.assign(recursiveDeepCopy(value1), value2);\r\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,QAAc,QAAc;AACvD,QAAM,QAAQ,QAAQ,MAAM;AAC5B,QAAM,QAAQ,QAAQ,MAAM;AAE5B,UAAQ,MAAM;AAAA,IACV,OAAM,UAAU,eAAe,UAAU,WAAW,CAAC,CAAC;AAClD,aAAO;AAAA,IACX,OAAM,UAAU,eAAe,UAAU,WAAW,CAAC,CAAC;AAClD,aAAO;AAAA,IACX,MAAK,UAAU,WAAW,UAAU;AAChC,aAAO,CAAC,GAAG,QAAQ,GAAG,MAAM;AAAA,IAChC,MAAK,UAAU,YAAY,UAAU;AACjC,aAAO,OAAO,OAAO,kBAAkB,MAAM,GAAG,MAAM;AAAA,IAC1D;AACI,aAAO,CAAC;AAAA,EAChB;AACJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/help/index.ts","../src/help/data_set/data_set.ts","../src/help/recursiveDeepCopy/recursiveDeepCopy.ts","../src/help/emptyData/emptyData.ts","../src/help/gettype/gettype.ts","../src/help/parameterMerge/parameterMerge.ts","../src/help/head/head.ts","../src/help/deepCloneWithJson/deepCloneWithJson.ts"],"sourcesContent":["export * as help from './help';","export * from './data_set/data_set';\r\nexport * from './recursiveDeepCopy/recursiveDeepCopy';\r\nexport * from './emptyData/emptyData';\r\nexport * from './gettype/gettype';\r\nexport * from './parameterMerge/parameterMerge';\r\nexport * from './head/head';\r\nexport * from './deepCloneWithJson/deepCloneWithJson';","/**\r\n * 動態設定多層物件的參數\r\n * @param data 被設定的物件\r\n * @param key 位置\r\n * @param value 參數\r\n * @returns \r\n */\r\nexport function data_set(data: any, key: string, value: any) {\r\n const keys = key.split(\".\");\r\n const firstKey = keys.shift();\r\n if (!firstKey) return;\r\n\r\n if (!(firstKey in data))\r\n data[firstKey] = {};\r\n\r\n if (keys.length < 1) {\r\n data[firstKey] = value;\r\n return\r\n }\r\n data_set(data[firstKey], keys.join(\".\"), value);\r\n}","/**\r\n* 透過遞迴複製物件\r\n* @param o \r\n* @returns \r\n*/\r\nexport function recursiveDeepCopy<T = any>(o: T): T {\r\n switch (Object.prototype.toString.apply(o)) {\r\n case \"[object Array]\":\r\n const tempArry: any = [];\r\n (o as Array<any>).forEach(value => {\r\n (tempArry as Array<any>).push(recursiveDeepCopy(value));\r\n })\r\n return tempArry;\r\n case \"[object Object]\":\r\n const tempO: any = {};\r\n Object.keys(o as Object).forEach(key => {\r\n if (Object.prototype.hasOwnProperty.call(o, key))\r\n tempO[key] = recursiveDeepCopy((o as { [_: string]: any })[key]);\r\n })\r\n return tempO;\r\n default:\r\n return o;\r\n }\r\n}","/**\r\n * 判斷資料是否為空值\r\n * @param data \r\n * @returns \r\n */\r\nexport function emptyData(data: any) {\r\n return typeof data === \"undefined\" || data === null\r\n}","/**\r\n * 回傳物體的型態\r\n * @param obj \r\n * @returns \r\n */\r\nexport function gettype<T = any>(obj: T) {\r\n switch (true) {\r\n case obj instanceof Array:\r\n return 'array';\r\n case obj instanceof Date:\r\n return 'date';\r\n case obj === null:\r\n return 'null';\r\n default:\r\n return typeof obj;\r\n }\r\n}","import { gettype, recursiveDeepCopy } from \"..\";\r\n\r\n/**\r\n * 兩個參數的合併(只能是物件或者陣列)\r\n * 如果是空值就回傳空物件\r\n * @param value1 \r\n * @param value2 \r\n * @returns \r\n */\r\nexport function parameterMerge(value1?: any, value2?: any) {\r\n const type1 = gettype(value1);\r\n const type2 = gettype(value2);\r\n\r\n switch (true) {\r\n case (type1 === \"undefined\" || type1 === \"null\") && !!value2:\r\n return value2;\r\n case (type2 === \"undefined\" || type2 === \"null\") && !!value1:\r\n return value1;\r\n case type1 === \"array\" && type1 === type2:\r\n return [...value1, ...value2];\r\n case type1 === \"object\" && type1 === type2:\r\n return Object.assign(recursiveDeepCopy(value1), value2);\r\n default:\r\n return {};\r\n }\r\n}","import { gettype } from \"..\";\r\n\r\n/**\r\n * 回傳物件的第一個值或者空值\r\n * @param arr\r\n * @returns\r\n */\r\nexport function head<T = any>(arr: Array<T>): T | null {\r\n if (gettype(arr) !== 'array') return null;\r\n return arr.length > 0 ? arr[0] : null;\r\n}\r\n\r\n\r\n","/**\r\n * 透過 JSON 複製物件\r\n * @param obj 要複製的物件\r\n * @returns\r\n */\r\nexport function deepCloneWithJson<T>(obj: T) {\r\n return JSON.parse(JSON.stringify(obj));\r\n }\r\n "],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,SAAS,SAAS,MAAW,KAAa,OAAY;AACzD,QAAM,OAAO,IAAI,MAAM,GAAG;AAC1B,QAAM,WAAW,KAAK,MAAM;AAC5B,MAAI,CAAC;AAAU;AAEf,MAAI,EAAE,YAAY;AACd,SAAK,QAAQ,IAAI,CAAC;AAEtB,MAAI,KAAK,SAAS,GAAG;AACjB,SAAK,QAAQ,IAAI;AACjB;AAAA,EACJ;AACA,WAAS,KAAK,QAAQ,GAAG,KAAK,KAAK,GAAG,GAAG,KAAK;AAClD;;;ACfO,SAAS,kBAA2B,GAAS;AAChD,UAAQ,OAAO,UAAU,SAAS,MAAM,CAAC,GAAG;AAAA,IACxC,KAAK;AACD,YAAM,WAAgB,CAAC;AACvB,MAAC,EAAiB,QAAQ,WAAS;AAC/B,QAAC,SAAwB,KAAK,kBAAkB,KAAK,CAAC;AAAA,MAC1D,CAAC;AACD,aAAO;AAAA,IACX,KAAK;AACD,YAAM,QAAa,CAAC;AACpB,aAAO,KAAK,CAAW,EAAE,QAAQ,SAAO;AACpC,YAAI,OAAO,UAAU,eAAe,KAAK,GAAG,GAAG;AAC3C,gBAAM,GAAG,IAAI,kBAAmB,EAA2B,GAAG,CAAC;AAAA,MACvE,CAAC;AACD,aAAO;AAAA,IACX;AACI,aAAO;AAAA,EACf;AACJ;;;AClBO,SAAS,UAAU,MAAW;AACjC,SAAO,OAAO,SAAS,eAAe,SAAS;AACnD;;;ACFO,SAAS,QAAiB,KAAQ;AACrC,UAAQ,MAAM;AAAA,IACV,KAAK,eAAe;AAChB,aAAO;AAAA,IACX,KAAK,eAAe;AAChB,aAAO;AAAA,IACX,KAAK,QAAQ;AACT,aAAO;AAAA,IACX;AACI,aAAO,OAAO;AAAA,EACtB;AACJ;;;ACPO,SAAS,eAAe,QAAc,QAAc;AACvD,QAAM,QAAQ,QAAQ,MAAM;AAC5B,QAAM,QAAQ,QAAQ,MAAM;AAE5B,UAAQ,MAAM;AAAA,IACV,OAAM,UAAU,eAAe,UAAU,WAAW,CAAC,CAAC;AAClD,aAAO;AAAA,IACX,OAAM,UAAU,eAAe,UAAU,WAAW,CAAC,CAAC;AAClD,aAAO;AAAA,IACX,MAAK,UAAU,WAAW,UAAU;AAChC,aAAO,CAAC,GAAG,QAAQ,GAAG,MAAM;AAAA,IAChC,MAAK,UAAU,YAAY,UAAU;AACjC,aAAO,OAAO,OAAO,kBAAkB,MAAM,GAAG,MAAM;AAAA,IAC1D;AACI,aAAO,CAAC;AAAA,EAChB;AACJ;;;AClBO,SAAS,KAAc,KAAyB;AACnD,MAAI,QAAQ,GAAG,MAAM;AAAS,WAAO;AACrC,SAAO,IAAI,SAAS,IAAI,IAAI,CAAC,IAAI;AACrC;;;ACLO,SAAS,kBAAqB,KAAQ;AACzC,SAAO,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AACvC;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -8,8 +8,10 @@ var __export = (target, all) => {
|
|
|
8
8
|
var help_exports = {};
|
|
9
9
|
__export(help_exports, {
|
|
10
10
|
data_set: () => data_set,
|
|
11
|
+
deepCloneWithJson: () => deepCloneWithJson,
|
|
11
12
|
emptyData: () => emptyData,
|
|
12
13
|
gettype: () => gettype,
|
|
14
|
+
head: () => head,
|
|
13
15
|
parameterMerge: () => parameterMerge,
|
|
14
16
|
recursiveDeepCopy: () => recursiveDeepCopy
|
|
15
17
|
});
|
|
@@ -86,6 +88,18 @@ function parameterMerge(value1, value2) {
|
|
|
86
88
|
return {};
|
|
87
89
|
}
|
|
88
90
|
}
|
|
91
|
+
|
|
92
|
+
// src/help/head/head.ts
|
|
93
|
+
function head(arr) {
|
|
94
|
+
if (gettype(arr) !== "array")
|
|
95
|
+
return null;
|
|
96
|
+
return arr.length > 0 ? arr[0] : null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/help/deepCloneWithJson/deepCloneWithJson.ts
|
|
100
|
+
function deepCloneWithJson(obj) {
|
|
101
|
+
return JSON.parse(JSON.stringify(obj));
|
|
102
|
+
}
|
|
89
103
|
export {
|
|
90
104
|
help_exports as help
|
|
91
105
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/help/index.ts","../src/help/data_set/data_set.ts","../src/help/recursiveDeepCopy/recursiveDeepCopy.ts","../src/help/emptyData/emptyData.ts","../src/help/gettype/gettype.ts","../src/help/parameterMerge/parameterMerge.ts"],"sourcesContent":["export * from './data_set/data_set';\r\nexport * from './recursiveDeepCopy/recursiveDeepCopy';\r\nexport * from './emptyData/emptyData';\r\nexport * from './gettype/gettype';\r\nexport * from './parameterMerge/parameterMerge';","/**\r\n * 動態設定多層物件的參數\r\n * @param data 被設定的物件\r\n * @param key 位置\r\n * @param value 參數\r\n * @returns \r\n */\r\nexport function data_set(data: any, key: string, value: any) {\r\n const keys = key.split(\".\");\r\n const firstKey = keys.shift();\r\n if (!firstKey) return;\r\n\r\n if (!(firstKey in data))\r\n data[firstKey] = {};\r\n\r\n if (keys.length < 1) {\r\n data[firstKey] = value;\r\n return\r\n }\r\n data_set(data[firstKey], keys.join(\".\"), value);\r\n}","/**\r\n* 透過遞迴複製物件\r\n* @param o \r\n* @returns \r\n*/\r\nexport function recursiveDeepCopy<T = any>(o: T): T {\r\n switch (Object.prototype.toString.apply(o)) {\r\n case \"[object Array]\":\r\n const tempArry: any = [];\r\n (o as Array<any>).forEach(value => {\r\n (tempArry as Array<any>).push(recursiveDeepCopy(value));\r\n })\r\n return tempArry;\r\n case \"[object Object]\":\r\n const tempO: any = {};\r\n Object.keys(o as Object).forEach(key => {\r\n if (Object.prototype.hasOwnProperty.call(o, key))\r\n tempO[key] = recursiveDeepCopy((o as { [_: string]: any })[key]);\r\n })\r\n return tempO;\r\n default:\r\n return o;\r\n }\r\n}","/**\r\n * 判斷資料是否為空值\r\n * @param data \r\n * @returns \r\n */\r\nexport function emptyData(data: any) {\r\n return typeof data === \"undefined\" || data === null\r\n}","/**\r\n * 回傳物體的型態\r\n * @param obj \r\n * @returns \r\n */\r\nexport function gettype<T = any>(obj: T) {\r\n switch (true) {\r\n case obj instanceof Array:\r\n return 'array';\r\n case obj instanceof Date:\r\n return 'date';\r\n case obj === null:\r\n return 'null';\r\n default:\r\n return typeof obj;\r\n }\r\n}","import { gettype, recursiveDeepCopy } from \"..\";\r\n\r\n/**\r\n * 兩個參數的合併(只能是物件或者陣列)\r\n * 如果是空值就回傳空物件\r\n * @param value1 \r\n * @param value2 \r\n * @returns \r\n */\r\nexport function parameterMerge(value1?: any, value2?: any) {\r\n const type1 = gettype(value1);\r\n const type2 = gettype(value2);\r\n\r\n switch (true) {\r\n case (type1 === \"undefined\" || type1 === \"null\") && !!value2:\r\n return value2;\r\n case (type2 === \"undefined\" || type2 === \"null\") && !!value1:\r\n return value1;\r\n case type1 === \"array\" && type1 === type2:\r\n return [...value1, ...value2];\r\n case type1 === \"object\" && type1 === type2:\r\n return Object.assign(recursiveDeepCopy(value1), value2);\r\n default:\r\n return {};\r\n }\r\n}"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,SAAS,SAAS,MAAW,KAAa,OAAY;AACzD,QAAM,OAAO,IAAI,MAAM,GAAG;AAC1B,QAAM,WAAW,KAAK,MAAM;AAC5B,MAAI,CAAC;AAAU;AAEf,MAAI,EAAE,YAAY;AACd,SAAK,QAAQ,IAAI,CAAC;AAEtB,MAAI,KAAK,SAAS,GAAG;AACjB,SAAK,QAAQ,IAAI;AACj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GAAG,MAAM;AAAA,IAC1D;AACI,aAAO,CAAC;AAAA,EAChB;AACJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/help/index.ts","../src/help/data_set/data_set.ts","../src/help/recursiveDeepCopy/recursiveDeepCopy.ts","../src/help/emptyData/emptyData.ts","../src/help/gettype/gettype.ts","../src/help/parameterMerge/parameterMerge.ts","../src/help/head/head.ts","../src/help/deepCloneWithJson/deepCloneWithJson.ts"],"sourcesContent":["export * from './data_set/data_set';\r\nexport * from './recursiveDeepCopy/recursiveDeepCopy';\r\nexport * from './emptyData/emptyData';\r\nexport * from './gettype/gettype';\r\nexport * from './parameterMerge/parameterMerge';\r\nexport * from './head/head';\r\nexport * from './deepCloneWithJson/deepCloneWithJson';","/**\r\n * 動態設定多層物件的參數\r\n * @param data 被設定的物件\r\n * @param key 位置\r\n * @param value 參數\r\n * @returns \r\n */\r\nexport function data_set(data: any, key: string, value: any) {\r\n const keys = key.split(\".\");\r\n const firstKey = keys.shift();\r\n if (!firstKey) return;\r\n\r\n if (!(firstKey in data))\r\n data[firstKey] = {};\r\n\r\n if (keys.length < 1) {\r\n data[firstKey] = value;\r\n return\r\n }\r\n data_set(data[firstKey], keys.join(\".\"), value);\r\n}","/**\r\n* 透過遞迴複製物件\r\n* @param o \r\n* @returns \r\n*/\r\nexport function recursiveDeepCopy<T = any>(o: T): T {\r\n switch (Object.prototype.toString.apply(o)) {\r\n case \"[object Array]\":\r\n const tempArry: any = [];\r\n (o as Array<any>).forEach(value => {\r\n (tempArry as Array<any>).push(recursiveDeepCopy(value));\r\n })\r\n return tempArry;\r\n case \"[object Object]\":\r\n const tempO: any = {};\r\n Object.keys(o as Object).forEach(key => {\r\n if (Object.prototype.hasOwnProperty.call(o, key))\r\n tempO[key] = recursiveDeepCopy((o as { [_: string]: any })[key]);\r\n })\r\n return tempO;\r\n default:\r\n return o;\r\n }\r\n}","/**\r\n * 判斷資料是否為空值\r\n * @param data \r\n * @returns \r\n */\r\nexport function emptyData(data: any) {\r\n return typeof data === \"undefined\" || data === null\r\n}","/**\r\n * 回傳物體的型態\r\n * @param obj \r\n * @returns \r\n */\r\nexport function gettype<T = any>(obj: T) {\r\n switch (true) {\r\n case obj instanceof Array:\r\n return 'array';\r\n case obj instanceof Date:\r\n return 'date';\r\n case obj === null:\r\n return 'null';\r\n default:\r\n return typeof obj;\r\n }\r\n}","import { gettype, recursiveDeepCopy } from \"..\";\r\n\r\n/**\r\n * 兩個參數的合併(只能是物件或者陣列)\r\n * 如果是空值就回傳空物件\r\n * @param value1 \r\n * @param value2 \r\n * @returns \r\n */\r\nexport function parameterMerge(value1?: any, value2?: any) {\r\n const type1 = gettype(value1);\r\n const type2 = gettype(value2);\r\n\r\n switch (true) {\r\n case (type1 === \"undefined\" || type1 === \"null\") && !!value2:\r\n return value2;\r\n case (type2 === \"undefined\" || type2 === \"null\") && !!value1:\r\n return value1;\r\n case type1 === \"array\" && type1 === type2:\r\n return [...value1, ...value2];\r\n case type1 === \"object\" && type1 === type2:\r\n return Object.assign(recursiveDeepCopy(value1), value2);\r\n default:\r\n return {};\r\n }\r\n}","import { gettype } from \"..\";\r\n\r\n/**\r\n * 回傳物件的第一個值或者空值\r\n * @param arr\r\n * @returns\r\n */\r\nexport function head<T = any>(arr: Array<T>): T | null {\r\n if (gettype(arr) !== 'array') return null;\r\n return arr.length > 0 ? arr[0] : null;\r\n}\r\n\r\n\r\n","/**\r\n * 透過 JSON 複製物件\r\n * @param obj 要複製的物件\r\n * @returns\r\n */\r\nexport function deepCloneWithJson<T>(obj: T) {\r\n return JSON.parse(JSON.stringify(obj));\r\n }\r\n "],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,SAAS,SAAS,MAAW,KAAa,OAAY;AACzD,QAAM,OAAO,IAAI,MAAM,GAAG;AAC1B,QAAM,WAAW,KAAK,MAAM;AAC5B,MAAI,CAAC;AAAU;AAEf,MAAI,EAAE,YAAY;A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,GAAG,MAAM;AAAA,IAChC,MAAK,UAAU,YAAY,UAAU;AACjC,aAAO,OAAO,OAAO,kBAAkB,MAAM,GAAG,MAAM;AAAA,IAC1D;AACI,aAAO,CAAC;AAAA,EAChB;AACJ;;;AClBO,SAAS,KAAc,KAAyB;AACnD,MAAI,QAAQ,GAAG,MAAM;AAAS,WAAO;AACrC,SAAO,IAAI,SAAS,IAAI,IAAI,CAAC,IAAI;AACrC;;;ACLO,SAAS,kBAAqB,KAAQ;AACzC,SAAO,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AACvC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aimidy/util",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "https://github.com/aimidy/util
|
|
18
|
+
"url": "https://github.com/aimidy/util"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
21
|
"demo",
|