data-structure-typed 1.12.21 → 1.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +278 -179
  2. package/dist/data-structures/binary-tree/binary-tree.d.ts +46 -1
  3. package/dist/data-structures/binary-tree/binary-tree.js +67 -0
  4. package/dist/data-structures/binary-tree/segment-tree.d.ts +29 -0
  5. package/dist/data-structures/binary-tree/segment-tree.js +45 -0
  6. package/dist/data-structures/graph/abstract-graph.d.ts +40 -5
  7. package/dist/data-structures/graph/abstract-graph.js +47 -7
  8. package/dist/data-structures/graph/directed-graph.d.ts +8 -0
  9. package/dist/data-structures/graph/directed-graph.js +14 -2
  10. package/dist/data-structures/graph/undirected-graph.d.ts +10 -0
  11. package/dist/data-structures/graph/undirected-graph.js +23 -1
  12. package/dist/data-structures/hash/coordinate-map.d.ts +7 -1
  13. package/dist/data-structures/hash/coordinate-map.js +16 -0
  14. package/dist/data-structures/hash/coordinate-set.d.ts +7 -1
  15. package/dist/data-structures/hash/coordinate-set.js +16 -0
  16. package/dist/data-structures/heap/heap.d.ts +16 -0
  17. package/dist/data-structures/heap/heap.js +38 -0
  18. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +30 -7
  19. package/dist/data-structures/linked-list/doubly-linked-list.js +71 -4
  20. package/dist/data-structures/linked-list/singly-linked-list.d.ts +262 -328
  21. package/dist/data-structures/linked-list/singly-linked-list.js +258 -273
  22. package/dist/data-structures/priority-queue/priority-queue.d.ts +7 -1
  23. package/dist/data-structures/priority-queue/priority-queue.js +18 -2
  24. package/dist/data-structures/queue/deque.d.ts +18 -7
  25. package/dist/data-structures/queue/deque.js +50 -3
  26. package/dist/data-structures/types/abstract-graph.d.ts +2 -2
  27. package/dist/utils/types/utils.d.ts +0 -49
  28. package/dist/utils/types/utils.js +14 -52
  29. package/dist/utils/utils.d.ts +1 -97
  30. package/dist/utils/utils.js +197 -546
  31. package/package.json +4 -3
  32. package/src/data-structures/binary-tree/aa-tree.ts +1 -1
  33. package/src/data-structures/binary-tree/binary-tree.ts +84 -14
  34. package/src/data-structures/binary-tree/segment-tree.ts +45 -13
  35. package/src/data-structures/graph/abstract-graph.ts +58 -15
  36. package/src/data-structures/graph/directed-graph.ts +14 -5
  37. package/src/data-structures/graph/undirected-graph.ts +23 -6
  38. package/src/data-structures/hash/coordinate-map.ts +13 -1
  39. package/src/data-structures/hash/coordinate-set.ts +13 -1
  40. package/src/data-structures/heap/heap.ts +31 -0
  41. package/src/data-structures/linked-list/doubly-linked-list.ts +68 -11
  42. package/src/data-structures/linked-list/singly-linked-list.ts +312 -334
  43. package/src/data-structures/priority-queue/priority-queue.ts +15 -2
  44. package/src/data-structures/queue/deque.ts +38 -8
  45. package/src/data-structures/types/abstract-graph.ts +3 -3
  46. package/src/utils/types/utils.ts +165 -167
  47. package/src/utils/utils.ts +209 -480
  48. package/tests/unit/data-structures/graph/directed-graph.test.ts +431 -8
@@ -1,15 +1,5 @@
1
- import _ from 'lodash';
2
- import type {AnyFunction, JSONObject, JSONSerializable} from './types';
3
-
4
- export function randomText(length: number) {
5
- let result = '';
6
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
7
- const charactersLength = characters.length;
8
- for (let i = 0; i < length; i++) {
9
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
10
- }
11
- return result;
12
- }
1
+ // import _ from 'lodash';
2
+ // import type {AnyFunction, CaseType, JSONObject, JSONSerializable} from './types';
13
3
 
14
4
  export const uuidV4 = function () {
15
5
  return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
@@ -18,446 +8,214 @@ export const uuidV4 = function () {
18
8
  });
19
9
  };
20
10
 
