@aimidy/util 1.0.5 → 1.0.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.
@@ -0,0 +1,124 @@
1
+ /**
2
+ * 動態設定多層物件的參數
3
+ * @param data 被設定的物件
4
+ * @param key 位置
5
+ * @param value 參數
6
+ * @returns
7
+ */
8
+ declare function data_set(data: any, key: string, value: any): void;
9
+
10
+ /**
11
+ * 獲取資料
12
+ * @param data 資料集{key:value}
13
+ * @param key 資料對應的位置 app.column.name
14
+ * @param defaultValue 如果取不到值要給予什麼參數,預設 null
15
+ * @returns
16
+ *
17
+ * {a:[{b:a},{b:a}]}
18
+ * a.b = [a,a]
19
+ */
20
+ declare function data_get(data: any, key: string, defaultValue?: any): any;
21
+
22
+ /**
23
+ * 透過遞迴複製物件
24
+ * @param o
25
+ * @returns
26
+ */
27
+ declare function recursiveDeepCopy<T = any>(o: T): T;
28
+
29
+ /**
30
+ * 判斷資料是否為空值
31
+ * @param data
32
+ * @returns
33
+ */
34
+ declare function emptyData(data: any): boolean;
35
+
36
+ /**
37
+ * 回傳物體的型態
38
+ * @param obj
39
+ * @returns
40
+ */
41
+ declare function gettype<T = any>(obj: T): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "array" | "date" | "null";
42
+
43
+ /**
44
+ * 兩個參數的合併(只能是物件或者陣列)
45
+ * 如果是空值就回傳空物件
46
+ * @param value1
47
+ * @param value2
48
+ * @returns
49
+ */
50
+ declare function parameterMerge(value1?: any, value2?: any): any;
51
+
52
+ /**
53
+ * 回傳物件的第一個值或者空值
54
+ * @param arr
55
+ * @returns
56
+ */
57
+ declare function head<T = any>(arr: Array<T>): T | null;
58
+
59
+ /**
60
+ * 透過 JSON 複製物件
61
+ * @param obj 要複製的物件
62
+ * @returns
63
+ */
64
+ declare function deepCloneWithJson<T>(obj: T): any;
65
+
66
+ type TremoveValeu = string | number;
67
+ /**
68
+ * 移除陣列某一個位置的值
69
+ * @param arr 陣列
70
+ * @param item 要移除的值
71
+ * @returns
72
+ */
73
+ declare function remove(arr: TremoveValeu[], item: TremoveValeu): TremoveValeu[];
74
+
75
+ /**
76
+ * 尋找字串內是否有符合的值,並移除後回傳結果
77
+ * @param str 字串
78
+ * @param key 要搜尋的文字
79
+ * @returns [boolean,string]
80
+ */
81
+ declare function searchInStr(str: string, key: string): [boolean, string];
82
+
83
+ /**
84
+ * 駝峰轉小寫+convert(default:底線)
85
+ * @param str
86
+ * @returns
87
+ */
88
+ declare function strToConvert(str: string, convert?: string): string;
89
+
90
+ /**
91
+ * 底線轉駝峰
92
+ * @param str
93
+ * @returns
94
+ */
95
+ declare function strToHump(str: string): string;
96
+
97
+ /**
98
+ * 物件深度合併
99
+ * @param target
100
+ * @param sources
101
+ * @returns
102
+ */
103
+ declare function deepAssign(...param: {
104
+ [_: string]: any;
105
+ }[]): any;
106
+
107
+ declare const index_data_get: typeof data_get;
108
+ declare const index_data_set: typeof data_set;
109
+ declare const index_deepAssign: typeof deepAssign;
110
+ declare const index_deepCloneWithJson: typeof deepCloneWithJson;
111
+ declare const index_emptyData: typeof emptyData;
112
+ declare const index_gettype: typeof gettype;
113
+ declare const index_head: typeof head;
114
+ declare const index_parameterMerge: typeof parameterMerge;
115
+ declare const index_recursiveDeepCopy: typeof recursiveDeepCopy;
116
+ declare const index_remove: typeof remove;
117
+ declare const index_searchInStr: typeof searchInStr;
118
+ declare const index_strToConvert: typeof strToConvert;
119
+ declare const index_strToHump: typeof strToHump;
120
+ declare namespace index {
121
+ export { index_data_get as data_get, index_data_set as data_set, index_deepAssign as deepAssign, index_deepCloneWithJson as deepCloneWithJson, index_emptyData as emptyData, index_gettype as gettype, index_head as head, index_parameterMerge as parameterMerge, index_recursiveDeepCopy as recursiveDeepCopy, index_remove as remove, index_searchInStr as searchInStr, index_strToConvert as strToConvert, index_strToHump as strToHump };
122
+ }
123
+
124
+ export { data_get, data_set, deepAssign, deepCloneWithJson, emptyData, gettype, head, index as i, parameterMerge, recursiveDeepCopy, remove, searchInStr, strToConvert, strToHump };
@@ -0,0 +1,124 @@
1
+ /**
2
+ * 動態設定多層物件的參數
3
+ * @param data 被設定的物件
4
+ * @param key 位置
5
+ * @param value 參數
6
+ * @returns
7
+ */
8
+ declare function data_set(data: any, key: string, value: any): void;
9
+
10
+ /**
11
+ * 獲取資料
12
+ * @param data 資料集{key:value}
13
+ * @param key 資料對應的位置 app.column.name
14
+ * @param defaultValue 如果取不到值要給予什麼參數,預設 null
15
+ * @returns
16
+ *
17
+ * {a:[{b:a},{b:a}]}
18
+ * a.b = [a,a]
19
+ */
20
+ declare function data_get(data: any, key: string, defaultValue?: any): any;
21
+
22
+ /**
23
+ * 透過遞迴複製物件
24
+ * @param o
25
+ * @returns
26
+ */
27
+ declare function recursiveDeepCopy<T = any>(o: T): T;
28
+
29
+ /**
30
+ * 判斷資料是否為空值
31
+ * @param data
32
+ * @returns
33
+ */
34
+ declare function emptyData(data: any): boolean;
35
+
36
+ /**
37
+ * 回傳物體的型態
38
+ * @param obj
39
+ * @returns
40
+ */
41
+ declare function gettype<T = any>(obj: T): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "array" | "date" | "null";
42
+
43
+ /**
44
+ * 兩個參數的合併(只能是物件或者陣列)
45
+ * 如果是空值就回傳空物件
46
+ * @param value1
47
+ * @param value2
48
+ * @returns
49
+ */
50
+ declare function parameterMerge(value1?: any, value2?: any): any;
51
+
52
+ /**
53
+ * 回傳物件的第一個值或者空值
54
+ * @param arr
55
+ * @returns
56
+ */
57
+ declare function head<T = any>(arr: Array<T>): T | null;
58
+
59
+ /**
60
+ * 透過 JSON 複製物件
61
+ * @param obj 要複製的物件
62
+ * @returns
63
+ */
64
+ declare function deepCloneWithJson<T>(obj: T): any;
65
+
66
+ type TremoveValeu = string | number;
67
+ /**
68
+ * 移除陣列某一個位置的值
69
+ * @param arr 陣列
70
+ * @param item 要移除的值
71
+ * @returns
72
+ */
73
+ declare function remove(arr: TremoveValeu[], item: TremoveValeu): TremoveValeu[];
74
+
75
+ /**
76
+ * 尋找字串內是否有符合的值,並移除後回傳結果
77
+ * @param str 字串
78
+ * @param key 要搜尋的文字
79
+ * @returns [boolean,string]
80
+ */
81
+ declare function searchInStr(str: string, key: string): [boolean, string];
82
+
83
+ /**
84
+ * 駝峰轉小寫+convert(default:底線)
85
+ * @param str
86
+ * @returns
87
+ */
88
+ declare function strToConvert(str: string, convert?: string): string;
89
+
90
+ /**
91
+ * 底線轉駝峰
92
+ * @param str
93
+ * @returns
94
+ */
95
+ declare function strToHump(str: string): string;
96
+
97
+ /**
98
+ * 物件深度合併
99
+ * @param target
100
+ * @param sources
101
+ * @returns
102
+ */
103
+ declare function deepAssign(...param: {
104
+ [_: string]: any;
105
+ }[]): any;
106
+
107
+ declare const index_data_get: typeof data_get;
108
+ declare const index_data_set: typeof data_set;
109
+ declare const index_deepAssign: typeof deepAssign;
110
+ declare const index_deepCloneWithJson: typeof deepCloneWithJson;
111
+ declare const index_emptyData: typeof emptyData;
112
+ declare const index_gettype: typeof gettype;
113
+ declare const index_head: typeof head;
114
+ declare const index_parameterMerge: typeof parameterMerge;
115
+ declare const index_recursiveDeepCopy: typeof recursiveDeepCopy;
116
+ declare const index_remove: typeof remove;
117
+ declare const index_searchInStr: typeof searchInStr;
118
+ declare const index_strToConvert: typeof strToConvert;
119
+ declare const index_strToHump: typeof strToHump;
120
+ declare namespace index {
121
+ export { index_data_get as data_get, index_data_set as data_set, index_deepAssign as deepAssign, index_deepCloneWithJson as deepCloneWithJson, index_emptyData as emptyData, index_gettype as gettype, index_head as head, index_parameterMerge as parameterMerge, index_recursiveDeepCopy as recursiveDeepCopy, index_remove as remove, index_searchInStr as searchInStr, index_strToConvert as strToConvert, index_strToHump as strToHump };
122
+ }
123
+
124
+ export { data_get, data_set, deepAssign, deepCloneWithJson, emptyData, gettype, head, index as i, parameterMerge, recursiveDeepCopy, remove, searchInStr, strToConvert, strToHump };
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/help/index.ts
21
+ var help_exports = {};
22
+ __export(help_exports, {
23
+ data_get: () => data_get,
24
+ data_set: () => data_set,
25
+ deepAssign: () => deepAssign,
26
+ deepCloneWithJson: () => deepCloneWithJson,
27
+ emptyData: () => emptyData,
28
+ gettype: () => gettype,
29
+ head: () => head,
30
+ parameterMerge: () => parameterMerge,
31
+ recursiveDeepCopy: () => recursiveDeepCopy,
32
+ remove: () => remove,
33
+ searchInStr: () => searchInStr,
34
+ strToConvert: () => strToConvert,
35
+ strToHump: () => strToHump
36
+ });
37
+ module.exports = __toCommonJS(help_exports);
38
+
39
+ // src/help/data_set/data_set.ts
40
+ function data_set(data, key, value) {
41
+ const keys = key.split(".");
42
+ const firstKey = keys.shift();
43
+ if (!firstKey)
44
+ return;
45
+ if (!(firstKey in data))
46
+ data[firstKey] = {};
47
+ if (keys.length < 1) {
48
+ data[firstKey] = value;
49
+ return;
50
+ }
51
+ data_set(data[firstKey], keys.join("."), value);
52
+ }
53
+
54
+ // src/help/data_get/data_get.ts
55
+ function data_get(data, key, defaultValue = null) {
56
+ switch (gettype(data)) {
57
+ case "object":
58
+ const coypData = deepCloneWithJson(data);
59
+ const keys = key.split(".");
60
+ let firstKey = keys.shift();
61
+ if (!firstKey)
62
+ return defaultValue;
63
+ if (!(firstKey in coypData))
64
+ return defaultValue;
65
+ let rep = coypData[firstKey];
66
+ if (keys.length > 0)
67
+ rep = data_get(rep, keys.join("."), defaultValue);
68
+ return rep != null ? rep : defaultValue;
69
+ case "undefined":
70
+ case "null":
71
+ return defaultValue;
72
+ case "array":
73
+ return data.map((value) => data_get(value, key, defaultValue));
74
+ default:
75
+ return data;
76
+ }
77
+ }
78
+
79
+ // src/help/recursiveDeepCopy/recursiveDeepCopy.ts
80
+ function recursiveDeepCopy(o) {
81
+ switch (Object.prototype.toString.apply(o)) {
82
+ case "[object Array]":
83
+ const tempArry = [];
84
+ o.forEach((value) => {
85
+ tempArry.push(recursiveDeepCopy(value));
86
+ });
87
+ return tempArry;
88
+ case "[object Object]":
89
+ const tempO = {};
90
+ Object.keys(o).forEach((key) => {
91
+ if (Object.prototype.hasOwnProperty.call(o, key))
92
+ tempO[key] = recursiveDeepCopy(o[key]);
93
+ });
94
+ return tempO;
95
+ default:
96
+ return o;
97
+ }
98
+ }
99
+
100
+ // src/help/emptyData/emptyData.ts
101
+ function emptyData(data) {
102
+ return typeof data === "undefined" || data === null;
103
+ }
104
+
105
+ // src/help/gettype/gettype.ts
106
+ function gettype(obj) {
107
+ switch (true) {
108
+ case obj instanceof Array:
109
+ return "array";
110
+ case obj instanceof Date:
111
+ return "date";
112
+ case obj === null:
113
+ return "null";
114
+ default:
115
+ return typeof obj;
116
+ }
117
+ }
118
+
119
+ // src/help/parameterMerge/parameterMerge.ts
120
+ function parameterMerge(value1, value2) {
121
+ const type1 = gettype(value1);
122
+ const type2 = gettype(value2);
123
+ switch (true) {
124
+ case ((type1 === "undefined" || type1 === "null") && !!value2):
125
+ return value2;
126
+ case ((type2 === "undefined" || type2 === "null") && !!value1):
127
+ return value1;
128
+ case (type1 === "array" && type1 === type2):
129
+ return [...value1, ...value2];
130
+ case (type1 === "object" && type1 === type2):
131
+ return Object.assign(recursiveDeepCopy(value1), value2);
132
+ default:
133
+ return {};
134
+ }
135
+ }
136
+
137
+ // src/help/head/head.ts
138
+ function head(arr) {
139
+ if (gettype(arr) !== "array")
140
+ return null;
141
+ return arr.length > 0 ? arr[0] : null;
142
+ }
143
+
144
+ // src/help/deepCloneWithJson/deepCloneWithJson.ts
145
+ function deepCloneWithJson(obj) {
146
+ return JSON.parse(JSON.stringify(obj));
147
+ }
148
+
149
+ // src/help/remove/remove.ts
150
+ function remove(arr, item) {
151
+ if (arr.length === 0)
152
+ return [];
153
+ const index = arr.indexOf(item);
154
+ if (index === -1)
155
+ return arr;
156
+ return [...arr.slice(0, index), ...arr.slice(index + 1)];
157
+ }
158
+
159
+ // src/help/searchInStr/searchInStr.ts
160
+ function searchInStr(str, key) {
161
+ return str.indexOf(key) === -1 ? [false, str] : [true, str.replace(key, "")];
162
+ }
163
+
164
+ // src/help/strToConvert/strToConvert.ts
165
+ function strToConvert(str, convert = "_") {
166
+ return str.replace(/\B([A-Z])/g, `${convert}$1`).toLowerCase();
167
+ }
168
+
169
+ // src/help/strToHump/strToHump.ts
170
+ function strToHump(str) {
171
+ if (str.startsWith("_"))
172
+ str = str.slice(1);
173
+ return str.replace(/([^_])(?:_+([^_]))/g, function($0, $1, $2) {
174
+ return $1 + $2.toUpperCase();
175
+ });
176
+ }
177
+
178
+ // src/help/deepAssign/deepAssign.ts
179
+ function deepAssign(...param) {
180
+ let result = Object.assign({}, ...param);
181
+ for (let item of param) {
182
+ for (const [idx, val] of Object.entries(item)) {
183
+ if (gettype(val) === "object") {
184
+ result[idx] = deepAssign(result[idx], val);
185
+ }
186
+ }
187
+ }
188
+ return result;
189
+ }
190
+ // Annotate the CommonJS export names for ESM import in node:
191
+ 0 && (module.exports = {
192
+ data_get,
193
+ data_set,
194
+ deepAssign,
195
+ deepCloneWithJson,
196
+ emptyData,
197
+ gettype,
198
+ head,
199
+ parameterMerge,
200
+ recursiveDeepCopy,
201
+ remove,
202
+ searchInStr,
203
+ strToConvert,
204
+ strToHump
205
+ });
206
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/help/index.ts","../../src/help/data_set/data_set.ts","../../src/help/data_get/data_get.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","../../src/help/remove/remove.ts","../../src/help/searchInStr/searchInStr.ts","../../src/help/strToConvert/strToConvert.ts","../../src/help/strToHump/strToHump.ts","../../src/help/deepAssign/deepAssign.ts"],"sourcesContent":["export * from './data_set/data_set';\r\nexport * from './data_get/data_get';\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\nexport * from './remove/remove';\r\nexport * from './searchInStr/searchInStr';\r\nexport * from './strToConvert/strToConvert';\r\nexport * from './strToHump/strToHump';\r\nexport * from './deepAssign/deepAssign';","/**\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}","import { deepCloneWithJson, gettype } from \"..\";\r\n\r\n/**\r\n * 獲取資料\r\n * @param data 資料集{key:value}\r\n * @param key 資料對應的位置 app.column.name\r\n * @param defaultValue 如果取不到值要給予什麼參數,預設 null\r\n * @returns\r\n *\r\n * {a:[{b:a},{b:a}]}\r\n * a.b = [a,a]\r\n */\r\nexport function data_get(data: any, key: string, defaultValue: any = null,): any {\r\n switch (gettype(data)) {\r\n case \"object\":\r\n const coypData = deepCloneWithJson(data);\r\n const keys = key.split('.');\r\n let firstKey = keys.shift();\r\n if (!firstKey) return defaultValue;\r\n if (!(firstKey in coypData)) return defaultValue;\r\n\r\n let rep = coypData[firstKey];\r\n if (keys.length > 0)\r\n rep = data_get(rep, keys.join('.'), defaultValue);\r\n\r\n return rep ?? defaultValue;\r\n case 'undefined':\r\n case 'null':\r\n return defaultValue;\r\n case 'array':\r\n return (data as any[]).map((value: any) => data_get(value, key, defaultValue)) as any;\r\n default:\r\n return data;\r\n }\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 ","type TremoveValeu = string | number\r\n\r\n/**\r\n * 移除陣列某一個位置的值\r\n * @param arr 陣列\r\n * @param item 要移除的值\r\n * @returns\r\n */\r\nexport function remove(arr: TremoveValeu[], item: TremoveValeu) {\r\n if (arr.length === 0) return [];\r\n\r\n const index = arr.indexOf(item);\r\n if (index === -1) return arr;\r\n\r\n return [...arr.slice(0, index), ...arr.slice(index + 1)];\r\n}","/**\r\n * 尋找字串內是否有符合的值,並移除後回傳結果\r\n * @param str 字串\r\n * @param key 要搜尋的文字\r\n * @returns [boolean,string]\r\n */\r\nexport function searchInStr(str: string, key: string): [boolean, string] {\r\n return str.indexOf(key) === -1 ? [false, str] : [true, str.replace(key, '')];\r\n}","/**\r\n * 駝峰轉小寫+convert(default:底線)\r\n * @param str\r\n * @returns\r\n */\r\nexport function strToConvert(str: string, convert: string = \"_\") {\r\n return str.replace(/\\B([A-Z])/g, `${convert}$1`).toLowerCase();\r\n}","/**\r\n * 底線轉駝峰\r\n * @param str\r\n * @returns\r\n */\r\nexport function strToHump(str: string) {\r\n if (str.startsWith('_')) str = str.slice(1);\r\n\r\n return str.replace(/([^_])(?:_+([^_]))/g, function ($0, $1, $2) {\r\n return $1 + $2.toUpperCase();\r\n });\r\n}","import { gettype } from \"../gettype/gettype\";\r\n\r\n/**\r\n * 物件深度合併\r\n * @param target\r\n * @param sources\r\n * @returns\r\n */\r\nexport function deepAssign(...param: { [_: string]: any }[]) {\r\n let result = Object.assign({}, ...param);\r\n\r\n for (let item of param) {\r\n for (const [idx, val] of Object.entries<any>(item)) {\r\n if (gettype(val) === \"object\") {\r\n result[idx] = deepAssign(result[idx], val);\r\n }\r\n }\r\n }\r\n return result;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;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;;;ACRO,SAAS,SAAS,MAAW,KAAa,eAAoB,MAAY;AAC7E,UAAQ,QAAQ,IAAI,GAAG;AAAA,IACnB,KAAK;AACD,YAAM,WAAW,kBAAkB,IAAI;AACvC,YAAM,OAAO,IAAI,MAAM,GAAG;AAC1B,UAAI,WAAW,KAAK,MAAM;AAC1B,UAAI,CAAC;AAAU,eAAO;AACtB,UAAI,EAAE,YAAY;AAAW,eAAO;AAEpC,UAAI,MAAM,SAAS,QAAQ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GAAG,GAAG,KAAK;AAEvC,WAAS,QAAQ,OAAO;AACpB,eAAW,CAAC,KAAK,GAAG,KAAK,OAAO,QAAa,IAAI,GAAG;AAChD,UAAI,QAAQ,GAAG,MAAM,UAAU;AAC3B,eAAO,GAAG,IAAI,WAAW,OAAO,GAAG,GAAG,GAAG;AAAA,MAC7C;AAAA,IACJ;AAAA,EACJ;AACA,SAAO;AACX;","names":[]}
@@ -0,0 +1,167 @@
1
+ // src/help/data_set/data_set.ts
2
+ function data_set(data, key, value) {
3
+ const keys = key.split(".");
4
+ const firstKey = keys.shift();
5
+ if (!firstKey)
6
+ return;
7
+ if (!(firstKey in data))
8
+ data[firstKey] = {};
9
+ if (keys.length < 1) {
10
+ data[firstKey] = value;
11
+ return;
12
+ }
13
+ data_set(data[firstKey], keys.join("."), value);
14
+ }
15
+
16
+ // src/help/data_get/data_get.ts
17
+ function data_get(data, key, defaultValue = null) {
18
+ switch (gettype(data)) {
19
+ case "object":
20
+ const coypData = deepCloneWithJson(data);
21
+ const keys = key.split(".");
22
+ let firstKey = keys.shift();
23
+ if (!firstKey)
24
+ return defaultValue;
25
+ if (!(firstKey in coypData))
26
+ return defaultValue;
27
+ let rep = coypData[firstKey];
28
+ if (keys.length > 0)
29
+ rep = data_get(rep, keys.join("."), defaultValue);
30
+ return rep != null ? rep : defaultValue;
31
+ case "undefined":
32
+ case "null":
33
+ return defaultValue;
34
+ case "array":
35
+ return data.map((value) => data_get(value, key, defaultValue));
36
+ default:
37
+ return data;
38
+ }
39
+ }
40
+
41
+ // src/help/recursiveDeepCopy/recursiveDeepCopy.ts
42
+ function recursiveDeepCopy(o) {
43
+ switch (Object.prototype.toString.apply(o)) {
44
+ case "[object Array]":
45
+ const tempArry = [];
46
+ o.forEach((value) => {
47
+ tempArry.push(recursiveDeepCopy(value));
48
+ });
49
+ return tempArry;
50
+ case "[object Object]":
51
+ const tempO = {};
52
+ Object.keys(o).forEach((key) => {
53
+ if (Object.prototype.hasOwnProperty.call(o, key))
54
+ tempO[key] = recursiveDeepCopy(o[key]);
55
+ });
56
+ return tempO;
57
+ default:
58
+ return o;
59
+ }
60
+ }
61
+
62
+ // src/help/emptyData/emptyData.ts
63
+ function emptyData(data) {
64
+ return typeof data === "undefined" || data === null;
65
+ }
66
+
67
+ // src/help/gettype/gettype.ts
68
+ function gettype(obj) {
69
+ switch (true) {
70
+ case obj instanceof Array:
71
+ return "array";
72
+ case obj instanceof Date:
73
+ return "date";
74
+ case obj === null:
75
+ return "null";
76
+ default:
77
+ return typeof obj;
78
+ }
79
+ }
80
+
81
+ // src/help/parameterMerge/parameterMerge.ts
82
+ function parameterMerge(value1, value2) {
83
+ const type1 = gettype(value1);
84
+ const type2 = gettype(value2);
85
+ switch (true) {
86
+ case ((type1 === "undefined" || type1 === "null") && !!value2):
87
+ return value2;
88
+ case ((type2 === "undefined" || type2 === "null") && !!value1):
89
+ return value1;
90
+ case (type1 === "array" && type1 === type2):
91
+ return [...value1, ...value2];
92
+ case (type1 === "object" && type1 === type2):
93
+ return Object.assign(recursiveDeepCopy(value1), value2);
94
+ default:
95
+ return {};
96
+ }
97
+ }
98
+
99
+ // src/help/head/head.ts
100
+ function head(arr) {
101
+ if (gettype(arr) !== "array")
102
+ return null;
103
+ return arr.length > 0 ? arr[0] : null;
104
+ }
105
+
106
+ // src/help/deepCloneWithJson/deepCloneWithJson.ts
107
+ function deepCloneWithJson(obj) {
108
+ return JSON.parse(JSON.stringify(obj));
109
+ }
110
+
111
+ // src/help/remove/remove.ts
112
+ function remove(arr, item) {
113
+ if (arr.length === 0)
114
+ return [];
115
+ const index = arr.indexOf(item);
116
+ if (index === -1)
117
+ return arr;
118
+ return [...arr.slice(0, index), ...arr.slice(index + 1)];
119
+ }
120
+
121
+ // src/help/searchInStr/searchInStr.ts
122
+ function searchInStr(str, key) {
123
+ return str.indexOf(key) === -1 ? [false, str] : [true, str.replace(key, "")];
124
+ }
125
+
126
+ // src/help/strToConvert/strToConvert.ts
127
+ function strToConvert(str, convert = "_") {
128
+ return str.replace(/\B([A-Z])/g, `${convert}$1`).toLowerCase();
129
+ }
130
+
131
+ // src/help/strToHump/strToHump.ts
132
+ function strToHump(str) {
133
+ if (str.startsWith("_"))
134
+ str = str.slice(1);
135
+ return str.replace(/([^_])(?:_+([^_]))/g, function($0, $1, $2) {
136
+ return $1 + $2.toUpperCase();
137
+ });
138
+ }
139
+
140
+ // src/help/deepAssign/deepAssign.ts
141
+ function deepAssign(...param) {
142
+ let result = Object.assign({}, ...param);
143
+ for (let item of param) {
144
+ for (const [idx, val] of Object.entries(item)) {
145
+ if (gettype(val) === "object") {
146
+ result[idx] = deepAssign(result[idx], val);
147
+ }
148
+ }
149
+ }
150
+ return result;
151
+ }
152
+ export {
153
+ data_get,
154
+ data_set,
155
+ deepAssign,
156
+ deepCloneWithJson,
157
+ emptyData,
158
+ gettype,
159
+ head,
160
+ parameterMerge,
161
+ recursiveDeepCopy,
162
+ remove,
163
+ searchInStr,
164
+ strToConvert,
165
+ strToHump
166
+ };
167
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/help/data_set/data_set.ts","../../src/help/data_get/data_get.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","../../src/help/remove/remove.ts","../../src/help/searchInStr/searchInStr.ts","../../src/help/strToConvert/strToConvert.ts","../../src/help/strToHump/strToHump.ts","../../src/help/deepAssign/deepAssign.ts"],"sourcesContent":["/**\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}","import { deepCloneWithJson, gettype } from \"..\";\r\n\r\n/**\r\n * 獲取資料\r\n * @param data 資料集{key:value}\r\n * @param key 資料對應的位置 app.column.name\r\n * @param defaultValue 如果取不到值要給予什麼參數,預設 null\r\n * @returns\r\n *\r\n * {a:[{b:a},{b:a}]}\r\n * a.b = [a,a]\r\n */\r\nexport function data_get(data: any, key: string, defaultValue: any = null,): any {\r\n switch (gettype(data)) {\r\n case \"object\":\r\n const coypData = deepCloneWithJson(data);\r\n const keys = key.split('.');\r\n let firstKey = keys.shift();\r\n if (!firstKey) return defaultValue;\r\n if (!(firstKey in coypData)) return defaultValue;\r\n\r\n let rep = coypData[firstKey];\r\n if (keys.length > 0)\r\n rep = data_get(rep, keys.join('.'), defaultValue);\r\n\r\n return rep ?? defaultValue;\r\n case 'undefined':\r\n case 'null':\r\n return defaultValue;\r\n case 'array':\r\n return (data as any[]).map((value: any) => data_get(value, key, defaultValue)) as any;\r\n default:\r\n return data;\r\n }\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 ","type TremoveValeu = string | number\r\n\r\n/**\r\n * 移除陣列某一個位置的值\r\n * @param arr 陣列\r\n * @param item 要移除的值\r\n * @returns\r\n */\r\nexport function remove(arr: TremoveValeu[], item: TremoveValeu) {\r\n if (arr.length === 0) return [];\r\n\r\n const index = arr.indexOf(item);\r\n if (index === -1) return arr;\r\n\r\n return [...arr.slice(0, index), ...arr.slice(index + 1)];\r\n}","/**\r\n * 尋找字串內是否有符合的值,並移除後回傳結果\r\n * @param str 字串\r\n * @param key 要搜尋的文字\r\n * @returns [boolean,string]\r\n */\r\nexport function searchInStr(str: string, key: string): [boolean, string] {\r\n return str.indexOf(key) === -1 ? [false, str] : [true, str.replace(key, '')];\r\n}","/**\r\n * 駝峰轉小寫+convert(default:底線)\r\n * @param str\r\n * @returns\r\n */\r\nexport function strToConvert(str: string, convert: string = \"_\") {\r\n return str.replace(/\\B([A-Z])/g, `${convert}$1`).toLowerCase();\r\n}","/**\r\n * 底線轉駝峰\r\n * @param str\r\n * @returns\r\n */\r\nexport function strToHump(str: string) {\r\n if (str.startsWith('_')) str = str.slice(1);\r\n\r\n return str.replace(/([^_])(?:_+([^_]))/g, function ($0, $1, $2) {\r\n return $1 + $2.toUpperCase();\r\n });\r\n}","import { gettype } from \"../gettype/gettype\";\r\n\r\n/**\r\n * 物件深度合併\r\n * @param target\r\n * @param sources\r\n * @returns\r\n */\r\nexport function deepAssign(...param: { [_: string]: any }[]) {\r\n let result = Object.assign({}, ...param);\r\n\r\n for (let item of param) {\r\n for (const [idx, val] of Object.entries<any>(item)) {\r\n if (gettype(val) === \"object\") {\r\n result[idx] = deepAssign(result[idx], val);\r\n }\r\n }\r\n }\r\n return result;\r\n}\r\n"],"mappings":";AAOO,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;;;ACRO,SAAS,SAAS,MAAW,KAAa,eAAoB,MAAY;AAC7E,UAAQ,QAAQ,IAAI,GAAG;AAAA,IACnB,KAAK;AACD,YAAM,WAAW,kBAAkB,IAAI;AACvC,YAAM,OAAO,IAAI,MAAM,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AAI,IAAI,IAAI;AAC9D,WAAO,KAAK,GAAG,YAAY;AAAA,EAC7B,CAAC;AACH;;;ACHO,SAAS,cAAc,OAA+B;AACzD,MAAI,SAAS,OAAO,OAAO,CAAC,GAAG,GAAG,KAAK;AAEvC,WAAS,QAAQ,OAAO;AACpB,eAAW,CAAC,KAAK,GAAG,KAAK,OAAO,QAAa,IAAI,GAAG;AAChD,UAAI,QAAQ,GAAG,MAAM,UAAU;AAC3B,eAAO,GAAG,IAAI,WAAW,OAAO,GAAG,GAAG,GAAG;AAAA,MAC7C;AAAA,IACJ;AAAA,EACJ;AACA,SAAO;AACX;","names":[]}
package/dist/index.d.mts CHANGED
@@ -1,65 +1 @@
1
- /**
2
- * 動態設定多層物件的參數
3
- * @param data 被設定的物件
4
- * @param key 位置
5
- * @param value 參數
6
- * @returns
7
- */
8
- declare function data_set(data: any, key: string, value: any): void;
9
-
10
- /**
11
- * 透過遞迴複製物件
12
- * @param o
13
- * @returns
14
- */
15
- declare function recursiveDeepCopy<T = any>(o: T): T;
16
-
17
- /**
18
- * 判斷資料是否為空值
19
- * @param data
20
- * @returns
21
- */
22
- declare function emptyData(data: any): boolean;
23
-
24
- /**
25
- * 回傳物體的型態
26
- * @param obj
27
- * @returns
28
- */
29
- declare function gettype<T = any>(obj: T): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "array" | "date" | "null";
30
-
31
- /**
32
- * 兩個參數的合併(只能是物件或者陣列)
33
- * 如果是空值就回傳空物件
34
- * @param value1
35
- * @param value2
36
- * @returns
37
- */
38
- declare function parameterMerge(value1?: any, value2?: any): any;
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
-
54
- declare const index_data_set: typeof data_set;
55
- declare const index_deepCloneWithJson: typeof deepCloneWithJson;
56
- declare const index_emptyData: typeof emptyData;
57
- declare const index_gettype: typeof gettype;
58
- declare const index_head: typeof head;
59
- declare const index_parameterMerge: typeof parameterMerge;
60
- declare const index_recursiveDeepCopy: typeof recursiveDeepCopy;
61
- declare namespace index {
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 };
63
- }
64
-
65
- export { index as help };
1
+ export { i as help } from './help/index.mjs';
package/dist/index.d.ts CHANGED
@@ -1,65 +1 @@
1
- /**
2
- * 動態設定多層物件的參數
3
- * @param data 被設定的物件
4
- * @param key 位置
5
- * @param value 參數
6
- * @returns
7
- */
8
- declare function data_set(data: any, key: string, value: any): void;
9
-
10
- /**
11
- * 透過遞迴複製物件
12
- * @param o
13
- * @returns
14
- */
15
- declare function recursiveDeepCopy<T = any>(o: T): T;
16
-
17
- /**
18
- * 判斷資料是否為空值
19
- * @param data
20
- * @returns
21
- */
22
- declare function emptyData(data: any): boolean;
23
-
24
- /**
25
- * 回傳物體的型態
26
- * @param obj
27
- * @returns
28
- */
29
- declare function gettype<T = any>(obj: T): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "array" | "date" | "null";
30
-
31
- /**
32
- * 兩個參數的合併(只能是物件或者陣列)
33
- * 如果是空值就回傳空物件
34
- * @param value1
35
- * @param value2
36
- * @returns
37
- */
38
- declare function parameterMerge(value1?: any, value2?: any): any;
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
-
54
- declare const index_data_set: typeof data_set;
55
- declare const index_deepCloneWithJson: typeof deepCloneWithJson;
56
- declare const index_emptyData: typeof emptyData;
57
- declare const index_gettype: typeof gettype;
58
- declare const index_head: typeof head;
59
- declare const index_parameterMerge: typeof parameterMerge;
60
- declare const index_recursiveDeepCopy: typeof recursiveDeepCopy;
61
- declare namespace index {
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 };
63
- }
64
-
65
- export { index as help };
1
+ export { i as help } from './help/index.js';
package/dist/index.js CHANGED
@@ -27,13 +27,19 @@ module.exports = __toCommonJS(src_exports);
27
27
  // src/help/index.ts
