data-structure-typed 0.8.6

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 (166) hide show
  1. package/.idea/data-structure-typed.iml +12 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/vcs.xml +6 -0
  4. package/README.md +2 -0
  5. package/dist/data-structures/binary-tree/aa-tree.js +6 -0
  6. package/dist/data-structures/binary-tree/avl-tree.js +231 -0
  7. package/dist/data-structures/binary-tree/b-tree.js +6 -0
  8. package/dist/data-structures/binary-tree/binary-indexed-tree.js +31 -0
  9. package/dist/data-structures/binary-tree/binary-tree.js +992 -0
  10. package/dist/data-structures/binary-tree/bst.js +431 -0
  11. package/dist/data-structures/binary-tree/index.js +20 -0
  12. package/dist/data-structures/binary-tree/rb-tree.js +6 -0
  13. package/dist/data-structures/binary-tree/segment-tree.js +151 -0
  14. package/dist/data-structures/binary-tree/splay-tree.js +6 -0
  15. package/dist/data-structures/binary-tree/tree-multiset.js +16 -0
  16. package/dist/data-structures/binary-tree/two-three-tree.js +6 -0
  17. package/dist/data-structures/graph/abstract-graph.js +648 -0
  18. package/dist/data-structures/graph/directed-graph.js +268 -0
  19. package/dist/data-structures/graph/index.js +19 -0
  20. package/dist/data-structures/graph/undirected-graph.js +142 -0
  21. package/dist/data-structures/hash/coordinate-map.js +24 -0
  22. package/dist/data-structures/hash/coordinate-set.js +21 -0
  23. package/dist/data-structures/hash/hash-table.js +2 -0
  24. package/dist/data-structures/hash/index.js +17 -0
  25. package/dist/data-structures/hash/pair.js +2 -0
  26. package/dist/data-structures/hash/tree-map.js +2 -0
  27. package/dist/data-structures/hash/tree-set.js +2 -0
  28. package/dist/data-structures/heap/heap.js +114 -0
  29. package/dist/data-structures/heap/index.js +19 -0
  30. package/dist/data-structures/heap/max-heap.js +22 -0
  31. package/dist/data-structures/heap/min-heap.js +22 -0
  32. package/dist/data-structures/index.js +25 -0
  33. package/dist/data-structures/linked-list/doubly-linked-list.js +259 -0
  34. package/dist/data-structures/linked-list/index.js +18 -0
  35. package/dist/data-structures/linked-list/singly-linked-list.js +660 -0
  36. package/dist/data-structures/linked-list/skip-linked-list.js +2 -0
  37. package/dist/data-structures/matrix/index.js +19 -0
  38. package/dist/data-structures/matrix/matrix.js +14 -0
  39. package/dist/data-structures/matrix/matrix2d.js +119 -0
  40. package/dist/data-structures/matrix/navigator.js +78 -0
  41. package/dist/data-structures/matrix/vector2d.js +161 -0
  42. package/dist/data-structures/priority-queue/index.js +19 -0
  43. package/dist/data-structures/priority-queue/max-priority-queue.js +15 -0
  44. package/dist/data-structures/priority-queue/min-priority-queue.js +15 -0
  45. package/dist/data-structures/priority-queue/priority-queue.js +174 -0
  46. package/dist/data-structures/queue/deque.js +132 -0
  47. package/dist/data-structures/queue/index.js +17 -0
  48. package/dist/data-structures/queue/queue.js +113 -0
  49. package/dist/data-structures/stack/index.js +17 -0
  50. package/dist/data-structures/stack/stack.js +97 -0
  51. package/dist/data-structures/trampoline.js +52 -0
  52. package/dist/data-structures/trie/index.js +17 -0
  53. package/dist/data-structures/trie/trie.js +141 -0
  54. package/dist/index.js +17 -0
  55. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +2 -0
  56. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +21 -0
  57. package/dist/types/data-structures/binary-tree/b-tree.d.ts +2 -0
  58. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +8 -0
  59. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +140 -0
  60. package/dist/types/data-structures/binary-tree/bst.d.ts +32 -0
  61. package/dist/types/data-structures/binary-tree/index.d.ts +4 -0
  62. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -0
  63. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +33 -0
  64. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +2 -0
  65. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +11 -0
  66. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +2 -0
  67. package/dist/types/data-structures/graph/abstract-graph.d.ts +126 -0
  68. package/dist/types/data-structures/graph/directed-graph.d.ts +51 -0
  69. package/dist/types/data-structures/graph/index.d.ts +3 -0
  70. package/dist/types/data-structures/graph/undirected-graph.d.ts +24 -0
  71. package/dist/types/data-structures/hash/coordinate-map.d.ts +8 -0
  72. package/dist/types/data-structures/hash/coordinate-set.d.ts +7 -0
  73. package/dist/types/data-structures/hash/hash-table.d.ts +1 -0
  74. package/dist/types/data-structures/hash/index.d.ts +1 -0
  75. package/dist/types/data-structures/hash/pair.d.ts +1 -0
  76. package/dist/types/data-structures/hash/tree-map.d.ts +1 -0
  77. package/dist/types/data-structures/hash/tree-set.d.ts +1 -0
  78. package/dist/types/data-structures/heap/heap.d.ts +72 -0
  79. package/dist/types/data-structures/heap/index.d.ts +3 -0
  80. package/dist/types/data-structures/heap/max-heap.d.ts +14 -0
  81. package/dist/types/data-structures/heap/min-heap.d.ts +14 -0
  82. package/dist/types/data-structures/index.d.ts +9 -0
  83. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +59 -0
  84. package/dist/types/data-structures/linked-list/index.d.ts +2 -0
  85. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +358 -0
  86. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
  87. package/dist/types/data-structures/matrix/index.d.ts +3 -0
  88. package/dist/types/data-structures/matrix/matrix.d.ts +9 -0
  89. package/dist/types/data-structures/matrix/matrix2d.d.ts +25 -0
  90. package/dist/types/data-structures/matrix/navigator.d.ts +31 -0
  91. package/dist/types/data-structures/matrix/vector2d.d.ts +74 -0
  92. package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
  93. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +4 -0
  94. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +4 -0
  95. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +36 -0
  96. package/dist/types/data-structures/queue/deque.d.ts +37 -0
  97. package/dist/types/data-structures/queue/index.d.ts +1 -0
  98. package/dist/types/data-structures/queue/queue.d.ts +76 -0
  99. package/dist/types/data-structures/stack/index.d.ts +1 -0
  100. package/dist/types/data-structures/stack/stack.d.ts +69 -0
  101. package/dist/types/data-structures/trampoline.d.ts +25 -0
  102. package/dist/types/data-structures/trie/index.d.ts +1 -0
  103. package/dist/types/data-structures/trie/trie.d.ts +28 -0
  104. package/dist/types/index.d.ts +1 -0
  105. package/dist/types/index.js +17 -0
  106. package/dist/types/types/index.d.ts +1 -0
  107. package/dist/types/types/utils.d.ts +46 -0
  108. package/dist/types/utils.d.ts +122 -0
  109. package/dist/types/utils.js +53 -0
  110. package/dist/utils.js +569 -0
  111. package/package.json +75 -0
  112. package/src/data-structures/binary-tree/aa-tree.ts +3 -0
  113. package/src/data-structures/binary-tree/avl-tree.ts +232 -0
  114. package/src/data-structures/binary-tree/b-tree.ts +3 -0
  115. package/src/data-structures/binary-tree/binary-indexed-tree.ts +33 -0
  116. package/src/data-structures/binary-tree/binary-tree.ts +1088 -0
  117. package/src/data-structures/binary-tree/bst.ts +404 -0
  118. package/src/data-structures/binary-tree/index.ts +4 -0
  119. package/src/data-structures/binary-tree/rb-tree.ts +3 -0
  120. package/src/data-structures/binary-tree/segment-tree.ts +164 -0
  121. package/src/data-structures/binary-tree/splay-tree.ts +3 -0
  122. package/src/data-structures/binary-tree/tree-multiset.ts +21 -0
  123. package/src/data-structures/binary-tree/two-three-tree.ts +3 -0
  124. package/src/data-structures/graph/abstract-graph.ts +789 -0
  125. package/src/data-structures/graph/directed-graph.ts +322 -0
  126. package/src/data-structures/graph/index.ts +3 -0
  127. package/src/data-structures/graph/undirected-graph.ts +154 -0
  128. package/src/data-structures/hash/coordinate-map.ts +24 -0
  129. package/src/data-structures/hash/coordinate-set.ts +20 -0
  130. package/src/data-structures/hash/hash-table.ts +1 -0
  131. package/src/data-structures/hash/index.ts +1 -0
  132. package/src/data-structures/hash/pair.ts +1 -0
  133. package/src/data-structures/hash/tree-map.ts +1 -0
  134. package/src/data-structures/hash/tree-set.ts +1 -0
  135. package/src/data-structures/heap/heap.ts +136 -0
  136. package/src/data-structures/heap/index.ts +3 -0
  137. package/src/data-structures/heap/max-heap.ts +22 -0
  138. package/src/data-structures/heap/min-heap.ts +24 -0
  139. package/src/data-structures/index.ts +10 -0
  140. package/src/data-structures/linked-list/doubly-linked-list.ts +258 -0
  141. package/src/data-structures/linked-list/index.ts +2 -0
  142. package/src/data-structures/linked-list/singly-linked-list.ts +750 -0
  143. package/src/data-structures/linked-list/skip-linked-list.ts +1 -0
  144. package/src/data-structures/matrix/index.ts +3 -0
  145. package/src/data-structures/matrix/matrix.ts +13 -0
  146. package/src/data-structures/matrix/matrix2d.ts +125 -0
  147. package/src/data-structures/matrix/navigator.ts +99 -0
  148. package/src/data-structures/matrix/vector2d.ts +189 -0
  149. package/src/data-structures/priority-queue/index.ts +3 -0
  150. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -0
  151. package/src/data-structures/priority-queue/min-priority-queue.ts +12 -0
  152. package/src/data-structures/priority-queue/priority-queue.ts +208 -0
  153. package/src/data-structures/queue/deque.ts +139 -0
  154. package/src/data-structures/queue/index.ts +1 -0
  155. package/src/data-structures/queue/queue.ts +123 -0
  156. package/src/data-structures/stack/index.ts +1 -0
  157. package/src/data-structures/stack/stack.ts +104 -0
  158. package/src/data-structures/trampoline.ts +91 -0
  159. package/src/data-structures/trie/index.ts +1 -0
  160. package/src/data-structures/trie/trie.ts +153 -0
  161. package/src/index.ts +1 -0
  162. package/src/types/index.ts +1 -0
  163. package/src/types/patches/index.d.ts +0 -0
  164. package/src/types/utils.ts +158 -0
  165. package/src/utils.ts +605 -0
  166. package/tsconfig.json +52 -0
