data-structure-typed 0.8.18 → 0.9.16
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/.idea/modules.xml +1 -1
- package/README.md +197 -2
- package/dist/data-structures/binary-tree/aa-tree.js +5 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +1 -5
- package/dist/data-structures/binary-tree/avl-tree.js +93 -46
- package/dist/data-structures/binary-tree/b-tree.js +5 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +14 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +20 -32
- package/dist/data-structures/binary-tree/binary-tree.js +480 -370
- package/dist/data-structures/binary-tree/bst.d.ts +4 -8
- package/dist/data-structures/binary-tree/bst.js +152 -107
- package/dist/data-structures/binary-tree/rb-tree.js +5 -2
- package/dist/data-structures/binary-tree/segment-tree.d.ts +3 -3
- package/dist/data-structures/binary-tree/segment-tree.js +91 -61
- package/dist/data-structures/binary-tree/splay-tree.js +5 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +31 -11
- package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
- package/dist/data-structures/graph/abstract-graph.d.ts +5 -33
- package/dist/data-structures/graph/abstract-graph.js +546 -311
- package/dist/data-structures/graph/directed-graph.d.ts +5 -13
- package/dist/data-structures/graph/directed-graph.js +250 -128
- package/dist/data-structures/graph/undirected-graph.d.ts +4 -3
- package/dist/data-structures/graph/undirected-graph.js +166 -81
- package/dist/data-structures/hash/coordinate-map.d.ts +1 -1
- package/dist/data-structures/hash/coordinate-map.js +38 -20
- package/dist/data-structures/hash/coordinate-set.js +33 -15
- package/dist/data-structures/hash/index.d.ts +5 -0
- package/dist/data-structures/hash/index.js +5 -0
- package/dist/data-structures/heap/heap.d.ts +2 -8
- package/dist/data-structures/heap/heap.js +36 -31
- package/dist/data-structures/heap/max-heap.d.ts +3 -2
- package/dist/data-structures/heap/max-heap.js +27 -9
- package/dist/data-structures/heap/min-heap.d.ts +3 -2
- package/dist/data-structures/heap/min-heap.js +27 -9
- 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 +0 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +56 -53
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +8 -12
- package/dist/data-structures/linked-list/singly-linked-list.js +308 -174
- package/dist/data-structures/matrix/matrix.js +8 -7
- package/dist/data-structures/matrix/matrix2d.d.ts +5 -5
- package/dist/data-structures/matrix/matrix2d.js +80 -63
- package/dist/data-structures/matrix/navigator.d.ts +2 -16
- package/dist/data-structures/matrix/navigator.js +37 -18
- package/dist/data-structures/matrix/vector2d.d.ts +18 -18
- package/dist/data-structures/matrix/vector2d.js +117 -94
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -21
- package/dist/data-structures/priority-queue/priority-queue.js +159 -116
- package/dist/data-structures/queue/deque.js +82 -56
- package/dist/data-structures/queue/queue.d.ts +9 -10
- package/dist/data-structures/queue/queue.js +34 -34
- package/dist/data-structures/stack/stack.d.ts +9 -10
- package/dist/data-structures/stack/stack.js +31 -31
- package/dist/data-structures/trampoline.d.ts +14 -23
- package/dist/data-structures/trampoline.js +103 -25
- package/dist/data-structures/trie/trie.d.ts +13 -3
- package/dist/data-structures/trie/trie.js +234 -80
- package/dist/data-structures/types/abstract-graph.d.ts +29 -0
- package/dist/data-structures/types/abstract-graph.js +2 -0
- package/dist/data-structures/types/avl-tree.d.ts +5 -0
- package/dist/data-structures/types/avl-tree.js +2 -0
- package/dist/data-structures/types/binary-tree.d.ts +16 -0
- package/dist/data-structures/types/binary-tree.js +2 -0
- package/dist/data-structures/types/bst.d.ts +7 -0
- package/dist/data-structures/types/bst.js +2 -0
- package/dist/data-structures/types/directed-graph.d.ts +10 -0
- package/dist/data-structures/types/directed-graph.js +2 -0
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/types/doubly-linked-list.js +2 -0
- package/dist/data-structures/types/heap.d.ts +7 -0
- package/dist/data-structures/types/heap.js +2 -0
- package/dist/data-structures/types/index.d.ts +13 -0
- package/dist/data-structures/types/index.js +29 -0
- package/dist/data-structures/types/navigator.d.ts +14 -0
- package/dist/data-structures/types/navigator.js +2 -0
- package/dist/data-structures/types/priority-queue.d.ts +7 -0
- package/dist/data-structures/types/priority-queue.js +2 -0
- package/dist/data-structures/types/segment-tree.d.ts +1 -0
- package/dist/data-structures/types/segment-tree.js +2 -0
- package/dist/data-structures/types/singly-linked-list.d.ts +5 -0
- package/dist/data-structures/types/singly-linked-list.js +2 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -0
- package/dist/data-structures/types/tree-multiset.js +2 -0
- package/dist/{types → data-structures/types}/utils.d.ts +7 -1
- package/dist/{types → data-structures/types}/utils.js +20 -19
- package/dist/{utils.d.ts → utils/utils.d.ts} +6 -23
- package/dist/utils/utils.js +651 -0
- package/package.json +20 -42
- package/src/data-structures/binary-tree/avl-tree.ts +1 -6
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +4 -4
- package/src/data-structures/binary-tree/binary-tree.ts +184 -139
- package/src/data-structures/binary-tree/bst.ts +15 -24
- 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/segment-tree.ts +20 -12
- package/src/data-structures/binary-tree/tree-multiset.ts +1 -4
- package/src/data-structures/diagrams/README.md +7 -0
- package/src/data-structures/graph/abstract-graph.ts +58 -94
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list.png +0 -0
- package/src/data-structures/graph/diagrams/max-flow.png +0 -0
- package/src/data-structures/graph/diagrams/mst.png +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/directed-graph.ts +12 -28
- package/src/data-structures/graph/undirected-graph.ts +11 -10
- package/src/data-structures/hash/coordinate-map.ts +1 -1
- package/src/data-structures/hash/index.ts +5 -0
- package/src/data-structures/heap/heap.ts +2 -11
- package/src/data-structures/heap/max-heap.ts +3 -2
- package/src/data-structures/heap/min-heap.ts +3 -2
- package/src/data-structures/index.ts +1 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -9
- package/src/data-structures/linked-list/singly-linked-list.ts +18 -32
- package/src/data-structures/matrix/matrix2d.ts +11 -11
- package/src/data-structures/matrix/navigator.ts +2 -14
- package/src/data-structures/matrix/vector2d.ts +52 -52
- package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/priority-queue.ts +70 -78
- package/src/data-structures/queue/deque.ts +2 -2
- package/src/data-structures/queue/queue.ts +12 -13
- package/src/data-structures/stack/stack.ts +12 -13
- package/src/data-structures/trampoline.ts +31 -71
- package/src/data-structures/trie/trie.ts +61 -11
- package/src/data-structures/types/abstract-graph.ts +51 -0
- package/src/data-structures/types/avl-tree.ts +6 -0
- package/src/data-structures/types/binary-tree.ts +15 -0
- package/src/data-structures/types/bst.ts +5 -0
- package/src/data-structures/types/directed-graph.ts +18 -0
- package/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/src/data-structures/types/heap.ts +8 -0
- package/src/data-structures/types/index.ts +13 -0
- package/src/data-structures/types/navigator.ts +12 -0
- package/src/data-structures/types/priority-queue.ts +9 -0
- package/src/data-structures/types/segment-tree.ts +1 -0
- package/src/data-structures/types/singly-linked-list.ts +15 -0
- package/src/data-structures/types/tree-multiset.ts +3 -0
- package/src/{types → data-structures/types}/utils.ts +20 -5
- package/src/utils/index.ts +1 -0
- package/src/{utils.ts → utils/utils.ts} +32 -132
- package/tsconfig.json +9 -6
- package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
- package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
- package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
- package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
- package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
- package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
- package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
- package/dist/types/data-structures/graph/index.d.ts +0 -3
- package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
- package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
- package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
- package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/pair.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +0 -72
- package/dist/types/data-structures/heap/index.d.ts +0 -3
- package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
- package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
- package/dist/types/data-structures/index.d.ts +0 -9
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
- package/dist/types/data-structures/linked-list/index.d.ts +0 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
- package/dist/types/data-structures/matrix/index.d.ts +0 -3
- package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
- package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
- package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
- package/dist/types/data-structures/queue/deque.d.ts +0 -37
- package/dist/types/data-structures/queue/index.d.ts +0 -1
- package/dist/types/data-structures/queue/queue.d.ts +0 -76
- package/dist/types/data-structures/stack/index.d.ts +0 -1
- package/dist/types/data-structures/stack/stack.d.ts +0 -69
- package/dist/types/data-structures/trampoline.d.ts +0 -25
- package/dist/types/data-structures/trie/index.d.ts +0 -1
- package/dist/types/data-structures/trie/trie.d.ts +0 -28
- package/dist/types/types/index.d.ts +0 -1
- package/dist/types/types/utils.d.ts +0 -46
- package/dist/utils.js +0 -569
- package/src/types/index.ts +0 -1
- package/src/types/patches/index.d.ts +0 -0
- /package/dist/{types → utils}/index.d.ts +0 -0
- /package/dist/{types → utils}/index.js +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;
|
package/src/types/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './utils';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|