28
28
  var help_exports = {};
29
29
  __export(help_exports, {
30
+ data_get: () => data_get,
30
31
  data_set: () => data_set,
32
+ deepAssign: () => deepAssign,
31
33
  deepCloneWithJson: () => deepCloneWithJson,
32
34
  emptyData: () => emptyData,
33
35
  gettype: () => gettype,
34
36
  head: () => head,
35
37
  parameterMerge: () => parameterMerge,
36
- recursiveDeepCopy: () => recursiveDeepCopy
38
+ recursiveDeepCopy: () => recursiveDeepCopy,
39
+ remove: () => remove,
40
+ searchInStr: () => searchInStr,
41
+ strToConvert: () => strToConvert,
42
+ strToHump: () => strToHump
37
43
  });
38
44
 
39
45
  // src/help/data_set/data_set.ts
@@ -51,6 +57,31 @@ function data_set(data, key, value) {
51
57
  data_set(data[firstKey], keys.join("."), value);
52
58
  }
53
59
 
60
+ // src/help/data_get/data_get.ts
61
+ function data_get(data, key, defaultValue = null) {
62
+ switch (gettype(data)) {
63
+ case "object":
64
+ const coypData = deepCloneWithJson(data);
65
+ const keys = key.split(".");
66
+ let firstKey = keys.shift();
67
+ if (!firstKey)
68
+ return defaultValue;
69
+ if (!(firstKey in coypData))
70
+ return defaultValue;
71
+ let rep = coypData[firstKey];
72
+ if (keys.length > 0)
73
+ rep = data_get(rep, keys.join("."), defaultValue);
74
+ return rep != null ? rep : defaultValue;
75
+ case "undefined":
76
+ case "null":
77
+ return defaultValue;
78
+ case "array":
79
+ return data.map((value) => data_get(value, key, defaultValue));
80
+ default:
81
+ return data;
82
+ }
83
+ }
84
+
54
85
  // src/help/recursiveDeepCopy/recursiveDeepCopy.ts