package/dist/utils.js ADDED
@@ -0,0 +1,569 @@
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;
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "data-structure-typed",
3
+ "version": "0.8.6",
4
+ "description": "Hash (CoordinateSet, CoordinateMap) Heap (MaxHeap, MinHeap) Binary Tree (AVL Tree, Binary Indexed Tree, Binary Search Tree, Segment Tree, Tree Multiset) Graph (Directed Graph, Undirected Graph) Linked List (Singly Linked List, Doubly Linked List) Matrix Priority Queue (Max Priority Queue, Min Priority Queue) Queue (Queue, Dequeue) Stack Trie",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/zrwusa/data-structure-typed.git"
12
+ },
13
+ "keywords": [
14
+ "Hash",
15
+ "CoordinateSet",
16
+ "CoordinateMap",
17
+ "Heap",
18
+ "MaxHeap",
19
+ "MinHeap",
20
+ "Binary",
21
+ "Tree",
22
+ "AVL",
23
+ "Tree",
24
+ "Binary",
25
+ "Indexed",
26
+ "Tree",
27
+ "Binary",
28
+ "Search",
29
+ "Tree",
30
+ "Segment",
31
+ "Tree",
32
+ "Tree",
33
+ "Multiset",
34
+ "Graph",
35
+ "Directed",
36
+ "Graph",
37
+ "Undirected",
38
+ "Graph",
39
+ "Linked",
40
+ "List",
41
+ "Singly",
42
+ "Linked",
43
+ "List",
44
+ "Doubly",
45
+ "Linked",
46
+ "List",
47
+ "Matrix",
48
+ "Priority",
49
+ "Queue",
50
+ "Max",
51
+ "Priority",
52
+ "Queue",
53
+ "Min",
54
+ "Priority",
55
+ "Queue",
56
+ "Queue",
57
+ "Queue",
58
+ "Dequeue",
59
+ "Stack",
60
+ "Trie"
61
+ ],
62
+ "author": "Tyler Zeng",
63
+ "license": "ISC",
64
+ "bugs": {
65
+ "url": "https://github.com/zrwusa/data-structure-ts/issues"
66
+ },
67
+ "homepage": "https://github.com/zrwusa/data-structure-ts#readme",
68
+ "devDependencies": {
69
+ "@types/lodash": "^4.14.178",
70
+ "typescript": "^4.6.2"
71
+ },
72
+ "dependencies": {
73
+ "lodash": "^4.17.21"
74
+ }
75
+ }
@@ -0,0 +1,3 @@
1
+ export class AaTree {
2
+
3
+ }