21
- export class IncrementId {
22
- private _id: string;
23
- private readonly _prefix: string;
24
-
25
- constructor(prefix?: string) {
26
- this._prefix = prefix ? prefix : '';
27
- this._id = this._prefix + '0';
28
- }
29
-
30
- getId() {
31
- const {_id, _prefix} = this;
32
- if (!_id) {
33
- this._id = _prefix + '0';
34
- } else {
35
- const idNumStr = _id.substr(_prefix.length, _id.length - _prefix.length);
36
- const newIdNum = parseInt(idNumStr, 10) + 1;
37
- this._id = _prefix + newIdNum.toString();
38
- }
39
- return this._id;
40
- }
41
- }
42
-
43
- export function incrementId(prefix?: string) {
44
- const _prefix = prefix ? prefix : '';
45
- let _id = _prefix + '0';
46
- return function id() {
47
- const idNumStr = _id.substr(_prefix.length, _id.length - _prefix.length);
48
- const newIdNum = parseInt(idNumStr, 10) + 1;
49
- _id = _prefix + newIdNum.toString();
50
- return _id;
51
- };
52
- }
53
-
54
- export const getValue = <T, K extends keyof T>(obj: T, names: K[]): Array<T[K]> => names.map(i => obj[i]);
55
-
56
- export const isObject = (object: string | JSONObject | boolean | AnyFunction | number) => object != null && typeof object === 'object';
57
-
58
- export const looseEqual = (a: any, b: any): boolean => a == b;
59
-
60
- export const strictEqual = (a: any, b: any): boolean => a === b;
61
-
62
- export const strictObjectIsEqual = (a: any, b: any): boolean => Object.is(a, b);
63
-
64
- export const deepObjectStrictEqual = (object1: JSONSerializable, object2: JSONSerializable) => {
65
- const keys1 = Object.keys(object1);
66
- const keys2 = Object.keys(object2);
67
- if (keys1.length !== keys2.length) {
68
- return false;
69
- }
70
- for (const key of keys1) {
71
- const val1 = object1[key];
72
- const val2 = object2[key];
73
- const areObjects = isObject(val1) && isObject(val2);
74
- if (
75
- areObjects && !deepObjectStrictEqual(val1, val2) ||
76
- !areObjects && val1 !== val2
77
- ) {
78
- return false;
79
- }
80
- }
81
- return true;
82
- };
83
-
84
- export function reverseColor(oldColor: string) {
85
- const oldColorTemp = '0x' + oldColor.replace(/#/g, '');
86
- const str = '000000' + (0xFFFFFF - Number(oldColorTemp)).toString(16);
87
- return '#' + str.substring(str.length - 6, str.length);
88
- }
89
-
90
- export const isSameStructure = (objA: unknown, objB: unknown) => {
91
- const objATraversable = objA as JSONSerializable;
92
- const objBTraversable = objB as JSONSerializable;
93
- const objAKeys = Object.keys(objATraversable);
94
- const objBKeys = Object.keys(objBTraversable);
95
- let isSame = true;
96
- if (objAKeys.length !== objBKeys.length) {
97
- return isSame = false;
98
- } else {
99
- objAKeys.forEach((i) => {
100
- if (!objBKeys.includes(i)) {
101
- return isSame = false;
102
- }
103
- });
104
- return isSame;
105
- }
106
- };
107
-
108
- export const isLeafParent = (obj: JSONObject) => {
109
- let isLeaf = true;
110
- Object.values(obj).forEach(value => {
111
- if (typeof value === 'object' && value instanceof Array) {
112
- value.forEach(item => {
113
- if (typeof item === 'object') {
114
- return false;
115
- }
116
- });
117
- return isLeaf = true;
118
- }
119
- if (!['string', 'boolean', 'number', 'undefined', 'function'].includes(typeof value) && (value !== null)) {
120
- return isLeaf = false;
121
- }
122
- });
123
- return isLeaf;
124
- };
125
-
126
- export const addDays = (date: Date, days: number): Date => {
127
- date.setDate(date.getDate() + days);
128
- return date;
129
- };
130
-
131
- export class WaitManager {
132
- private _time30 = 20000;
133
- private readonly _nXSpeed: number = 1;
134
-
135
- constructor(nXSpeed?: number) {
136
- if (nXSpeed === undefined) nXSpeed = 1;
137
- this._nXSpeed = nXSpeed;
138
- }
139
-
140
- private _time1 = 1000;
141
-
142
- get time1(): number {
143
- return this._time1 / this._nXSpeed;
144
- }
145
-
146
- private _time2 = 2000;
147
-
148
- get time2(): number {
149
- return this._time2 / this._nXSpeed;
150
- }
151
-
152
- private _time3 = 3000;
153
-
154
- get time3(): number {
155
- return this._time3 / this._nXSpeed;
156
- }
157
-
158
- private _time4 = 4000;
159
-
160
- get time4(): number {
161
- return this._time4 / this._nXSpeed;
162
- }
163
-
164
- private _time10 = 10000;
165
-
166
- get time10(): number {
167
- return this._time10 / this._nXSpeed;
168
- }
169
-
170
- private _time20 = 20000;
171
-
172
- get time20(): number {
173
- return this._time20 / this._nXSpeed;
174
- }
175
-
176
- get time50(): number {
177
- return this._time30 / this._nXSpeed;
178
- }
179
-
180
- private _time60 = 60000;
181
-
182
- get time60(): number {
183
- return this._time60 / this._nXSpeed;
184
- }
185
-
186
- private _cusTime = 1000;
187
-
188
- get cusTime(): number {
189
- return this._cusTime / this._nXSpeed;
190
- }
191
-
192
- set cusTime(v: number) {
193
- this._cusTime = v;
194
- }
195
- }
196
-
197
- export const wait = async (ms: number, resolveValue?: any) => {
198
- return new Promise((resolve, reject) => {
199
- setTimeout(() => {
200
- const finalResolveValue = resolveValue || true;
201
- resolve(finalResolveValue);
202
- }, ms);
203
- });
204
- };
205
-
206
- export function extractValue<Item>(data: { key: string, value: Item }[]) {
207
- let result: Item[] = [];
208
- if (data && data.length > 0) {
209
- result = data.map(item => item.value);
210
- }
211
- return result;
212
- }
213
-
214
- export function keyValueToArray<Item>(data: { [key: string]: Item }) {
215
- const itemArray: Array<Item> = [];
216
- const keys = Object.keys(data);
217
- for (const i of keys) {
218
- itemArray.push({...data[i], _id: i});
219
- }
220
- return itemArray;
221
- }
222
-
223
- export function minuted(time: number) {
224
- const minutes = Math.floor(time / 60000).toString();
225
- const seconds = Math.floor((time % 60000) / 1000).toString().padStart(2, '0');
226
- return `${minutes}:${seconds}`;
227
- }
228
-
229
- export function randomDate(start?: Date, end?: Date, specificProbabilityStart?: Date, specificProbability?: number) {
230
- if (!start) start = new Date('1970-1-1');
231
- if (!end) end = new Date();
232
-
233
- if (specificProbabilityStart) {
234
- if (!specificProbability) specificProbability = 0.5;
235
- if (Math.random() <= specificProbability) {
236
- return new Date(specificProbabilityStart.getTime() + Math.random() * (end.getTime() - specificProbabilityStart.getTime()));
237
- }
238
- }
239
-
240
- return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
241
- }
242
-
243
- export const capitalizeWords = (str: string) => str.replace(/(?:^|\s)\S/g, (a: string) => a.toUpperCase());
244
-
245
- export const capitalizeFirstLetter = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
246
-
247
- export const comparerArray = <T>(otherArray: T[], limitKeys?: string[]) => {
248
- return function (current: T) {
249
- return otherArray.filter(function (other: T) {
250
- if (!limitKeys) {
251
- return _.isEqual(current, other);
252
- } else {
253
- // TODO
254
- }
255
- }).length == 0;
256
- };
257
- };
258
-
259
- export const onlyInA = <T>(a: T[], b: T[]) => a.filter(comparerArray(b));
260
-
261
- export const onlyInB = <T>(a: T[], b: T[]) => b.filter(comparerArray(a));
262
-
263
- export const diffAB = <T>(a: T[], b: T[]) => onlyInA(a, b).concat(onlyInB(a, b));
264
-
265
- export class StringUtil {
266
- // camelCase
267
- static toCamelCase(str: string) {
268
- return _.camelCase(str);
269
- }
270
-
271
- // snake_case
272
- static toSnakeCase(str: string) {
273
- return _.snakeCase(str);
274
- }
275
-
276
- // PascalCase
277
- static toPascalCase(str: string) {
278
- return _.startCase(_.camelCase(str)).replace(/ /g, '');
279
- }
280
-
281
- // CONSTANT_CASE
282
- static toConstantCase(str: string) {
283
- return _.upperCase(str).replace(/ /g, '_');
284
- }
285
-
286
- // kebab-case
287
- static toKebabCase(str: string) {
288
- return _.kebabCase(str);
289
- }
290
-
291
- // lowercase
292
- static toLowerCase(str: string) {
293
- return _.lowerCase(str).replace(/ /g, '');
294
- }
295
-
296
- // Title Case
297
- static toTitleCase(str: string) {
298
- return _.startCase(_.camelCase(str));
299
- }
300
-
301
- // Sentence case
302
- static toSentenceCase(str: string) {
303
- return _.upperFirst(_.lowerCase(str));
304
- }
305
-
306
- // path/case
307
- static toPathCase(str: string) {
308
- return _.lowerCase(str).replace(/ /g, '/');
309
- }
310
-
311
- // dot.case
312
- static toDotCase(str: string) {
313
- return _.lowerCase(str).replace(/ /g, '.');
314
- }
315
- }
316
-
317
- export type CaseType =
318
- 'camel'
319
- | 'snake'
320
- | 'pascal'
321
- | 'constant'
322
- | 'kebab'
323
- | 'lower'
324
- | 'title'
325
- | 'sentence'
326
- | 'path'
327
- | 'dot';
328
- export const deepKeysConvert = (obj: any, toType?: CaseType): any => {
329
- const _toType = toType || 'snake';
330
- if (Array.isArray(obj)) {
331
- return obj.map(v => deepKeysConvert(v, _toType));
332
- } else if (obj !== null && obj.constructor === Object) {
333
- return Object.keys(obj).reduce(
334
- (result, key) => {
335
- let newKey = '';
336
- switch (_toType) {
337
- case 'camel':
338
- newKey = StringUtil.toCamelCase(key);
339
- break;
340
- case 'snake':
341
- newKey = StringUtil.toSnakeCase(key);
342
- break;
343
- case 'pascal':
344
- newKey = StringUtil.toPascalCase(key);
345
- break;
346
- case 'constant':
347
- newKey = StringUtil.toConstantCase(key);
348
- break;
349
- case 'kebab':
350
- newKey = StringUtil.toKebabCase(key);
351
- break;
352
- case 'lower':
353
- newKey = StringUtil.toLowerCase(key);
354
- break;
355
- case 'title':
356
- newKey = StringUtil.toTitleCase(key);
357
- break;
358
- case 'sentence':
359
- newKey = StringUtil.toSentenceCase(key);
360
- break;
361
- case 'path':
362
- newKey = StringUtil.toPathCase(key);
363
- break;
364
- case 'dot':
365
- newKey = StringUtil.toDotCase(key);
366
- break;
367
- default:
368
- newKey = StringUtil.toDotCase(key);
369
- break;
370
- }
371
- return {
372
- ...result,
373
- [newKey]: deepKeysConvert(obj[key], _toType),
374
- };
375
- },
376
- {},
377
- );
378
- }
379
- return obj;
380
- };
381
-
382
- export const deepRemoveByKey = (obj: any, keysToBeRemoved: string[]) => {
383
- const result = _.transform(obj, function (result: JSONSerializable, value: any, key: string) {
384
- if (_.isObject(value)) {
385
- value = deepRemoveByKey(value, keysToBeRemoved);
386
- }
387
- if (!keysToBeRemoved.includes(key)) {
388
- _.isArray(obj) ? result.push(value) : result[key] = value;
389
- }
390
- });
391
- return result as typeof obj;
392
- };
393
-
394
- export const deepRenameKeys = (obj: JSONSerializable, keysMap: { [key in string]: string }) => {
395
- return _.transform(obj, function (result: JSONSerializable, value: any, key: string | number) {
396
- const currentKey = keysMap[key] || key;
397
- result[currentKey] = _.isObject(value) ? deepRenameKeys(value, keysMap) : value;
398
- });
399
- };
400
-
401
- export const deepReplaceValues = (obj: JSONSerializable, keyReducerMap: { [key in string]: (item: JSONSerializable) => any }) => {
402
- const newObject = _.clone(obj) as JSONSerializable;
403
- _.each(obj, (val: any, key: string) => {
404
- for (const item in keyReducerMap) {
405
- if (key === item) {
406
- newObject[key] = keyReducerMap[item](newObject);
407
- } else if (typeof (val) === 'object' || val instanceof Array) {
408
- newObject[key] = deepReplaceValues(val, keyReducerMap);
409
- }
410
- }
411
- });
412
- return newObject;
413
- };
11
+ // export const isObject = (object: string | JSONObject | boolean | AnyFunction | number) => object != null && typeof object === 'object';
12
+
13
+ // export const deepObjectStrictEqual = (object1: JSONSerializable, object2: JSONSerializable) => {
14
+ // const keys1 = Object.keys(object1);
15
+ // const keys2 = Object.keys(object2);
16
+ // if (keys1.length !== keys2.length) {
17
+ // return false;
18
+ // }
19
+ // for (const key of keys1) {
20
+ // const val1 = object1[key];
21
+ // const val2 = object2[key];
22
+ // const areObjects = isObject(val1) && isObject(val2);
23
+ // if (
24
+ // areObjects && !deepObjectStrictEqual(val1, val2) ||
25
+ // !areObjects && val1 !== val2
26
+ // ) {
27
+ // return false;
28
+ // }
29
+ // }
30
+ // return true;
31
+ // };
32
+
33
+ // export class StringUtil {
34
+ // // camelCase
35
+ // static toCamelCase(str: string) {
36
+ // return _.camelCase(str);
37
+ // }
38
+ //
39
+ // // snake_case
40
+ // static toSnakeCase(str: string) {
41
+ // return _.snakeCase(str);
42
+ // }
43
+ //
44
+ // // PascalCase
45
+ // static toPascalCase(str: string) {
46
+ // return _.startCase(_.camelCase(str)).replace(/ /g, '');
47
+ // }
48
+ //
49
+ // // CONSTANT_CASE
50
+ // static toConstantCase(str: string) {
51
+ // return _.upperCase(str).replace(/ /g, '_');
52
+ // }
53
+ //
54
+ // // kebab-case
55
+ // static toKebabCase(str: string) {
56
+ // return _.kebabCase(str);
57
+ // }
58
+ //
59
+ // // lowercase
60
+ // static toLowerCase(str: string) {
61
+ // return _.lowerCase(str).replace(/ /g, '');
62
+ // }
63
+ //
64
+ // // Title Case
65
+ // static toTitleCase(str: string) {
66
+ // return _.startCase(_.camelCase(str));
67
+ // }
68
+ //
69
+ // // Sentence case
70
+ // static toSentenceCase(str: string) {
71
+ // return _.upperFirst(_.lowerCase(str));
72
+ // }
73
+ //
74
+ // // path/case
75
+ // static toPathCase(str: string) {
76
+ // return _.lowerCase(str).replace(/ /g, '/');
77
+ // }
78
+ //
79
+ // // dot.case
80
+ // static toDotCase(str: string) {
81
+ // return _.lowerCase(str).replace(/ /g, '.');
82
+ // }
83
+ // }
84
+
85
+
86
+ // export const deepKeysConvert = (obj: any, toType?: CaseType): any => {
87
+ // const _toType = toType || 'snake';
88
+ // if (Array.isArray(obj)) {
89
+ // return obj.map(v => deepKeysConvert(v, _toType));
90
+ // } else if (obj !== null && obj.constructor === Object) {
91
+ // return Object.keys(obj).reduce(
92
+ // (result, key) => {
93
+ // let newKey = '';
94
+ // switch (_toType) {
95
+ // case 'camel':
96
+ // newKey = StringUtil.toCamelCase(key);
97
+ // break;
98
+ // case 'snake':
99
+ // newKey = StringUtil.toSnakeCase(key);
100
+ // break;
101
+ // case 'pascal':
102
+ // newKey = StringUtil.toPascalCase(key);
103
+ // break;
104
+ // case 'constant':
105
+ // newKey = StringUtil.toConstantCase(key);
106
+ // break;
107
+ // case 'kebab':
108
+ // newKey = StringUtil.toKebabCase(key);
109
+ // break;
110
+ // case 'lower':
111
+ // newKey = StringUtil.toLowerCase(key);
112
+ // break;
113
+ // case 'title':
114
+ // newKey = StringUtil.toTitleCase(key);
115
+ // break;
116
+ // case 'sentence':
117
+ // newKey = StringUtil.toSentenceCase(key);
118
+ // break;
119
+ // case 'path':
120
+ // newKey = StringUtil.toPathCase(key);
121
+ // break;
122
+ // case 'dot':
123
+ // newKey = StringUtil.toDotCase(key);
124
+ // break;
125
+ // default:
126
+ // newKey = StringUtil.toDotCase(key);
127
+ // break;
128
+ // }
129
+ // return {
130
+ // ...result,
131
+ // [newKey]: deepKeysConvert(obj[key], _toType),
132
+ // };
133
+ // },
134
+ // {},
135
+ // );
136
+ // }
137
+ // return obj;
138
+ // };
139
+
140
+ // export const deepRemoveByKey = (obj: any, keysToBeRemoved: string[]) => {
141
+ // const result = _.transform(obj, function (result: JSONSerializable, value: any, key: string) {
142
+ // if (_.isObject(value)) {
143
+ // value = deepRemoveByKey(value, keysToBeRemoved);
144
+ // }
145
+ // if (!keysToBeRemoved.includes(key)) {
146
+ // _.isArray(obj) ? result.push(value) : result[key] = value;
147
+ // }
148
+ // });
149
+ // return result as typeof obj;
150
+ // };
151
+
152
+ // export const deepRenameKeys = (obj: JSONSerializable, keysMap: { [key in string]: string }) => {
153
+ // return _.transform(obj, function (result: JSONSerializable, value: any, key: string | number) {
154
+ // const currentKey = keysMap[key] || key;
155
+ // result[currentKey] = _.isObject(value) ? deepRenameKeys(value, keysMap) : value;
156
+ // });
157
+ // };
158
+
159
+ // export const deepReplaceValues = (obj: JSONSerializable, keyReducerMap: { [key in string]: (item: JSONSerializable) => any }) => {
160
+ // const newObject = _.clone(obj) as JSONSerializable;
161
+ // _.each(obj, (val: any, key: string) => {
162
+ // for (const item in keyReducerMap) {
163
+ // if (key === item) {
164
+ // newObject[key] = keyReducerMap[item](newObject);
165
+ // } else if (typeof (val) === 'object' || val instanceof Array) {
166
+ // newObject[key] = deepReplaceValues(val, keyReducerMap);
167
+ // }
168
+ // }
169
+ // });
170
+ // return newObject;
171
+ // };
414
172
 
415
173
  // TODO determine depth and pass root node as a param through callback
416
- export const deepAdd = (obj: JSONSerializable, keyReducerMap: { [key in string]: (item: JSONSerializable) => any }, isItemRootParent?: boolean) => {
417
- const newObject = _.clone(obj) as JSONObject | [];
418
- if (_.isObject(newObject) && !_.isArray(newObject)) {
419
- for (const item in keyReducerMap) {
420
- newObject[item] = keyReducerMap[item](newObject);
421
- }
422
- }
423
- _.each(obj, (val: any, key: string | number) => {
424
- if (_.isObject(val)) {
425
- for (const item in keyReducerMap) {
426
- // @ts-ignore
427
- newObject[key] = deepAdd(val, keyReducerMap, isItemRootParent);
428
- }
429
- }
430
- });
431
- return newObject;
432
- };
433
-
434
- const styleString = (color: string) => `color: ${color}; font-weight: bold`;
435
-
436
- const styleHeader = (header: string) => `%c[${header}]`;
437
-
438
- export const bunnyConsole = {
439
- log: (headerLog = 'bunny', ...args: any[]) => {
440
- return console.log(styleHeader(headerLog), styleString('black'), ...args);
441
- },
442
- warn: (headerLog = 'bunny', ...args: any[]) => {
443
- return console.warn(styleHeader(headerLog), styleString('orange'), ...args);
444
- },
445
- error: (headerLog = 'bunny', ...args: any[]) => {
446
- return console.error(styleHeader(headerLog), styleString('red'), ...args);
447
- }
448
- };
449
-
450
- export const timeStart = () => {
451
- return performance ? performance.now() : new Date().getTime();
452
- };
453
-
454
- export const timeEnd = (startTime: number, headerLog?: string, consoleConditionFn?: (timeSpent: number) => boolean) => {
455
- const timeSpent = (performance ? performance.now() : new Date().getTime()) - startTime;
456
- const isPassCondition = consoleConditionFn ? consoleConditionFn(timeSpent) : true;
457
- if (isPassCondition) {
458
- bunnyConsole.log(headerLog ? headerLog : 'time spent', timeSpent.toFixed(2));
459
- }
460
- };
174
+ // export const deepAdd = (obj: JSONSerializable, keyReducerMap: { [key in string]: (item: JSONSerializable) => any }, isItemRootParent?: boolean) => {
175
+ // const newObject = _.clone(obj) as JSONObject | [];
176
+ // if (_.isObject(newObject) && !_.isArray(newObject)) {
177
+ // for (const item in keyReducerMap) {
178
+ // newObject[item] = keyReducerMap[item](newObject);
179
+ // }
180
+ // }
181
+ // _.each(obj, (val: any, key: string | number) => {
182
+ // if (_.isObject(val)) {
183
+ // for (const item in keyReducerMap) {
184
+ // // @ts-ignore
185
+ // newObject[key] = deepAdd(val, keyReducerMap, isItemRootParent);
186
+ // }
187
+ // }
188
+ // });
189
+ // return newObject;
190
+ // };
191
+
192
+ // const styleString = (color: string) => `color: ${color}; font-weight: bold`;
193
+
194
+ // const styleHeader = (header: string) => `%c[${header}]`;
195
+
196
+ // export const bunnyConsole = {
197
+ // log: (headerLog = 'bunny', ...args: any[]) => {
198
+ // return console.log(styleHeader(headerLog), styleString('black'), ...args);
199
+ // },
200
+ // warn: (headerLog = 'bunny', ...args: any[]) => {
201
+ // return console.warn(styleHeader(headerLog), styleString('orange'), ...args);
202
+ // },
203
+ // error: (headerLog = 'bunny', ...args: any[]) => {
204
+ // return console.error(styleHeader(headerLog), styleString('red'), ...args);
205
+ // }
206
+ // };
207
+
208
+ // export const timeStart = () => {
209
+ // return performance ? performance.now() : new Date().getTime();
210
+ // };
211
+
212
+ // export const timeEnd = (startTime: number, headerLog?: string, consoleConditionFn?: (timeSpent: number) => boolean) => {
213
+ // const timeSpent = (performance ? performance.now() : new Date().getTime()) - startTime;
214
+ // const isPassCondition = consoleConditionFn ? consoleConditionFn(timeSpent) : true;
215
+ // if (isPassCondition) {
216
+ // bunnyConsole.log(headerLog ? headerLog : 'time spent', timeSpent.toFixed(2));
217
+ // }
218
+ // };
461
219
 
462
220
  export const arrayRemove = function <T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean): T[] {
463
221
  let i = -1, len = array ? array.length : 0;
@@ -475,35 +233,6 @@ export const arrayRemove = function <T>(array: T[], predicate: (item: T, index:
475
233
  return result;
476
234
  };
477
235
 
478
- export function memo() {
479
- const cache: { [k: string]: any } = {};
480
- // eslint-disable-next-line @typescript-eslint/ban-types
481
- return function (target: Object, propertyKey: string, descriptor: PropertyDescriptor) {
482
- const originalMethod = descriptor.value;
483
- descriptor.value = function (...args: any[]) {
484
- const cacheKey = `__cacheKey__${args.toString()}`;
485
- // eslint-disable-next-line no-prototype-builtins
486
- if (!cache.hasOwnProperty(cacheKey)) {
487
- cache[cacheKey] = originalMethod.apply(this, args);
488
- }
489
- return cache[cacheKey];
490
- }
491
- }
492
- }
493
-
494
- export function zip<T = number, T1 = number>(array1: T[], array2: T1[], options?: { isToObj: boolean }) {
495
- const zipped: [T, T1][] = [];
496
- const zippedObjCoords: { x: T, y: T1 }[] = [];
497
- const {isToObj} = options ? options : {isToObj: false};
498
- for (let i = 0; i < array1.length; i++) {
499
- if (isToObj) {
500
- zippedObjCoords.push({x: array1[i], y: array2[i]})
501
- } else {
502
- zipped.push([array1[i], array2[i]]);
503
- }
504
- }
505
- return isToObj ? zippedObjCoords : zipped;
506
- }
507
236
 
508
237
  /**
509
238
  * data-structure-typed
@@ -512,7 +241,7 @@ export function zip<T = number, T1 = number>(array1: T[], array2: T1[], options?
512
241
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
513
242
  * @license MIT License
514
243
  */
515
- import {Thunk, ToThunkFn, TrlAsyncFn, TrlFn} from './types';
244
+ import type {Thunk, ToThunkFn, TrlAsyncFn, TrlFn} from './types';
516
245
 
517
246
  export const THUNK_SYMBOL = Symbol('thunk')
518
247