55
86
  function recursiveDeepCopy(o) {
56
87
  switch (Object.prototype.toString.apply(o)) {
@@ -120,6 +151,48 @@ function head(arr) {
120
151
  function deepCloneWithJson(obj) {
121
152
  return JSON.parse(JSON.stringify(obj));
122
153
  }
154
+
155
+ // src/help/remove/remove.ts
156
+ function remove(arr, item) {
157
+ if (arr.length === 0)
158
+ return [];
159
+ const index = arr.indexOf(item);
160
+ if (index === -1)
161
+ return arr;
162
+ return [...arr.slice(0, index), ...arr.slice(index + 1)];
163
+ }
164
+
165
+ // src/help/searchInStr/searchInStr.ts
166
+ function searchInStr(str, key) {
167
+ return str.indexOf(key) === -1 ? [false, str] : [true, str.replace(key, "")];
168
+ }
169
+
170
+ // src/help/strToConvert/strToConvert.ts
171
+ function strToConvert(str, convert = "_") {
172
+ return str.replace(/\B([A-Z])/g, `${convert}$1`).toLowerCase();
173
+ }
174
+
175
+ // src/help/strToHump/strToHump.ts
176
+ function strToHump(str) {
177
+ if (str.startsWith("_"))
178
+ str = str.slice(1);
179
+ return str.replace(/([^_])(?:_+([^_]))/g, function($0, $1, $2) {
180
+ return $1 + $2.toUpperCase();
181
+ });
182
+ }
183
+
184
+ // src/help/deepAssign/deepAssign.ts
185
+ function deepAssign(...param) {
186
+ let result = Object.assign({}, ...param);
187
+ for (let item of param) {
188
+ for (const [idx, val] of Object.entries(item)) {
189
+ if (gettype(val) === "object") {
190
+ result[idx] = deepAssign(result[idx], val);
191
+ }
192
+ }
193
+ }
194
+ return result;
195
+ }
123
196
  // Annotate the CommonJS export names for ESM import in node:
124
197
  0 && (module.exports = {
125
198
  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","../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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AAA,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":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/help/index.ts","../src/help/data_set/data_set.ts","../src/help/data_get/data_get.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","../src/help/remove/remove.ts","../src/help/searchInStr/searchInStr.ts","../src/help/strToConvert/strToConvert.ts","../src/help/strToHump/strToHump.ts","../src/help/deepAssign/deepAssign.ts"],"sourcesContent":["import * as help from './help';\r\n\r\nexport { help }","export * from './data_set/data_set';\r\nexport * from './data_get/data_get';\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\nexport * from './remove/remove';\r\nexport * from './searchInStr/searchInStr';\r\nexport * from './strToConvert/strToConvert';\r\nexport * from './strToHump/strToHump';\r\nexport * from './deepAssign/deepAssign';","/**\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}","import { deepCloneWithJson, gettype } from \"..\";\r\n\r\n/**\r\n * 獲取資料\r\n * @param data 資料集{key:value}\r\n * @param key 資料對應的位置 app.column.name\r\n * @param defaultValue 如果取不到值要給予什麼參數,預設 null\r\n * @returns\r\n *\r\n * {a:[{b:a},{b:a}]}\r\n * a.b = [a,a]\r\n */\r\nexport function data_get(data: any, key: string, defaultValue: any = null,): any {\r\n switch (gettype(data)) {\r\n case \"object\":\r\n const coypData = deepCloneWithJson(data);\r\n const keys = key.split('.');\r\n let firstKey = keys.shift();\r\n if (!firstKey) return defaultValue;\r\n if (!(firstKey in coypData)) return defaultValue;\r\n\r\n let rep = coypData[firstKey];\r\n if (keys.length > 0)\r\n rep = data_get(rep, keys.join('.'), defaultValue);\r\n\r\n return rep ?? defaultValue;\r\n case 'undefined':\r\n case 'null':\r\n return defaultValue;\r\n case 'array':\r\n return (data as any[]).map((value: any) => data_get(value, key, defaultValue)) as any;\r\n default:\r\n return data;\r\n }\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 ","type TremoveValeu = string | number\r\n\r\n/**\r\n * 移除陣列某一個位置的值\r\n * @param arr 陣列\r\n * @param item 要移除的值\r\n * @returns\r\n */\r\nexport function remove(arr: TremoveValeu[], item: TremoveValeu) {\r\n if (arr.length === 0) return [];\r\n\r\n const index = arr.indexOf(item);\r\n if (index === -1) return arr;\r\n\r\n return [...arr.slice(0, index), ...arr.slice(index + 1)];\r\n}","/**\r\n * 尋找字串內是否有符合的值,並移除後回傳結果\r\n * @param str 字串\r\n * @param key 要搜尋的文字\r\n * @returns [boolean,string]\r\n */\r\nexport function searchInStr(str: string, key: string): [boolean, string] {\r\n return str.indexOf(key) === -1 ? [false, str] : [true, str.replace(key, '')];\r\n}","/**\r\n * 駝峰轉小寫+convert(default:底線)\r\n * @param str\r\n * @returns\r\n */\r\nexport function strToConvert(str: string, convert: string = \"_\") {\r\n return str.replace(/\\B([A-Z])/g, `${convert}$1`).toLowerCase();\r\n}","/**\r\n * 底線轉駝峰\r\n * @param str\r\n * @returns\r\n */\r\nexport function strToHump(str: string) {\r\n if (str.startsWith('_')) str = str.slice(1);\r\n\r\n return str.replace(/([^_])(?:_+([^_]))/g, function ($0, $1, $2) {\r\n return $1 + $2.toUpperCase();\r\n });\r\n}","import { gettype } from \"../gettype/gettype\";\r\n\r\n/**\r\n * 物件深度合併\r\n * @param target\r\n * @param sources\r\n * @returns\r\n */\r\nexport function deepAssign(...param: { [_: string]: any }[]) {\r\n let result = Object.assign({}, ...param);\r\n\r\n for (let item of param) {\r\n for (const [idx, val] of Object.entries<any>(item)) {\r\n if (gettype(val) === \"object\") {\r\n result[idx] = deepAssign(result[idx], val);\r\n }\r\n }\r\n }\r\n return result;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;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;;;ACRO,SAAS,SAAS,MAAW,KAAa,eAAoB,MAAY;AAC7E,UAAQ,QAAQ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I,IAAI,WAAW,GAAG;AAAG,UAAM,IAAI,MAAM,CAAC;AAE1C,SAAO,IAAI,QAAQ,uBAAuB,SAAU,IAAI,IAAI,IAAI;AAC9D,WAAO,KAAK,GAAG,YAAY;AAAA,EAC7B,CAAC;AACH;;;ACHO,SAAS,cAAc,OAA+B;AACzD,MAAI,SAAS,OAAO,OAAO,CAAC,GAAG,GAAG,KAAK;AAEvC,WAAS,QAAQ,OAAO;AACpB,eAAW,CAAC,KAAK,GAAG,KAAK,OAAO,QAAa,IAAI,GAAG;AAChD,UAAI,QAAQ,GAAG,MAAM,UAAU;AAC3B,eAAO,GAAG,IAAI,WAAW,OAAO,GAAG,GAAG,GAAG;AAAA,MAC7C;AAAA,IACJ;AAAA,EACJ;AACA,SAAO;AACX;","names":[]}
package/dist/index.mjs CHANGED
@@ -7,13 +7,19 @@ var __export = (target, all) => {
7
7
  // src/help/index.ts
8
8
  var help_exports = {};
9
9
  __export(help_exports, {
10
+ data_get: () => data_get,
10
11
  data_set: () => data_set,
12
+ deepAssign: () => deepAssign,
11
13
  deepCloneWithJson: () => deepCloneWithJson,
12
14
  emptyData: () => emptyData,
13
15
  gettype: () => gettype,
14
16
  head: () => head,
15
17
  parameterMerge: () => parameterMerge,
16
- recursiveDeepCopy: () => recursiveDeepCopy
18
+ recursiveDeepCopy: () => recursiveDeepCopy,
19
+ remove: () => remove,
20
+ searchInStr: () => searchInStr,
21
+ strToConvert: () => strToConvert,
22
+ strToHump: () => strToHump
17
23
  });
18
24
 
19
25
  // src/help/data_set/data_set.ts
@@ -31,6 +37,31 @@ function data_set(data, key, value) {
31
37
  data_set(data[firstKey], keys.join("."), value);
32
38
  }
33
39
 
40
+ // src/help/data_get/data_get.ts
41
+ function data_get(data, key, defaultValue = null) {
42
+ switch (gettype(data)) {
43
+ case "object":
44
+ const coypData = deepCloneWithJson(data);
45
+ const keys = key.split(".");
46
+ let firstKey = keys.shift();
47
+ if (!firstKey)
48
+ return defaultValue;
49
+ if (!(firstKey in coypData))
50
+ return defaultValue;
51
+ let rep = coypData[firstKey];
52
+ if (keys.length > 0)
53
+ rep = data_get(rep, keys.join("."), defaultValue);
54
+ return rep != null ? rep : defaultValue;
55
+ case "undefined":
56
+ case "null":
57
+ return defaultValue;
58
+ case "array":
59
+ return data.map((value) => data_get(value, key, defaultValue));
60
+ default:
61
+ return data;
62
+ }
63
+ }
64
+
34
65
  // src/help/recursiveDeepCopy/recursiveDeepCopy.ts
35
66
  function recursiveDeepCopy(o) {
36
67
  switch (Object.prototype.toString.apply(o)) {
@@ -100,6 +131,48 @@ function head(arr) {
100
131
  function deepCloneWithJson(obj) {
101
132
  return JSON.parse(JSON.stringify(obj));
102
133
  }
134
+
135
+ // src/help/remove/remove.ts
136
+ function remove(arr, item) {
137
+ if (arr.length === 0)
138
+ return [];
139
+ const index = arr.indexOf(item);
140
+ if (index === -1)
141
+ return arr;
142
+ return [...arr.slice(0, index), ...arr.slice(index + 1)];
143
+ }
144
+
145
+ // src/help/searchInStr/searchInStr.ts
146
+ function searchInStr(str, key) {
147
+ return str.indexOf(key) === -1 ? [false, str] : [true, str.replace(key, "")];
148
+ }
149
+
150
+ // src/help/strToConvert/strToConvert.ts
151
+ function strToConvert(str, convert = "_") {
152
+ return str.replace(/\B([A-Z])/g, `${convert}$1`).toLowerCase();
153
+ }
154
+
155
+ // src/help/strToHump/strToHump.ts
156
+ function strToHump(str) {
157
+ if (str.startsWith("_"))
158
+ str = str.slice(1);
159
+ return str.replace(/([^_])(?:_+([^_]))/g, function($0, $1, $2) {
160
+ return $1 + $2.toUpperCase();
161
+ });
162
+ }
163
+
164
+ // src/help/deepAssign/deepAssign.ts
165
+ function deepAssign(...param) {
166
+ let result = Object.assign({}, ...param);
167
+ for (let item of param) {
168
+ for (const [idx, val] of Object.entries(item)) {
169
+ if (gettype(val) === "object") {
170
+ result[idx] = deepAssign(result[idx], val);
171
+ }
172
+ }
173
+ }
174
+ return result;
175
+ }
103
176
  export {
104
177
  help_exports as help
105
178
  };
@@ -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","../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;AACd,SAAK,QAAQ,IAAI,CAAC;AAEtB,MAAI,KAAK,SAAS,GAAG;A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,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":[]}
1
+ {"version":3,"sources":["../src/help/index.ts","../src/help/data_set/data_set.ts","../src/help/data_get/data_get.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","../src/help/remove/remove.ts","../src/help/searchInStr/searchInStr.ts","../src/help/strToConvert/strToConvert.ts","../src/help/strToHump/strToHump.ts","../src/help/deepAssign/deepAssign.ts"],"sourcesContent":["export * from './data_set/data_set';\r\nexport * from './data_get/data_get';\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\nexport * from './remove/remove';\r\nexport * from './searchInStr/searchInStr';\r\nexport * from './strToConvert/strToConvert';\r\nexport * from './strToHump/strToHump';\r\nexport * from './deepAssign/deepAssign';","/**\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}","import { deepCloneWithJson, gettype } from \"..\";\r\n\r\n/**\r\n * 獲取資料\r\n * @param data 資料集{key:value}\r\n * @param key 資料對應的位置 app.column.name\r\n * @param defaultValue 如果取不到值要給予什麼參數,預設 null\r\n * @returns\r\n *\r\n * {a:[{b:a},{b:a}]}\r\n * a.b = [a,a]\r\n */\r\nexport function data_get(data: any, key: string, defaultValue: any = null,): any {\r\n switch (gettype(data)) {\r\n case \"object\":\r\n const coypData = deepCloneWithJson(data);\r\n const keys = key.split('.');\r\n let firstKey = keys.shift();\r\n if (!firstKey) return defaultValue;\r\n if (!(firstKey in coypData)) return defaultValue;\r\n\r\n let rep = coypData[firstKey];\r\n if (keys.length > 0)\r\n rep = data_get(rep, keys.join('.'), defaultValue);\r\n\r\n return rep ?? defaultValue;\r\n case 'undefined':\r\n case 'null':\r\n return defaultValue;\r\n case 'array':\r\n return (data as any[]).map((value: any) => data_get(value, key, defaultValue)) as any;\r\n default:\r\n return data;\r\n }\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 ","type TremoveValeu = string | number\r\n\r\n/**\r\n * 移除陣列某一個位置的值\r\n * @param arr 陣列\r\n * @param item 要移除的值\r\n * @returns\r\n */\r\nexport function remove(arr: TremoveValeu[], item: TremoveValeu) {\r\n if (arr.length === 0) return [];\r\n\r\n const index = arr.indexOf(item);\r\n if (index === -1) return arr;\r\n\r\n return [...arr.slice(0, index), ...arr.slice(index + 1)];\r\n}","/**\r\n * 尋找字串內是否有符合的值,並移除後回傳結果\r\n * @param str 字串\r\n * @param key 要搜尋的文字\r\n * @returns [boolean,string]\r\n */\r\nexport function searchInStr(str: string, key: string): [boolean, string] {\r\n return str.indexOf(key) === -1 ? [false, str] : [true, str.replace(key, '')];\r\n}","/**\r\n * 駝峰轉小寫+convert(default:底線)\r\n * @param str\r\n * @returns\r\n */\r\nexport function strToConvert(str: string, convert: string = \"_\") {\r\n return str.replace(/\\B([A-Z])/g, `${convert}$1`).toLowerCase();\r\n}","/**\r\n * 底線轉駝峰\r\n * @param str\r\n * @returns\r\n */\r\nexport function strToHump(str: string) {\r\n if (str.startsWith('_')) str = str.slice(1);\r\n\r\n return str.replace(/([^_])(?:_+([^_]))/g, function ($0, $1, $2) {\r\n return $1 + $2.toUpperCase();\r\n });\r\n}","import { gettype } from \"../gettype/gettype\";\r\n\r\n/**\r\n * 物件深度合併\r\n * @param target\r\n * @param sources\r\n * @returns\r\n */\r\nexport function deepAssign(...param: { [_: string]: any }[]) {\r\n let result = Object.assign({}, ...param);\r\n\r\n for (let item of param) {\r\n for (const [idx, val] of Object.entries<any>(item)) {\r\n if (gettype(val) === \"object\") {\r\n result[idx] = deepAssign(result[idx], val);\r\n }\r\n }\r\n }\r\n return result;\r\n}\r\n"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;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;;;ACRO,SAAS,SAAS,MAAW,KAAa,eAAoB,MAAY;AAC7E,UAAQ,QAAQ,IAAI,GAAG;AAAA,IACnB,KAAK;AACD,YAAM,W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,CAAC;AAE1C,SAAO,IAAI,QAAQ,uBAAuB,SAAU,IAAI,IAAI,IAAI;AAC9D,WAAO,KAAK,GAAG,YAAY;AAAA,EAC7B,CAAC;AACH;;;ACHO,SAAS,cAAc,OAA+B;AACzD,MAAI,SAAS,OAAO,OAAO,CAAC,GAAG,GAAG,KAAK;AAEvC,WAAS,QAAQ,OAAO;AACpB,eAAW,CAAC,KAAK,GAAG,KAAK,OAAO,QAAa,IAAI,GAAG;AAChD,UAAI,QAAQ,GAAG,MAAM,UAAU;AAC3B,eAAO,GAAG,IAAI,WAAW,OAAO,GAAG,GAAG,GAAG;AAAA,MAC7C;AAAA,IACJ;AAAA,EACJ;AACA,SAAO;AACX;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aimidy/util",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",