data-structure-typed 1.15.1 → 1.16.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 (224) hide show
  1. package/README.md +398 -27
  2. package/dist/data-structures/binary-tree/binary-tree.d.ts +30 -30
  3. package/dist/data-structures/binary-tree/binary-tree.js +55 -55
  4. package/dist/data-structures/binary-tree/segment-tree.d.ts +17 -17
  5. package/dist/data-structures/binary-tree/segment-tree.js +30 -30
  6. package/dist/data-structures/graph/abstract-graph.d.ts +6 -6
  7. package/dist/data-structures/graph/abstract-graph.js +6 -6
  8. package/dist/data-structures/graph/directed-graph.d.ts +4 -4
  9. package/dist/data-structures/graph/directed-graph.js +6 -6
  10. package/dist/data-structures/graph/undirected-graph.d.ts +3 -3
  11. package/dist/data-structures/hash/coordinate-map.d.ts +2 -2
  12. package/dist/data-structures/hash/coordinate-set.d.ts +2 -2
  13. package/dist/data-structures/heap/heap.d.ts +40 -25
  14. package/dist/data-structures/heap/heap.js +72 -27
  15. package/dist/data-structures/heap/max-heap.d.ts +3 -3
  16. package/dist/data-structures/heap/min-heap.d.ts +3 -3
  17. package/dist/data-structures/index.d.ts +1 -0
  18. package/dist/data-structures/index.js +1 -0
  19. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +9 -9
  20. package/dist/data-structures/linked-list/doubly-linked-list.js +12 -12
  21. package/dist/data-structures/linked-list/singly-linked-list.d.ts +7 -7
  22. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +4 -5
  23. package/dist/data-structures/priority-queue/max-priority-queue.js +30 -6
  24. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +4 -5
  25. package/dist/data-structures/priority-queue/min-priority-queue.js +31 -6
  26. package/dist/data-structures/priority-queue/priority-queue.d.ts +20 -9
  27. package/dist/data-structures/priority-queue/priority-queue.js +34 -28
  28. package/dist/data-structures/queue/deque.d.ts +1 -1
  29. package/dist/data-structures/tree/index.d.ts +1 -0
  30. package/dist/data-structures/tree/index.js +17 -0
  31. package/dist/data-structures/tree/tree.d.ts +9 -0
  32. package/dist/data-structures/tree/tree.js +52 -0
  33. package/dist/data-structures/types/heap.d.ts +0 -4
  34. package/dist/utils/types/utils.d.ts +1 -3
  35. package/dist/utils/types/utils.js +0 -14
  36. package/dist/utils/utils.js +0 -197
  37. package/docs/.nojekyll +1 -0
  38. package/docs/assets/highlight.css +92 -0
  39. package/docs/assets/main.js +58 -0
  40. package/docs/assets/search.js +1 -0
  41. package/docs/assets/style.css +1367 -0
  42. package/docs/classes/AVLTree.html +2192 -0
  43. package/docs/classes/AVLTreeNode.html +574 -0
  44. package/docs/classes/AaTree.html +150 -0
  45. package/docs/classes/AbstractEdge.html +269 -0
  46. package/docs/classes/AbstractGraph.html +927 -0
  47. package/docs/classes/AbstractVertex.html +215 -0
  48. package/docs/classes/ArrayDeque.html +417 -0
  49. package/docs/classes/BST.html +2038 -0
  50. package/docs/classes/BSTNode.html +570 -0
  51. package/docs/classes/BTree.html +150 -0
  52. package/docs/classes/BinaryIndexedTree.html +289 -0
  53. package/docs/classes/BinaryTree.html +1827 -0
  54. package/docs/classes/BinaryTreeNode.html +533 -0
  55. package/docs/classes/Character.html +198 -0
  56. package/docs/classes/CoordinateMap.html +469 -0
  57. package/docs/classes/CoordinateSet.html +430 -0
  58. package/docs/classes/Deque.html +767 -0
  59. package/docs/classes/DirectedEdge.html +354 -0
  60. package/docs/classes/DirectedGraph.html +1243 -0
  61. package/docs/classes/DirectedVertex.html +226 -0
  62. package/docs/classes/DoublyLinkedList.html +733 -0
  63. package/docs/classes/DoublyLinkedListNode.html +258 -0
  64. package/docs/classes/Heap.html +482 -0
  65. package/docs/classes/HeapItem.html +233 -0
  66. package/docs/classes/Matrix2D.html +480 -0
  67. package/docs/classes/MatrixNTI2D.html +218 -0
  68. package/docs/classes/MaxHeap.html +500 -0
  69. package/docs/classes/MaxPriorityQueue.html +809 -0
  70. package/docs/classes/MinHeap.html +501 -0
  71. package/docs/classes/MinPriorityQueue.html +811 -0
  72. package/docs/classes/Navigator.html +291 -0
  73. package/docs/classes/ObjectDeque.html +423 -0
  74. package/docs/classes/PriorityQueue.html +733 -0
  75. package/docs/classes/Queue.html +370 -0
  76. package/docs/classes/RBTree.html +150 -0
  77. package/docs/classes/SegmentTree.html +345 -0
  78. package/docs/classes/SegmentTreeNode.html +418 -0
  79. package/docs/classes/SinglyLinkedList.html +1105 -0
  80. package/docs/classes/SinglyLinkedListNode.html +375 -0
  81. package/docs/classes/SplayTree.html +150 -0
  82. package/docs/classes/Stack.html +346 -0
  83. package/docs/classes/TreeMultiSet.html +2036 -0
  84. package/docs/classes/TreeNode.html +236 -0
  85. package/docs/classes/Trie.html +350 -0
  86. package/docs/classes/TrieNode.html +258 -0
  87. package/docs/classes/TwoThreeTree.html +150 -0
  88. package/docs/classes/UndirectedEdge.html +313 -0
  89. package/docs/classes/UndirectedGraph.html +1080 -0
  90. package/docs/classes/UndirectedVertex.html +226 -0
  91. package/docs/classes/Vector2D.html +783 -0
  92. package/docs/enums/CP.html +159 -0
  93. package/docs/enums/FamilyPosition.html +159 -0
  94. package/docs/enums/LoopType.html +160 -0
  95. package/docs/index.html +494 -0
  96. package/docs/interfaces/AVLTreeDeleted.html +161 -0
  97. package/docs/interfaces/BinaryTreeNodeObj.html +168 -0
  98. package/docs/interfaces/HeapOptions.html +167 -0
  99. package/docs/interfaces/IDirectedGraph.html +243 -0
  100. package/docs/interfaces/IGraph.html +427 -0
  101. package/docs/interfaces/NavigatorParams.html +197 -0
  102. package/docs/interfaces/PriorityQueueOptions.html +168 -0
  103. package/docs/modules.html +218 -0
  104. package/docs/types/BSTComparator.html +140 -0
  105. package/docs/types/BSTDeletedResult.html +137 -0
  106. package/docs/types/BinaryTreeDeleted.html +137 -0
  107. package/docs/types/BinaryTreeNodeId.html +125 -0
  108. package/docs/types/BinaryTreeNodePropertyName.html +125 -0
  109. package/docs/types/DFSOrderPattern.html +125 -0
  110. package/docs/types/DijkstraResult.html +145 -0
  111. package/docs/types/Direction.html +125 -0
  112. package/docs/types/DoublyLinkedListGetBy.html +125 -0
  113. package/docs/types/NodeOrPropertyName.html +125 -0
  114. package/docs/types/PriorityQueueComparator.html +145 -0
  115. package/docs/types/PriorityQueueDFSOrderPattern.html +125 -0
  116. package/docs/types/ResultByProperty.html +130 -0
  117. package/docs/types/ResultsByProperty.html +130 -0
  118. package/docs/types/SegmentTreeNodeVal.html +125 -0
  119. package/docs/types/SpecifyOptional.html +132 -0
  120. package/docs/types/Thunk.html +133 -0
  121. package/docs/types/ToThunkFn.html +133 -0
  122. package/docs/types/TopologicalStatus.html +125 -0
  123. package/docs/types/TreeMultiSetDeletedResult.html +137 -0
  124. package/docs/types/TrlAsyncFn.html +138 -0
  125. package/docs/types/TrlFn.html +138 -0
  126. package/docs/types/Turning.html +125 -0
  127. package/docs/types/VertexId.html +125 -0
  128. package/{tests/unit/data-structures/binary-tree → notes}/bst.test.ts +11 -15
  129. package/notes/note.md +23 -0
  130. package/package.json +2 -4
  131. package/.idea/data-structure-typed.iml +0 -14
  132. package/.idea/modules.xml +0 -8
  133. package/.idea/vcs.xml +0 -6
  134. package/src/assets/complexities-diff.jpg +0 -0
  135. package/src/assets/data-structure-complexities.jpg +0 -0
  136. package/src/assets/logo.png +0 -0
  137. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  138. package/src/data-structures/binary-tree/avl-tree.ts +0 -293
  139. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  140. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -69
  141. package/src/data-structures/binary-tree/binary-tree.ts +0 -1485
  142. package/src/data-structures/binary-tree/bst.ts +0 -497
  143. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  144. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  145. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  146. package/src/data-structures/binary-tree/index.ts +0 -11
  147. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  148. package/src/data-structures/binary-tree/segment-tree.ts +0 -248
  149. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  150. package/src/data-structures/binary-tree/tree-multiset.ts +0 -53
  151. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  152. package/src/data-structures/diagrams/README.md +0 -5
  153. package/src/data-structures/graph/abstract-graph.ts +0 -956
  154. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  155. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  156. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  157. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  158. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  159. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  160. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  161. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  162. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  163. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  164. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  165. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  166. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  167. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  168. package/src/data-structures/graph/directed-graph.ts +0 -424
  169. package/src/data-structures/graph/index.ts +0 -3
  170. package/src/data-structures/graph/undirected-graph.ts +0 -254
  171. package/src/data-structures/hash/coordinate-map.ts +0 -71
  172. package/src/data-structures/hash/coordinate-set.ts +0 -60
  173. package/src/data-structures/hash/hash-table.ts +0 -1
  174. package/src/data-structures/hash/index.ts +0 -6
  175. package/src/data-structures/hash/pair.ts +0 -1
  176. package/src/data-structures/hash/tree-map.ts +0 -1
  177. package/src/data-structures/hash/tree-set.ts +0 -1
  178. package/src/data-structures/heap/heap.ts +0 -156
  179. package/src/data-structures/heap/index.ts +0 -3
  180. package/src/data-structures/heap/max-heap.ts +0 -31
  181. package/src/data-structures/heap/min-heap.ts +0 -34
  182. package/src/data-structures/index.ts +0 -13
  183. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -351
  184. package/src/data-structures/linked-list/index.ts +0 -2
  185. package/src/data-structures/linked-list/singly-linked-list.ts +0 -748
  186. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  187. package/src/data-structures/matrix/index.ts +0 -4
  188. package/src/data-structures/matrix/matrix.ts +0 -27
  189. package/src/data-structures/matrix/matrix2d.ts +0 -208
  190. package/src/data-structures/matrix/navigator.ts +0 -122
  191. package/src/data-structures/matrix/vector2d.ts +0 -316
  192. package/src/data-structures/priority-queue/index.ts +0 -3
  193. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -24
  194. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -24
  195. package/src/data-structures/priority-queue/priority-queue.ts +0 -346
  196. package/src/data-structures/queue/deque.ts +0 -241
  197. package/src/data-structures/queue/index.ts +0 -2
  198. package/src/data-structures/queue/queue.ts +0 -120
  199. package/src/data-structures/stack/index.ts +0 -1
  200. package/src/data-structures/stack/stack.ts +0 -98
  201. package/src/data-structures/trie/index.ts +0 -1
  202. package/src/data-structures/trie/trie.ts +0 -225
  203. package/src/data-structures/types/abstract-graph.ts +0 -51
  204. package/src/data-structures/types/avl-tree.ts +0 -6
  205. package/src/data-structures/types/binary-tree.ts +0 -15
  206. package/src/data-structures/types/bst.ts +0 -5
  207. package/src/data-structures/types/directed-graph.ts +0 -18
  208. package/src/data-structures/types/doubly-linked-list.ts +0 -1
  209. package/src/data-structures/types/heap.ts +0 -8
  210. package/src/data-structures/types/index.ts +0 -13
  211. package/src/data-structures/types/navigator.ts +0 -13
  212. package/src/data-structures/types/priority-queue.ts +0 -9
  213. package/src/data-structures/types/segment-tree.ts +0 -1
  214. package/src/data-structures/types/singly-linked-list.ts +0 -1
  215. package/src/data-structures/types/tree-multiset.ts +0 -3
  216. package/src/index.ts +0 -1
  217. package/src/utils/index.ts +0 -2
  218. package/src/utils/types/index.ts +0 -1
  219. package/src/utils/types/utils.ts +0 -176
  220. package/src/utils/utils.ts +0 -290
  221. package/tests/unit/data-structures/graph/abstract-graph.ts +0 -0
  222. package/tests/unit/data-structures/graph/directed-graph.test.ts +0 -495
  223. package/tests/unit/data-structures/graph/index.ts +0 -3
  224. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
