data-structure-typed 0.8.18 → 1.12.9

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 (287) hide show
  1. package/.dependency-cruiser.js +449 -0
  2. package/.idea/data-structure-typed.iml +2 -0
  3. package/.idea/modules.xml +1 -1
  4. package/README.md +298 -2
  5. package/dist/data-structures/binary-tree/aa-tree.js +5 -2
  6. package/dist/data-structures/binary-tree/avl-tree.d.ts +58 -5
  7. package/dist/data-structures/binary-tree/avl-tree.js +150 -46
  8. package/dist/data-structures/binary-tree/b-tree.js +5 -2
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +28 -1
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +41 -13
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +230 -36
  12. package/dist/data-structures/binary-tree/binary-tree.js +747 -369
  13. package/dist/data-structures/binary-tree/bst.d.ts +20 -8
  14. package/dist/data-structures/binary-tree/bst.js +164 -107
  15. package/dist/data-structures/binary-tree/rb-tree.js +5 -2
  16. package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -3
  17. package/dist/data-structures/binary-tree/segment-tree.js +95 -61
  18. package/dist/data-structures/binary-tree/splay-tree.js +5 -2
  19. package/dist/data-structures/binary-tree/tree-multiset.d.ts +5 -5
  20. package/dist/data-structures/binary-tree/tree-multiset.js +35 -11
  21. package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
  22. package/dist/data-structures/graph/abstract-graph.d.ts +168 -46
  23. package/dist/data-structures/graph/abstract-graph.js +712 -323
  24. package/dist/data-structures/graph/directed-graph.d.ts +114 -12
  25. package/dist/data-structures/graph/directed-graph.js +372 -128
  26. package/dist/data-structures/graph/undirected-graph.d.ts +67 -3
  27. package/dist/data-structures/graph/undirected-graph.js +233 -81
  28. package/dist/data-structures/hash/coordinate-map.d.ts +33 -1
  29. package/dist/data-structures/hash/coordinate-map.js +70 -20
  30. package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
  31. package/dist/data-structures/hash/coordinate-set.js +58 -15
  32. package/dist/data-structures/hash/index.d.ts +5 -0
  33. package/dist/data-structures/hash/index.js +5 -0
  34. package/dist/data-structures/heap/heap.d.ts +26 -37
  35. package/dist/data-structures/heap/heap.js +56 -60
  36. package/dist/data-structures/heap/max-heap.d.ts +8 -2
  37. package/dist/data-structures/heap/max-heap.js +32 -9
  38. package/dist/data-structures/heap/min-heap.d.ts +9 -2
  39. package/dist/data-structures/heap/min-heap.js +33 -9
  40. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -7
  41. package/dist/data-structures/linked-list/doubly-linked-list.js +101 -61
  42. package/dist/data-structures/linked-list/singly-linked-list.d.ts +18 -19
  43. package/dist/data-structures/linked-list/singly-linked-list.js +312 -174
  44. package/dist/data-structures/matrix/matrix.d.ts +9 -0
  45. package/dist/data-structures/matrix/matrix.js +19 -7
  46. package/dist/data-structures/matrix/matrix2d.d.ts +84 -4
  47. package/dist/data-structures/matrix/matrix2d.js +158 -61
  48. package/dist/data-structures/matrix/navigator.d.ts +34 -16
  49. package/dist/data-structures/matrix/navigator.js +65 -18
  50. package/dist/data-structures/matrix/vector2d.d.ts +153 -29
  51. package/dist/data-structures/matrix/vector2d.js +249 -102
  52. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +11 -2
  53. package/dist/data-structures/priority-queue/max-priority-queue.js +33 -8
  54. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -2
  55. package/dist/data-structures/priority-queue/min-priority-queue.js +33 -8
  56. package/dist/data-structures/priority-queue/priority-queue.d.ts +145 -21
  57. package/dist/data-structures/priority-queue/priority-queue.js +285 -116
  58. package/dist/data-structures/queue/deque.d.ts +69 -0
  59. package/dist/data-structures/queue/deque.js +151 -56
  60. package/dist/data-structures/queue/queue.d.ts +34 -37
  61. package/dist/data-structures/queue/queue.js +59 -61
  62. package/dist/data-structures/stack/stack.d.ts +29 -35
  63. package/dist/data-structures/stack/stack.js +51 -56
  64. package/dist/data-structures/trie/trie.d.ts +36 -6
  65. package/dist/data-structures/trie/trie.js +256 -83
  66. package/dist/data-structures/types/abstract-graph.d.ts +29 -0
  67. package/dist/data-structures/types/abstract-graph.js +2 -0
  68. package/dist/data-structures/types/avl-tree.d.ts +5 -0
  69. package/dist/data-structures/types/avl-tree.js +2 -0
  70. package/dist/data-structures/types/binary-tree.d.ts +16 -0
  71. package/dist/data-structures/types/binary-tree.js +2 -0
  72. package/dist/data-structures/types/bst.d.ts +7 -0
  73. package/dist/data-structures/types/bst.js +2 -0
  74. package/dist/data-structures/types/directed-graph.d.ts +10 -0
  75. package/dist/data-structures/types/directed-graph.js +2 -0
  76. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
  77. package/dist/data-structures/types/doubly-linked-list.js +2 -0
  78. package/dist/data-structures/types/heap.d.ts +7 -0
  79. package/dist/data-structures/types/heap.js +2 -0
  80. package/dist/data-structures/types/index.d.ts +13 -0
  81. package/dist/data-structures/types/index.js +29 -0
  82. package/dist/data-structures/types/navigator.d.ts +14 -0
  83. package/dist/data-structures/types/navigator.js +2 -0
  84. package/dist/data-structures/types/priority-queue.d.ts +7 -0
  85. package/dist/data-structures/types/priority-queue.js +2 -0
  86. package/dist/data-structures/types/segment-tree.d.ts +1 -0
  87. package/dist/data-structures/types/segment-tree.js +2 -0
  88. package/dist/data-structures/types/singly-linked-list.js +2 -0
  89. package/dist/data-structures/types/tree-multiset.d.ts +5 -0
  90. package/dist/data-structures/types/tree-multiset.js +2 -0
  91. package/dist/utils/trampoline.d.ts +14 -0
  92. package/dist/utils/trampoline.js +130 -0
  93. package/dist/utils/types/index.js +17 -0
  94. package/dist/{types → utils}/types/utils.d.ts +15 -1
  95. package/dist/{types → utils/types}/utils.js +21 -19
  96. package/dist/{utils.d.ts → utils/utils.d.ts} +5 -22
  97. package/dist/utils/utils.js +651 -0
  98. package/docs/.nojekyll +1 -0
  99. package/docs/assets/highlight.css +85 -0
  100. package/docs/assets/main.js +58 -0
  101. package/docs/assets/search.js +1 -0
  102. package/docs/assets/style.css +1367 -0
  103. package/docs/classes/AVLTree.html +2046 -0
  104. package/docs/classes/AVLTreeNode.html +423 -0
  105. package/docs/classes/AaTree.html +117 -0
  106. package/docs/classes/AbstractEdge.html +198 -0
  107. package/docs/classes/AbstractGraph.html +891 -0
  108. package/docs/classes/AbstractVertex.html +164 -0
  109. package/docs/classes/ArrayDeque.html +384 -0
  110. package/docs/classes/BST.html +1893 -0
  111. package/docs/classes/BSTNode.html +425 -0
  112. package/docs/classes/BTree.html +117 -0
  113. package/docs/classes/BinaryIndexedTree.html +244 -0
  114. package/docs/classes/BinaryTree.html +1754 -0
  115. package/docs/classes/BinaryTreeNode.html +396 -0
  116. package/docs/classes/Character.html +165 -0
  117. package/docs/classes/CoordinateMap.html +394 -0
  118. package/docs/classes/CoordinateSet.html +355 -0
  119. package/docs/classes/Deque.html +617 -0
  120. package/docs/classes/DirectedEdge.html +247 -0
  121. package/docs/classes/DirectedGraph.html +1207 -0
  122. package/docs/classes/DirectedVertex.html +154 -0
  123. package/docs/classes/DoublyLinkedList.html +619 -0
  124. package/docs/classes/DoublyLinkedListNode.html +160 -0
  125. package/docs/classes/Heap.html +315 -0
  126. package/docs/classes/Matrix2D.html +447 -0
  127. package/docs/classes/MatrixNTI2D.html +181 -0
  128. package/docs/classes/MaxHeap.html +325 -0
  129. package/docs/classes/MaxPriorityQueue.html +668 -0
  130. package/docs/classes/MinHeap.html +326 -0
  131. package/docs/classes/MinPriorityQueue.html +668 -0
  132. package/docs/classes/Navigator.html +285 -0
  133. package/docs/classes/ObjectDeque.html +289 -0
  134. package/docs/classes/PriorityQueue.html +643 -0
  135. package/docs/classes/Queue.html +337 -0
  136. package/docs/classes/RBTree.html +117 -0
  137. package/docs/classes/SegmentTree.html +234 -0
  138. package/docs/classes/SegmentTreeNode.html +302 -0
  139. package/docs/classes/SinglyLinkedList.html +1035 -0
  140. package/docs/classes/SinglyLinkedListNode.html +304 -0
  141. package/docs/classes/SplayTree.html +117 -0
  142. package/docs/classes/Stack.html +313 -0
  143. package/docs/classes/TreeMultiSet.html +1897 -0
  144. package/docs/classes/Trie.html +317 -0
  145. package/docs/classes/TrieNode.html +221 -0
  146. package/docs/classes/TwoThreeTree.html +117 -0
  147. package/docs/classes/UndirectedEdge.html +220 -0
  148. package/docs/classes/UndirectedGraph.html +1006 -0
  149. package/docs/classes/UndirectedVertex.html +154 -0
  150. package/docs/classes/Vector2D.html +746 -0
  151. package/docs/enums/CP.html +126 -0
  152. package/docs/enums/FamilyPosition.html +126 -0
  153. package/docs/enums/LoopType.html +119 -0
  154. package/docs/index.html +288 -0
  155. package/docs/modules.html +146 -0
  156. package/jest.config.js +5 -0
  157. package/package.json +33 -47
  158. package/rename_clear_files.sh +29 -0
  159. package/src/assets/complexities-diff.jpg +0 -0
  160. package/src/assets/data-structure-complexities.jpg +0 -0
  161. package/src/data-structures/binary-tree/avl-tree.ts +58 -6
  162. package/src/data-structures/binary-tree/binary-indexed-tree.ts +31 -4
  163. package/src/data-structures/binary-tree/binary-tree.ts +460 -145
  164. package/src/data-structures/binary-tree/bst.ts +31 -25
  165. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  166. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  167. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  168. package/src/data-structures/binary-tree/segment-tree.ts +25 -12
  169. package/src/data-structures/binary-tree/tree-multiset.ts +5 -4
  170. package/src/data-structures/diagrams/README.md +5 -0
  171. package/src/data-structures/graph/abstract-graph.ts +224 -108
  172. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  173. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  174. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  175. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  176. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  177. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  178. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  179. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  180. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  181. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  182. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  183. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  184. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  185. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  186. package/src/data-structures/graph/directed-graph.ts +132 -26
  187. package/src/data-structures/graph/undirected-graph.ts +78 -11
  188. package/src/data-structures/hash/coordinate-map.ts +33 -1
  189. package/src/data-structures/hash/coordinate-set.ts +25 -0
  190. package/src/data-structures/hash/index.ts +5 -0
  191. package/src/data-structures/heap/heap.ts +27 -41
  192. package/src/data-structures/heap/max-heap.ts +8 -2
  193. package/src/data-structures/heap/min-heap.ts +9 -2
  194. package/src/data-structures/linked-list/doubly-linked-list.ts +50 -17
  195. package/src/data-structures/linked-list/singly-linked-list.ts +56 -39
  196. package/src/data-structures/matrix/matrix.ts +11 -0
  197. package/src/data-structures/matrix/matrix2d.ts +90 -10
  198. package/src/data-structures/matrix/navigator.ts +34 -14
  199. package/src/data-structures/matrix/vector2d.ts +187 -63
  200. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -3
  201. package/src/data-structures/priority-queue/min-priority-queue.ts +12 -3
  202. package/src/data-structures/priority-queue/priority-queue.ts +200 -78
  203. package/src/data-structures/queue/deque.ts +71 -2
  204. package/src/data-structures/queue/queue.ts +37 -40
  205. package/src/data-structures/stack/stack.ts +32 -38
  206. package/src/data-structures/trie/trie.ts +83 -14
  207. package/src/data-structures/types/abstract-graph.ts +51 -0
  208. package/src/data-structures/types/avl-tree.ts +6 -0
  209. package/src/data-structures/types/binary-tree.ts +15 -0
  210. package/src/data-structures/types/bst.ts +5 -0
  211. package/src/data-structures/types/directed-graph.ts +18 -0
  212. package/src/data-structures/types/doubly-linked-list.ts +1 -0
  213. package/src/data-structures/types/heap.ts +8 -0
  214. package/src/data-structures/types/index.ts +13 -0
  215. package/src/data-structures/types/navigator.ts +13 -0
  216. package/src/data-structures/types/priority-queue.ts +9 -0
  217. package/src/data-structures/types/segment-tree.ts +1 -0
  218. package/src/data-structures/types/singly-linked-list.ts +1 -0
  219. package/src/data-structures/types/tree-multiset.ts +3 -0
  220. package/src/utils/index.ts +1 -0
  221. package/src/utils/trampoline.ts +51 -0
  222. package/src/utils/types/index.ts +1 -0
  223. package/src/{types → utils/types}/utils.ts +27 -5
  224. package/src/{utils.ts → utils/utils.ts} +41 -131
  225. package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
  226. package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
  227. package/{dist/types/data-structures/graph/index.d.ts → tests/unit/data-structures/graph/index.ts} +1 -1
  228. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
  229. package/tsconfig.json +9 -6
  230. package/dist/data-structures/trampoline.d.ts +0 -25
  231. package/dist/data-structures/trampoline.js +0 -52
  232. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  233. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  234. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  235. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  236. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  237. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  238. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  239. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  240. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  241. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  242. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  243. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  244. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  245. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  246. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  247. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  248. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  249. package/dist/types/data-structures/hash/index.d.ts +0 -1
  250. package/dist/types/data-structures/hash/pair.d.ts +0 -1
  251. package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
  252. package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
  253. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  254. package/dist/types/data-structures/heap/index.d.ts +0 -3
  255. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  256. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  257. package/dist/types/data-structures/index.d.ts +0 -9
  258. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  259. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  260. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  261. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
  262. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  263. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  264. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  265. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  266. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  267. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  268. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  269. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  270. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  271. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  272. package/dist/types/data-structures/queue/index.d.ts +0 -1
  273. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  274. package/dist/types/data-structures/stack/index.d.ts +0 -1
  275. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  276. package/dist/types/data-structures/trampoline.d.ts +0 -25
  277. package/dist/types/data-structures/trie/index.d.ts +0 -1
  278. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  279. package/dist/types/utils.d.ts +0 -46
  280. package/dist/utils.js +0 -569
  281. package/src/data-structures/trampoline.ts +0 -91
  282. package/src/types/index.ts +0 -1
  283. /package/dist/{types/data-structures/hash/hash-table.d.ts → data-structures/types/singly-linked-list.d.ts} +0 -0
  284. /package/dist/{types → utils}/index.d.ts +0 -0
  285. /package/dist/{types → utils}/index.js +0 -0
  286. /package/dist/{types → utils}/types/index.d.ts +0 -0
  287. /package/{src/types/patches/index.d.ts → tests/unit/data-structures/graph/abstract-graph.ts} +0 -0
