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.
- package/README.md +398 -27
- package/dist/data-structures/binary-tree/binary-tree.d.ts +30 -30
- package/dist/data-structures/binary-tree/binary-tree.js +55 -55
- package/dist/data-structures/binary-tree/segment-tree.d.ts +17 -17
- package/dist/data-structures/binary-tree/segment-tree.js +30 -30
- package/dist/data-structures/graph/abstract-graph.d.ts +6 -6
- package/dist/data-structures/graph/abstract-graph.js +6 -6
- package/dist/data-structures/graph/directed-graph.d.ts +4 -4
- package/dist/data-structures/graph/directed-graph.js +6 -6
- package/dist/data-structures/graph/undirected-graph.d.ts +3 -3
- package/dist/data-structures/hash/coordinate-map.d.ts +2 -2
- package/dist/data-structures/hash/coordinate-set.d.ts +2 -2
- package/dist/data-structures/heap/heap.d.ts +40 -25
- package/dist/data-structures/heap/heap.js +72 -27
- package/dist/data-structures/heap/max-heap.d.ts +3 -3
- package/dist/data-structures/heap/min-heap.d.ts +3 -3
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +9 -9
- package/dist/data-structures/linked-list/doubly-linked-list.js +12 -12
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +7 -7
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +4 -5
- package/dist/data-structures/priority-queue/max-priority-queue.js +30 -6
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +4 -5
- package/dist/data-structures/priority-queue/min-priority-queue.js +31 -6
- package/dist/data-structures/priority-queue/priority-queue.d.ts +20 -9
- package/dist/data-structures/priority-queue/priority-queue.js +34 -28
- package/dist/data-structures/queue/deque.d.ts +1 -1
- package/dist/data-structures/tree/index.d.ts +1 -0
- package/dist/data-structures/tree/index.js +17 -0
- package/dist/data-structures/tree/tree.d.ts +9 -0
- package/dist/data-structures/tree/tree.js +52 -0
- package/dist/data-structures/types/heap.d.ts +0 -4
- package/dist/utils/types/utils.d.ts +1 -3
- package/dist/utils/types/utils.js +0 -14
- package/dist/utils/utils.js +0 -197
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +92 -0
- package/docs/assets/main.js +58 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1367 -0
- package/docs/classes/AVLTree.html +2192 -0
- package/docs/classes/AVLTreeNode.html +574 -0
- package/docs/classes/AaTree.html +150 -0
- package/docs/classes/AbstractEdge.html +269 -0
- package/docs/classes/AbstractGraph.html +927 -0
- package/docs/classes/AbstractVertex.html +215 -0
- package/docs/classes/ArrayDeque.html +417 -0
- package/docs/classes/BST.html +2038 -0
- package/docs/classes/BSTNode.html +570 -0
- package/docs/classes/BTree.html +150 -0
- package/docs/classes/BinaryIndexedTree.html +289 -0
- package/docs/classes/BinaryTree.html +1827 -0
- package/docs/classes/BinaryTreeNode.html +533 -0
- package/docs/classes/Character.html +198 -0
- package/docs/classes/CoordinateMap.html +469 -0
- package/docs/classes/CoordinateSet.html +430 -0
- package/docs/classes/Deque.html +767 -0
- package/docs/classes/DirectedEdge.html +354 -0
- package/docs/classes/DirectedGraph.html +1243 -0
- package/docs/classes/DirectedVertex.html +226 -0
- package/docs/classes/DoublyLinkedList.html +733 -0
- package/docs/classes/DoublyLinkedListNode.html +258 -0
- package/docs/classes/Heap.html +482 -0
- package/docs/classes/HeapItem.html +233 -0
- package/docs/classes/Matrix2D.html +480 -0
- package/docs/classes/MatrixNTI2D.html +218 -0
- package/docs/classes/MaxHeap.html +500 -0
- package/docs/classes/MaxPriorityQueue.html +809 -0
- package/docs/classes/MinHeap.html +501 -0
- package/docs/classes/MinPriorityQueue.html +811 -0
- package/docs/classes/Navigator.html +291 -0
- package/docs/classes/ObjectDeque.html +423 -0
- package/docs/classes/PriorityQueue.html +733 -0
- package/docs/classes/Queue.html +370 -0
- package/docs/classes/RBTree.html +150 -0
- package/docs/classes/SegmentTree.html +345 -0
- package/docs/classes/SegmentTreeNode.html +418 -0
- package/docs/classes/SinglyLinkedList.html +1105 -0
- package/docs/classes/SinglyLinkedListNode.html +375 -0
- package/docs/classes/SplayTree.html +150 -0
- package/docs/classes/Stack.html +346 -0
- package/docs/classes/TreeMultiSet.html +2036 -0
- package/docs/classes/TreeNode.html +236 -0
- package/docs/classes/Trie.html +350 -0
- package/docs/classes/TrieNode.html +258 -0
- package/docs/classes/TwoThreeTree.html +150 -0
- package/docs/classes/UndirectedEdge.html +313 -0
- package/docs/classes/UndirectedGraph.html +1080 -0
- package/docs/classes/UndirectedVertex.html +226 -0
- package/docs/classes/Vector2D.html +783 -0
- package/docs/enums/CP.html +159 -0
- package/docs/enums/FamilyPosition.html +159 -0
- package/docs/enums/LoopType.html +160 -0
- package/docs/index.html +494 -0
- package/docs/interfaces/AVLTreeDeleted.html +161 -0
- package/docs/interfaces/BinaryTreeNodeObj.html +168 -0
- package/docs/interfaces/HeapOptions.html +167 -0
- package/docs/interfaces/IDirectedGraph.html +243 -0
- package/docs/interfaces/IGraph.html +427 -0
- package/docs/interfaces/NavigatorParams.html +197 -0
- package/docs/interfaces/PriorityQueueOptions.html +168 -0
- package/docs/modules.html +218 -0
- package/docs/types/BSTComparator.html +140 -0
- package/docs/types/BSTDeletedResult.html +137 -0
- package/docs/types/BinaryTreeDeleted.html +137 -0
- package/docs/types/BinaryTreeNodeId.html +125 -0
- package/docs/types/BinaryTreeNodePropertyName.html +125 -0
- package/docs/types/DFSOrderPattern.html +125 -0
- package/docs/types/DijkstraResult.html +145 -0
- package/docs/types/Direction.html +125 -0
- package/docs/types/DoublyLinkedListGetBy.html +125 -0
- package/docs/types/NodeOrPropertyName.html +125 -0
- package/docs/types/PriorityQueueComparator.html +145 -0
- package/docs/types/PriorityQueueDFSOrderPattern.html +125 -0
- package/docs/types/ResultByProperty.html +130 -0
- package/docs/types/ResultsByProperty.html +130 -0
- package/docs/types/SegmentTreeNodeVal.html +125 -0
- package/docs/types/SpecifyOptional.html +132 -0
- package/docs/types/Thunk.html +133 -0
- package/docs/types/ToThunkFn.html +133 -0
- package/docs/types/TopologicalStatus.html +125 -0
- package/docs/types/TreeMultiSetDeletedResult.html +137 -0
- package/docs/types/TrlAsyncFn.html +138 -0
- package/docs/types/TrlFn.html +138 -0
- package/docs/types/Turning.html +125 -0
- package/docs/types/VertexId.html +125 -0
- package/{tests/unit/data-structures/binary-tree → notes}/bst.test.ts +11 -15
- package/notes/note.md +23 -0
- package/package.json +2 -4
- package/.idea/data-structure-typed.iml +0 -14
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/src/assets/complexities-diff.jpg +0 -0
- package/src/assets/data-structure-complexities.jpg +0 -0
- package/src/assets/logo.png +0 -0
- package/src/data-structures/binary-tree/aa-tree.ts +0 -3
- package/src/data-structures/binary-tree/avl-tree.ts +0 -293
- package/src/data-structures/binary-tree/b-tree.ts +0 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -69
- package/src/data-structures/binary-tree/binary-tree.ts +0 -1485
- package/src/data-structures/binary-tree/bst.ts +0 -497
- package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/src/data-structures/binary-tree/index.ts +0 -11
- package/src/data-structures/binary-tree/rb-tree.ts +0 -3
- package/src/data-structures/binary-tree/segment-tree.ts +0 -248
- package/src/data-structures/binary-tree/splay-tree.ts +0 -3
- package/src/data-structures/binary-tree/tree-multiset.ts +0 -53
- package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
- package/src/data-structures/diagrams/README.md +0 -5
- package/src/data-structures/graph/abstract-graph.ts +0 -956
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/src/data-structures/graph/diagrams/mst.jpg +0 -0
- package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
- package/src/data-structures/graph/directed-graph.ts +0 -424
- package/src/data-structures/graph/index.ts +0 -3
- package/src/data-structures/graph/undirected-graph.ts +0 -254
- package/src/data-structures/hash/coordinate-map.ts +0 -71
- package/src/data-structures/hash/coordinate-set.ts +0 -60
- package/src/data-structures/hash/hash-table.ts +0 -1
- package/src/data-structures/hash/index.ts +0 -6
- package/src/data-structures/hash/pair.ts +0 -1
- package/src/data-structures/hash/tree-map.ts +0 -1
- package/src/data-structures/hash/tree-set.ts +0 -1
- package/src/data-structures/heap/heap.ts +0 -156
- package/src/data-structures/heap/index.ts +0 -3
- package/src/data-structures/heap/max-heap.ts +0 -31
- package/src/data-structures/heap/min-heap.ts +0 -34
- package/src/data-structures/index.ts +0 -13
- package/src/data-structures/linked-list/doubly-linked-list.ts +0 -351
- package/src/data-structures/linked-list/index.ts +0 -2
- package/src/data-structures/linked-list/singly-linked-list.ts +0 -748
- package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
- package/src/data-structures/matrix/index.ts +0 -4
- package/src/data-structures/matrix/matrix.ts +0 -27
- package/src/data-structures/matrix/matrix2d.ts +0 -208
- package/src/data-structures/matrix/navigator.ts +0 -122
- package/src/data-structures/matrix/vector2d.ts +0 -316
- package/src/data-structures/priority-queue/index.ts +0 -3
- package/src/data-structures/priority-queue/max-priority-queue.ts +0 -24
- package/src/data-structures/priority-queue/min-priority-queue.ts +0 -24
- package/src/data-structures/priority-queue/priority-queue.ts +0 -346
- package/src/data-structures/queue/deque.ts +0 -241
- package/src/data-structures/queue/index.ts +0 -2
- package/src/data-structures/queue/queue.ts +0 -120
- package/src/data-structures/stack/index.ts +0 -1
- package/src/data-structures/stack/stack.ts +0 -98
- package/src/data-structures/trie/index.ts +0 -1
- package/src/data-structures/trie/trie.ts +0 -225
- package/src/data-structures/types/abstract-graph.ts +0 -51
- package/src/data-structures/types/avl-tree.ts +0 -6
- package/src/data-structures/types/binary-tree.ts +0 -15
- package/src/data-structures/types/bst.ts +0 -5
- package/src/data-structures/types/directed-graph.ts +0 -18
- package/src/data-structures/types/doubly-linked-list.ts +0 -1
- package/src/data-structures/types/heap.ts +0 -8
- package/src/data-structures/types/index.ts +0 -13
- package/src/data-structures/types/navigator.ts +0 -13
- package/src/data-structures/types/priority-queue.ts +0 -9
- package/src/data-structures/types/segment-tree.ts +0 -1
- package/src/data-structures/types/singly-linked-list.ts +0 -1
- package/src/data-structures/types/tree-multiset.ts +0 -3
- package/src/index.ts +0 -1
- package/src/utils/index.ts +0 -2
- package/src/utils/types/index.ts +0 -1
- package/src/utils/types/utils.ts +0 -176
- package/src/utils/utils.ts +0 -290
- package/tests/unit/data-structures/graph/abstract-graph.ts +0 -0
- package/tests/unit/data-structures/graph/directed-graph.test.ts +0 -495
- package/tests/unit/data-structures/graph/index.ts +0 -3
- package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
package/src/utils/types/utils.ts
DELETED
|
@@ -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';
|
package/src/utils/utils.ts
DELETED
|
@@ -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
|
-
}
|
|
File without changes
|