@@ -1,176 +0,0 @@
1
- // export type JSONSerializable = {
2
- // [key: string]: any
3
- // }
4
-
5
- // export type JSONValue = string | number | boolean | undefined | JSONObject;
6
- //
7
- // export interface JSONObject {
8
- // [key: string]: JSONValue;
9
- // }
10
- //
11
- // export type AnyFunction<A extends any[] = any[], R = any> = (...args: A) => R;
12
-
13
- // export type Primitive =
14
- // | number
15
- // | string
16
- // | boolean
17
- // | symbol
18
- // | undefined
19
- // | null
20
- // | void
21
- // | AnyFunction
22
- // | Date;
23
-
24
- // export type Cast<T, TComplex> = { [M in keyof TComplex]: T };
25
-
26
- // export type DeepLeavesWrap<T, TComplex> =
27
- // T extends string ? Cast<string, TComplex>
28
- // : T extends number ? Cast<number, TComplex>
29
- // : T extends boolean ? Cast<boolean, TComplex>
30
- // : T extends undefined ? Cast<undefined, TComplex>
31
- // : T extends null ? Cast<null, TComplex>
32
- // : T extends void ? Cast<void, TComplex>
33
- // : T extends symbol ? Cast<symbol, TComplex>
34
- // : T extends AnyFunction ? Cast<AnyFunction, TComplex>
35
- // : T extends Date ? Cast<Date, TComplex>
36
- // : {
37
- // [K in keyof T]:
38
- // T[K] extends (infer U)[] ? DeepLeavesWrap<U, TComplex>[]
39
- // : DeepLeavesWrap<T[K], TComplex>;
40
- // }
41
-
42
-
43
- // type Json = null | string | number | boolean | Json [] | { [name: string]: Json }
44
-
45
- // export type TypeName<T> = T extends string
46
- // ? 'string'
47
- // : T extends number
48
- // ? 'number'
49
- // : T extends boolean
50
- // ? 'boolean'
51
- // : T extends undefined
52
- // ? 'undefined'
53
- // : T extends AnyFunction
54
- // ? 'function'
55
- // : 'object';
56
-
57
- // export type JsonKeys<T> = keyof {
58
- // [P in keyof T]: number
59
- // }
60
-
61
- /**
62
- * A function that emits a side effect and does not return anything.
63
- */
64
- // export type Procedure = (...args: any[]) => void;
65
-
66
- // export type DebounceOptions = {
67
- // isImmediate?: boolean;
68
- // maxWait?: number;
69
- // };
70
-
71
- // export interface DebouncedFunction<F extends Procedure> {
72
- // cancel: () => void;
73
- //
74
- // (this: ThisParameterType<F>, ...args: [...Parameters<F>]): void;
75
- // }
76
-
77
- // export type MonthKey =
78
- // 'January' |
79
- // 'February' |
80
- // 'March' |
81
- // 'April' |
82
- // 'May' |
83
- // 'June' |
84
- // 'July' |
85
- // 'August' |
86
- // 'September' |
87
- // 'October' |
88
- // 'November' |
89
- // 'December';
90
-
91
- // export type Month = { [key in MonthKey]: string }
92
-
93
- // export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
94
-
95
- // export class TreeNode<T> {
96
- // id: string;
97
- // name?: string | undefined;
98
- // value?: T | undefined;
99
- // children?: TreeNode<T>[] | undefined;
100
- //
101
- // constructor(id: string, name?: string, value?: T, children?: TreeNode<T>[]) {
102
- // this.id = id;
103
- // this.name = name || '';
104
- // this.value = value || undefined;
105
- // this.children = children || [];
106
- // }
107
- //
108
- // addChildren(children: TreeNode<T> | TreeNode<T> []) {
109
- // if (!this.children) {
110
- // this.children = [];
111
- // }
112
- // if (children instanceof TreeNode) {
113
- // this.children.push(children);
114
- // } else {
115
- // this.children = this.children.concat(children);
116
- // }
117
- // }
118
- //
119
- // getHeight() {
120
- // // eslint-disable-next-line @typescript-eslint/no-this-alias
121
- // const beginRoot = this;
122
- // let maxDepth = 1;
123
- // if (beginRoot) {
124
- // const bfs = (node: TreeNode<T>, level: number) => {
125
- // if (level > maxDepth) {
126
- // maxDepth = level;
127
- // }
128
- // const {children} = node;
129
- // if (children) {
130
- // for (let i = 0, len = children.length; i < len; i++) {
131
- // bfs(children[i], level + 1);
132
- // }
133
- // }
134
- // };
135
- // bfs(beginRoot, 1);
136
- // }
137
- // return maxDepth;
138
- // }
139
- //
140
- // }
141
-
142
- // export type OrderType = 'InOrder' | 'PreOrder' | 'PostOrder'
143
-
144
- // export type DeepProxy<T> = T extends (...args: any[]) => infer R
145
- // ? (...args: [...Parameters<T>]) => DeepProxy<R>
146
- // : T extends object
147
- // ? { [K in keyof T]: DeepProxy<T[K]> }
148
- // : T;
149
-
150
- // export type DeepProxyOnChange = (target: any, property: string | symbol, value: any, receiver: any, descriptor: any, result: any) => void;
151
-
152
- // export type DeepProxyOnGet = (target: any, property: string | symbol, value: any, receiver: any, descriptor: any, result: any) => void;
153
-
154
- // export type CurryFunc<T> = T extends (...args: infer Args) => infer R
155
- // ? Args extends [infer Arg, ...infer RestArgs]
156
- // ? (arg: Arg) => CurryFunc<(...args: RestArgs) => R>
157
- // : R
158
- // : T;
159
-
160
-
161
- export type ToThunkFn = () => ReturnType<TrlFn>;
162
- export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: Symbol };
163
- export type TrlFn = (...args: any[]) => any;
164
- export type TrlAsyncFn = (...args: any[]) => any;
165
-
166
- // export type CaseType =
167
- // 'camel'
168
- // | 'snake'
169
- // | 'pascal'
170
- // | 'constant'
171
- // | 'kebab'
172
- // | 'lower'
173
- // | 'title'
174
- // | 'sentence'
175
- // | 'path'
176
- // | 'dot';
@@ -1,290 +0,0 @@
1
- // import _ from 'lodash';
2
- // import type {AnyFunction, CaseType, JSONObject, JSONSerializable} from './types';
3
-
4
- export const uuidV4 = function () {
5
- return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
6
- const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
7
- return v.toString(16);
8
- });
9
- };
10
-
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
- // };
172
-
173
- // TODO determine depth and pass root node as a param through callback
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
- // };
219
-
220
- export const arrayRemove = function <T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean): T[] {
221
- let i = -1, len = array ? array.length : 0;
222
- const result = [];
223
-
224
- while (++i < len) {
225
- const value = array[i];
226
- if (predicate(value, i, array)) {
227
- result.push(value);
228
- Array.prototype.splice.call(array, i--, 1);
229
- len--;
230
- }
231
- }
232
-
233
- return result;
234
- };
235
-
236
-
237
- /**
238
- * data-structure-typed
239
- *
240
- * @author Tyler Zeng
241
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
242
- * @license MIT License
243
- */
244
- import type {Thunk, ToThunkFn, TrlAsyncFn, TrlFn} from './types';
245
-
246
- export const THUNK_SYMBOL = Symbol('thunk')
247
-
248
- export const isThunk = (fnOrValue: any) => {
249
- return typeof fnOrValue === 'function' && fnOrValue.__THUNK__ === THUNK_SYMBOL
250
- }
251
-
252
- export const toThunk = (fn: ToThunkFn): Thunk => {
253
- const thunk = () => fn()
254
- thunk.__THUNK__ = THUNK_SYMBOL
255
- return thunk
256
- }
257
-
258
- export const trampoline = (fn: TrlFn) => {
259
- const cont = (...args: [...Parameters<TrlFn>]) => toThunk(() => fn(...args))
260
-
261
- return Object.assign(
262
- (...args: [...Parameters<TrlFn>]) => {
263
- let result = fn(...args)
264
-
265
- while (isThunk(result) && typeof result === 'function') {
266
- result = result()
267
- }
268
-
269
- return result
270
- },
271
- {cont}
272
- )
273
- }
274
-
275
- export const trampolineAsync = (fn: TrlAsyncFn) => {
276
- const cont = (...args: [...Parameters<TrlAsyncFn>]) => toThunk(() => fn(...args))
277
-
278
- return Object.assign(
279
- async (...args: [...Parameters<TrlAsyncFn>]) => {
280
- let result = await fn(...args)
281
-
282
- while (isThunk(result) && typeof result === 'function') {
283
- result = await result()
284
- }
285
-
286
- return result
287
- },
288
- {cont}
289
- )
290
- }