package/dist/utils.js DELETED
@@ -1,569 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.zip = exports.memo = exports.arrayRemove = exports.timeEnd = exports.timeStart = exports.bunnyConsole = exports.deepAdd = exports.deepReplaceValues = exports.deepRenameKeys = exports.deepRemoveByKey = exports.deepKeysConvert = exports.StringUtil = exports.diffAB = exports.onlyInB = exports.onlyInA = exports.comparerArray = exports.capitalizeFirstLetter = exports.capitalizeWords = exports.randomDate = exports.minuted = exports.keyValueToArray = exports.extractValue = exports.NomicsAPIError = exports.BunnyAPIError = exports.AuthAPIError = exports.wait = exports.WaitManager = exports.addDays = exports.isLeafParent = exports.isSameStructure = exports.reverseColor = exports.isTypeEqual = exports.deepObjectStrictEqual = exports.strictObjectIsEqual = exports.strictEqual = exports.looseEqual = exports.isObject = exports.getValue = exports.incrementId = exports.IncrementId = exports.uuidV4 = exports.randomText = void 0;
16
- const lodash_1 = __importDefault(require("lodash"));
17
- function randomText(length) {
18
- let result = '';
19
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
20
- const charactersLength = characters.length;
21
- for (let i = 0; i < length; i++) {
22
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
23
- }
24
- return result;
25
- }
26
- exports.randomText = randomText;
27
- const uuidV4 = function () {
28
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
29
- const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
30
- return v.toString(16);
31
- });
32
- };
33
- exports.uuidV4 = uuidV4;
34
- class IncrementId {
35
- constructor(prefix) {
36
- this._prefix = prefix ? prefix : '';
37
- this._id = this._prefix + '0';
38
- }
39
- getId() {
40
- const { _id, _prefix } = this;
41
- if (!_id) {
42
- this._id = _prefix + '0';
43
- }
44
- else {
45
- const idNumStr = _id.substr(_prefix.length, _id.length - _prefix.length);
46
- const newIdNum = parseInt(idNumStr, 10) + 1;
47
- this._id = _prefix + newIdNum.toString();
48
- }
49
- return this._id;
50
- }
51
- }
52
- exports.IncrementId = IncrementId;
53
- function incrementId(prefix) {
54
- const _prefix = prefix ? prefix : '';
55
- let _id = _prefix + '0';
56
- return function id() {
57
- const idNumStr = _id.substr(_prefix.length, _id.length - _prefix.length);
58
- const newIdNum = parseInt(idNumStr, 10) + 1;
59
- _id = _prefix + newIdNum.toString();
60
- return _id;
61
- };
62
- }
63
- exports.incrementId = incrementId;
64
- const getValue = (obj, names) => {
65
- return names.map(i => obj[i]);
66
- };
67
- exports.getValue = getValue;
68
- const isObject = (object) => {
69
- return object != null && typeof object === 'object';
70
- };
71
- exports.isObject = isObject;
72
- const looseEqual = (a, b) => {
73
- return a == b;
74
- };
75
- exports.looseEqual = looseEqual;
76
- const strictEqual = (a, b) => {
77
- return a === b;
78
- };
79
- exports.strictEqual = strictEqual;
80
- const strictObjectIsEqual = (a, b) => {
81
- return Object.is(a, b);
82
- };
83
- exports.strictObjectIsEqual = strictObjectIsEqual;
84
- const deepObjectStrictEqual = (object1, object2) => {
85
- const keys1 = Object.keys(object1);
86
- const keys2 = Object.keys(object2);
87
- if (keys1.length !== keys2.length) {
88
- return false;
89
- }
90
- for (const key of keys1) {
91
- const val1 = object1[key];
92
- const val2 = object2[key];
93
- const areObjects = (0, exports.isObject)(val1) && (0, exports.isObject)(val2);
94
- if (areObjects && !(0, exports.deepObjectStrictEqual)(val1, val2) ||
95
- !areObjects && val1 !== val2) {
96
- return false;
97
- }
98
- }
99
- return true;
100
- };
101
- exports.deepObjectStrictEqual = deepObjectStrictEqual;
102
- const isTypeEqual = (obj) => {
103
- const m = obj;
104
- };
105
- exports.isTypeEqual = isTypeEqual;
106
- function reverseColor(oldColor) {
107
- const oldColorTemp = '0x' + oldColor.replace(/#/g, '');
108
- const str = '000000' + (0xFFFFFF - Number(oldColorTemp)).toString(16);
109
- return '#' + str.substring(str.length - 6, str.length);
110
- }
111
- exports.reverseColor = reverseColor;
112
- const isSameStructure = (objA, objB) => {
113
- const objATraversable = objA;
114
- const objBTraversable = objB;
115
- const objAKeys = Object.keys(objATraversable);
116
- const objBKeys = Object.keys(objBTraversable);
117
- let isSame = true;
118
- if (objAKeys.length !== objBKeys.length) {
119
- return isSame = false;
120
- }
121
- else {
122
- objAKeys.forEach((i) => {
123
- if (!objBKeys.includes(i)) {
124
- return isSame = false;
125
- }
126
- });
127
- return isSame;
128
- }
129
- };
130
- exports.isSameStructure = isSameStructure;
131
- const isLeafParent = (obj) => {
132
- let isLeaf = true;
133
- Object.values(obj).forEach(value => {
134
- if (typeof value === 'object' && value instanceof Array) {
135
- value.forEach(item => {
136
- if (typeof item === 'object') {
137
- return false;
138
- }
139
- });
140
- return isLeaf = true;
141
- }
142
- if (!['string', 'boolean', 'number', 'undefined', 'function'].includes(typeof value) && (value !== null)) {
143
- return isLeaf = false;
144
- }
145
- });
146
- return isLeaf;
147
- };
148
- exports.isLeafParent = isLeafParent;
149
- const addDays = (date, days) => {
150
- date.setDate(date.getDate() + days);
151
- return date;
152
- };
153
- exports.addDays = addDays;
154
- class WaitManager {
155
- get time1() {
156
- return this._time1 / this._nXSpeed;
157
- }
158
- get time2() {
159
- return this._time2 / this._nXSpeed;
160
- }
161
- get time3() {
162
- return this._time3 / this._nXSpeed;
163
- }
164
- get time4() {
165
- return this._time4 / this._nXSpeed;
166
- }
167
- get time10() {
168
- return this._time10 / this._nXSpeed;
169
- }
170
- get time20() {
171
- return this._time20 / this._nXSpeed;
172
- }
173
- get time50() {
174
- return this._time30 / this._nXSpeed;
175
- }
176
- get time60() {
177
- return this._time60 / this._nXSpeed;
178
- }
179
- get cusTime() {
180
- return this._cusTime / this._nXSpeed;
181
- }
182
- set cusTime(v) {
183
- this._cusTime = v;
184
- }
185
- constructor(nXSpeed) {
186
- this._time1 = 1000;
187
- this._time2 = 2000;
188
- this._time3 = 3000;
189
- this._time4 = 4000;
190
- this._time10 = 10000;
191
- this._time20 = 20000;
192
- this._time30 = 20000;
193
- this._time60 = 60000;
194
- this._cusTime = 1000;
195
- this._nXSpeed = 1;
196
- if (nXSpeed === undefined)
197
- nXSpeed = 1;
198
- this._nXSpeed = nXSpeed;
199
- }
200
- }
201
- exports.WaitManager = WaitManager;
202
- const wait = (ms, resolveValue) => __awaiter(void 0, void 0, void 0, function* () {
203
- return new Promise((resolve, reject) => {
204
- setTimeout(() => {
205
- const finalResolveValue = resolveValue || true;
206
- resolve(finalResolveValue);
207
- }, ms);
208
- });
209
- });
210
- exports.wait = wait;
211
- class AuthAPIError extends Error {
212
- constructor(serverErrorMessage, serverErrorCode, serverErrorStack) {
213
- super(serverErrorMessage);
214
- if (serverErrorStack) {
215
- this.serverErrorStack = serverErrorStack;
216
- }
217
- if (serverErrorCode) {
218
- this.serverErrorCode = serverErrorCode;
219
- }
220
- this.name = new.target.name;
221
- if (typeof Error.captureStackTrace === 'function') {
222
- Error.captureStackTrace(this, new.target);
223
- }
224
- if (typeof Object.setPrototypeOf === 'function') {
225
- Object.setPrototypeOf(this, new.target.prototype);
226
- }
227
- else {
228
- this.__proto__ = new.target.prototype;
229
- }
230
- }
231
- }
232
- exports.AuthAPIError = AuthAPIError;
233
- class BunnyAPIError extends Error {
234
- constructor(serverErrorMessage, serverErrorCode, serverErrorStack) {
235
- super(serverErrorMessage);
236
- if (serverErrorStack) {
237
- this.serverErrorStack = serverErrorStack;
238
- }
239
- if (serverErrorCode) {
240
- this.serverErrorCode = serverErrorCode;
241
- }
242
- this.name = new.target.name;
243
- if (typeof Error.captureStackTrace === 'function') {
244
- Error.captureStackTrace(this, new.target);
245
- }
246
- if (typeof Object.setPrototypeOf === 'function') {
247
- Object.setPrototypeOf(this, new.target.prototype);
248
- }
249
- else {
250
- this.__proto__ = new.target.prototype;
251
- }
252
- }
253
- }
254
- exports.BunnyAPIError = BunnyAPIError;
255
- class NomicsAPIError extends Error {
256
- constructor(serverErrorMessage, serverErrorCode, serverErrorStack) {
257
- super(serverErrorMessage);
258
- if (serverErrorStack) {
259
- this.serverErrorStack = serverErrorStack;
260
- }
261
- if (serverErrorCode) {
262
- this.serverErrorCode = serverErrorCode;
263
- }
264
- this.name = new.target.name;
265
- if (typeof Error.captureStackTrace === 'function') {
266
- Error.captureStackTrace(this, new.target);
267
- }
268
- if (typeof Object.setPrototypeOf === 'function') {
269
- Object.setPrototypeOf(this, new.target.prototype);
270
- }
271
- else {
272
- this.__proto__ = new.target.prototype;
273
- }
274
- }
275
- }
276
- exports.NomicsAPIError = NomicsAPIError;
277
- function extractValue(data) {
278
- let result = [];
279
- if (data && data.length > 0) {
280
- result = data.map(item => item.value);
281
- }
282
- return result;
283
- }
284
- exports.extractValue = extractValue;
285
- function keyValueToArray(data) {
286
- const itemArray = [];
287
- const keys = Object.keys(data);
288
- for (const i of keys) {
289
- itemArray.push(Object.assign(Object.assign({}, data[i]), { _id: i }));
290
- }
291
- return itemArray;
292
- }
293
- exports.keyValueToArray = keyValueToArray;
294
- function minuted(time) {
295
- const minutes = Math.floor(time / 60000).toString();
296
- const seconds = Math.floor((time % 60000) / 1000).toString().padStart(2, '0');
297
- return `${minutes}:${seconds}`;
298
- }
299
- exports.minuted = minuted;
300
- function randomDate(start, end, specificProbabilityStart, specificProbability) {
301
- if (!start)
302
- start = new Date('1970-1-1');
303
- if (!end)
304
- end = new Date();
305
- if (specificProbabilityStart) {
306
- if (!specificProbability)
307
- specificProbability = 0.5;
308
- if (Math.random() <= specificProbability) {
309
- return new Date(specificProbabilityStart.getTime() + Math.random() * (end.getTime() - specificProbabilityStart.getTime()));
310
- }
311
- }
312
- return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
313
- }
314
- exports.randomDate = randomDate;
315
- const capitalizeWords = (str) => {
316
- return str.replace(/(?:^|\s)\S/g, (a) => a.toUpperCase());
317
- };
318
- exports.capitalizeWords = capitalizeWords;
319
- const capitalizeFirstLetter = (str) => {
320
- return str.charAt(0).toUpperCase() + str.slice(1);
321
- };
322
- exports.capitalizeFirstLetter = capitalizeFirstLetter;
323
- const comparerArray = (otherArray, limitKeys) => {
324
- return function (current) {
325
- return otherArray.filter(function (other) {
326
- if (!limitKeys) {
327
- return lodash_1.default.isEqual(current, other);
328
- }
329
- else {
330
- // TODO
331
- }
332
- }).length == 0;
333
- };
334
- };
335
- exports.comparerArray = comparerArray;
336
- const onlyInA = (a, b) => {
337
- return a.filter((0, exports.comparerArray)(b));
338
- };
339
- exports.onlyInA = onlyInA;
340
- const onlyInB = (a, b) => {
341
- return b.filter((0, exports.comparerArray)(a));
342
- };
343
- exports.onlyInB = onlyInB;
344
- const diffAB = (a, b) => {
345
- return (0, exports.onlyInA)(a, b).concat((0, exports.onlyInB)(a, b));
346
- };
347
- exports.diffAB = diffAB;
348
- class StringUtil {
349
- // camelCase
350
- static toCamelCase(str) {
351
- return lodash_1.default.camelCase(str);
352
- }
353
- // snake_case
354
- static toSnakeCase(str) {
355
- return lodash_1.default.snakeCase(str);
356
- }
357
- // PascalCase
358
- static toPascalCase(str) {
359
- return lodash_1.default.startCase(lodash_1.default.camelCase(str)).replace(/ /g, '');
360
- }
361
- // CONSTANT_CASE
362
- static toConstantCase(str) {
363
- return lodash_1.default.upperCase(str).replace(/ /g, '_');
364
- }
365
- // kebab-case
366
- static toKebabCase(str) {
367
- return lodash_1.default.kebabCase(str);
368
- }
369
- // lowercase
370
- static toLowerCase(str) {
371
- return lodash_1.default.lowerCase(str).replace(/ /g, '');
372
- }
373
- // Title Case
374
- static toTitleCase(str) {
375
- return lodash_1.default.startCase(lodash_1.default.camelCase(str));
376
- }
377
- // Sentence case
378
- static toSentenceCase(str) {
379
- return lodash_1.default.upperFirst(lodash_1.default.lowerCase(str));
380
- }
381
- // path/case
382
- static toPathCase(str) {
383
- return lodash_1.default.lowerCase(str).replace(/ /g, '/');
384
- }
385
- // dot.case
386
- static toDotCase(str) {
387
- return lodash_1.default.lowerCase(str).replace(/ /g, '.');
388
- }
389
- }
390
- exports.StringUtil = StringUtil;
391
- const deepKeysConvert = (obj, toType) => {
392
- const _toType = toType || 'snake';
393
- if (Array.isArray(obj)) {
394
- return obj.map(v => (0, exports.deepKeysConvert)(v, _toType));
395
- }
396
- else if (obj !== null && obj.constructor === Object) {
397
- return Object.keys(obj).reduce((result, key) => {
398
- let newKey = '';
399
- switch (_toType) {
400
- case 'camel':
401
- newKey = StringUtil.toCamelCase(key);
402
- break;
403
- case 'snake':
404
- newKey = StringUtil.toSnakeCase(key);
405
- break;
406
- case 'pascal':
407
- newKey = StringUtil.toPascalCase(key);
408
- break;
409
- case 'constant':
410
- newKey = StringUtil.toConstantCase(key);
411
- break;
412
- case 'kebab':
413
- newKey = StringUtil.toKebabCase(key);
414
- break;
415
- case 'lower':
416
- newKey = StringUtil.toLowerCase(key);
417
- break;
418
- case 'title':
419
- newKey = StringUtil.toTitleCase(key);
420
- break;
421
- case 'sentence':
422
- newKey = StringUtil.toSentenceCase(key);
423
- break;
424
- case 'path':
425
- newKey = StringUtil.toPathCase(key);
426
- break;
427
- case 'dot':
428
- newKey = StringUtil.toDotCase(key);
429
- break;
430
- default:
431
- newKey = StringUtil.toDotCase(key);
432
- break;
433
- }
434
- return Object.assign(Object.assign({}, result), { [newKey]: (0, exports.deepKeysConvert)(obj[key], _toType) });
435
- }, {});
436
- }
437
- return obj;
438
- };
439
- exports.deepKeysConvert = deepKeysConvert;
440
- const deepRemoveByKey = (obj, keysToBeRemoved) => {
441
- const result = lodash_1.default.transform(obj, function (result, value, key) {
442
- if (lodash_1.default.isObject(value)) {
443
- value = (0, exports.deepRemoveByKey)(value, keysToBeRemoved);
444
- }
445
- if (!keysToBeRemoved.includes(key)) {
446
- lodash_1.default.isArray(obj) ? result.push(value) : result[key] = value;
447
- }
448
- });
449
- return result;
450
- };
451
- exports.deepRemoveByKey = deepRemoveByKey;
452
- const deepRenameKeys = (obj, keysMap) => {
453
- return lodash_1.default.transform(obj, function (result, value, key) {
454
- const currentKey = keysMap[key] || key;
455
- result[currentKey] = lodash_1.default.isObject(value) ? (0, exports.deepRenameKeys)(value, keysMap) : value;
456
- });
457
- };
458
- exports.deepRenameKeys = deepRenameKeys;
459
- const deepReplaceValues = (obj, keyReducerMap) => {
460
- const newObject = lodash_1.default.clone(obj);
461
- lodash_1.default.each(obj, (val, key) => {
462
- for (const item in keyReducerMap) {
463
- if (key === item) {
464
- newObject[key] = keyReducerMap[item](newObject);
465
- }
466
- else if (typeof (val) === 'object' || val instanceof Array) {
467
- newObject[key] = (0, exports.deepReplaceValues)(val, keyReducerMap);
468
- }
469
- }
470
- });
471
- return newObject;
472
- };
473
- exports.deepReplaceValues = deepReplaceValues;
474
- // function getCallStackSize() {
475
- // let count = 0, fn = arguments.callee;
476
- // while ( (fn = fn.caller) ) {
477
- // count++;
478
- // }
479
- // return count;
480
- // }
481
- // TODO determine depth and pass root node as a param through callback
482
- const deepAdd = (obj, keyReducerMap, isItemRootParent) => {
483
- const newObject = lodash_1.default.clone(obj);
484
- if (lodash_1.default.isObject(newObject) && !lodash_1.default.isArray(newObject)) {
485
- for (const item in keyReducerMap) {
486
- newObject[item] = keyReducerMap[item](newObject);
487
- }
488
- }
489
- lodash_1.default.each(obj, (val, key) => {
490
- if (lodash_1.default.isObject(val)) {
491
- for (const item in keyReducerMap) {
492
- // @ts-ignore
493
- newObject[key] = (0, exports.deepAdd)(val, keyReducerMap, isItemRootParent);
494
- }
495
- }
496
- });
497
- return newObject;
498
- };
499
- exports.deepAdd = deepAdd;
500
- const styleString = (color) => `color: ${color}; font-weight: bold`;
501
- const styleHeader = (header) => `%c[${header}]`;
502
- exports.bunnyConsole = {
503
- log: (headerLog = 'bunny', ...args) => {
504
- return console.log(styleHeader(headerLog), styleString('black'), ...args);
505
- },
506
- warn: (headerLog = 'bunny', ...args) => {
507
- return console.warn(styleHeader(headerLog), styleString('orange'), ...args);
508
- },
509
- error: (headerLog = 'bunny', ...args) => {
510
- return console.error(styleHeader(headerLog), styleString('red'), ...args);
511
- }
512
- };
513
- const timeStart = () => {
514
- return performance ? performance.now() : new Date().getTime();
515
- };
516
- exports.timeStart = timeStart;
517
- const timeEnd = (startTime, headerLog, consoleConditionFn) => {
518
- const timeSpent = (performance ? performance.now() : new Date().getTime()) - startTime;
519
- const isPassCondition = consoleConditionFn ? consoleConditionFn(timeSpent) : true;
520
- if (isPassCondition) {
521
- exports.bunnyConsole.log(headerLog ? headerLog : 'time spent', timeSpent.toFixed(2));
522
- }
523
- };
524
- exports.timeEnd = timeEnd;
525
- const arrayRemove = function (array, predicate) {
526
- let i = -1, len = array ? array.length : 0;
527
- const result = [];
528
- while (++i < len) {
529
- const value = array[i];
530
- if (predicate(value, i, array)) {
531
- result.push(value);
532
- Array.prototype.splice.call(array, i--, 1);
533
- len--;
534
- }
535
- }
536
- return result;
537
- };
538
- exports.arrayRemove = arrayRemove;
539
- function memo() {
540
- const cache = {};
541
- // eslint-disable-next-line @typescript-eslint/ban-types
542
- return function (target, propertyKey, descriptor) {
543
- const originalMethod = descriptor.value;
544
- descriptor.value = function (...args) {
545
- const cacheKey = `__cacheKey__${args.toString()}`;
546
- // eslint-disable-next-line no-prototype-builtins
547
- if (!cache.hasOwnProperty(cacheKey)) {
548
- cache[cacheKey] = originalMethod.apply(this, args);
549
- }
550
- return cache[cacheKey];
551
- };
552
- };
553
- }
554
- exports.memo = memo;
555
- function zip(array1, array2, options) {
556
- const zipped = [];
557
- const zippedObjCoords = [];
558
- const { isToObj } = options ? options : { isToObj: false };
559
- for (let i = 0; i < array1.length; i++) {
560
- if (isToObj) {
561
- zippedObjCoords.push({ x: array1[i], y: array2[i] });
562
- }
563
- else {
564
- zipped.push([array1[i], array2[i]]);
565
- }
566
- }
567
- return isToObj ? zippedObjCoords : zipped;
568
- }
569
- exports.zip = zip;
@@ -1,91 +0,0 @@
1
- export type ArgumentTypes<T extends (...args: any[]) => any> =
2
- T extends (...args: infer A) => any
3
- ? A
4
- : never;
5
-
6
- export const THUNK_SYMBOL: unique symbol = Symbol('thunk');
7
-
8
- export interface Thunk<T> extends Function {
9
- __THUNK__: typeof THUNK_SYMBOL;
10
-
11
- (): T;
12
- }
13
-
14
- export type ThunkOrValue<T> = T | Thunk<T>;
15
-
16
- export type UnwrapThunkDeep<T> = {
17
- 0: T extends Thunk<infer U> ? UnwrapThunkDeep<U> : T;
18
- }[
19
- T extends ThunkOrValue<T> ? 0 : never
20
- ];
21
-
22
- export const isThunk = <T>(value: any): value is Thunk<T> => {
23
- return typeof value === 'function' && value.__THUNK__ === THUNK_SYMBOL;
24
- };
25
-
26
- export const toThunk = <R>(fn: () => R): Thunk<R> => {
27
- const thunk = () => fn();
28
- thunk.__THUNK__ = THUNK_SYMBOL;
29
- return thunk;
30
- };
31
- export type UnwrapPromise<T> = T extends Promise<infer U> ? Exclude<U, Promise<T>> : T;
32
-
33
- export type Unbox<T> = UnwrapThunkDeep<UnwrapPromise<T>>;
34
-
35
- export type Cont<A extends any[], R> = (...args: A) => Thunk<Unbox<R>>;
36
-
37
- export interface Trampoline<F extends ((...args: any[]) => any)> {
38
- (...args: ArgumentTypes<F>): Unbox<ReturnType<F>>;
39
-
40
- cont: Cont<ArgumentTypes<F>, ReturnType<F>>;
41
- }
42
-
43
- export interface TrampolineAsync<F extends ((...args: any[]) => any)> {
44
- (...args: ArgumentTypes<F>): Promise<Unbox<ReturnType<F>>>;
45
-
46
- cont: Cont<ArgumentTypes<F>, ReturnType<F>>;
47
- }
48
-
49
- export const trampoline = <F extends ((...args: any[]) => any)>(fn: F): Trampoline<F> => {
50
- const cont = (...args: ArgumentTypes<F>) => toThunk(() => fn(...args));
51
-
52
- return Object.assign(
53
- (...args: ArgumentTypes<F>): Unbox<ReturnType<F>> => {
54
- let result: ThunkOrValue<ReturnType<F>> = fn(...args);
55
-
56
- while (isThunk<ReturnType<F>>(result)) {
57
- result = result();
58
- }
59
-
60
- return result;
61
- },
62
- {cont},
63
- );
64
- };
65
-
66
- export const trampolineAsync = <F extends ((...args: any[]) => any)>(fn: F): TrampolineAsync<F> => {
67
- const cont = (...args: ArgumentTypes<F>) => toThunk(() => fn(...args));
68
-
69
- return Object.assign(
70
- async (...args: ArgumentTypes<F>): Promise<Unbox<ReturnType<F>>> => {
71
- let result: ThunkOrValue<ReturnType<F>> = await fn(...args);
72
-
73
- while (isThunk<ReturnType<F>>(result)) {
74
- result = await result();
75
- }
76
-
77
- return result;
78
- },
79
- {cont},
80
- );
81
- };
82
-
83
-
84
- const factorial = trampoline((n: number, acc: number = 1): ThunkOrValue<number> => {
85
- return n
86
- // Note: calling factorial.cont instead of factorial directly
87
- ? factorial.cont(n - 1, acc * n)
88
- : acc;
89
- });
90
-
91
- // factorial(32768)
@@ -1 +0,0 @@
1
- export * from './utils';
File without changes
File without changes
File without changes