data-structure-typed 1.12.11 → 1.12.21
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/dist/data-structures/binary-tree/avl-tree.d.ts +14 -5
- package/dist/data-structures/binary-tree/avl-tree.js +15 -6
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +11 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +11 -2
- package/dist/data-structures/binary-tree/binary-tree.d.ts +26 -17
- package/dist/data-structures/binary-tree/binary-tree.js +72 -62
- package/dist/data-structures/binary-tree/bst.d.ts +92 -5
- package/dist/data-structures/binary-tree/bst.js +89 -5
- package/dist/data-structures/binary-tree/segment-tree.d.ts +41 -2
- package/dist/data-structures/binary-tree/segment-tree.js +41 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +34 -3
- package/dist/data-structures/binary-tree/tree-multiset.js +35 -4
- package/dist/data-structures/graph/abstract-graph.d.ts +5 -0
- package/dist/data-structures/graph/abstract-graph.js +12 -4
- package/dist/data-structures/graph/directed-graph.d.ts +18 -4
- package/dist/data-structures/graph/directed-graph.js +24 -37
- package/dist/data-structures/graph/undirected-graph.d.ts +13 -0
- package/dist/data-structures/graph/undirected-graph.js +18 -2
- package/dist/data-structures/hash/coordinate-map.d.ts +5 -2
- package/dist/data-structures/hash/coordinate-map.js +5 -2
- package/dist/data-structures/hash/coordinate-set.d.ts +5 -2
- package/dist/data-structures/hash/coordinate-set.js +5 -2
- package/dist/data-structures/heap/heap.d.ts +9 -6
- package/dist/data-structures/heap/heap.js +8 -8
- package/dist/data-structures/heap/max-heap.d.ts +5 -2
- package/dist/data-structures/heap/max-heap.js +5 -2
- package/dist/data-structures/heap/min-heap.d.ts +5 -2
- package/dist/data-structures/heap/min-heap.js +5 -2
- 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 +2 -2
- package/dist/data-structures/linked-list/doubly-linked-list.js +4 -4
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +5 -2
- package/dist/data-structures/linked-list/singly-linked-list.js +5 -2
- package/dist/data-structures/matrix/matrix.d.ts +5 -2
- package/dist/data-structures/matrix/matrix.js +5 -2
- package/dist/data-structures/matrix/matrix2d.d.ts +5 -2
- package/dist/data-structures/matrix/matrix2d.js +5 -2
- package/dist/data-structures/matrix/navigator.d.ts +5 -2
- package/dist/data-structures/matrix/vector2d.d.ts +5 -2
- package/dist/data-structures/matrix/vector2d.js +5 -2
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +5 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +5 -2
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +5 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +5 -2
- package/dist/data-structures/priority-queue/priority-queue.d.ts +7 -4
- package/dist/data-structures/priority-queue/priority-queue.js +2 -2
- package/dist/data-structures/queue/deque.d.ts +12 -9
- package/dist/data-structures/queue/deque.js +12 -9
- package/dist/data-structures/queue/queue.d.ts +4 -4
- package/dist/data-structures/queue/queue.js +4 -4
- package/dist/data-structures/stack/stack.d.ts +1 -1
- package/dist/data-structures/stack/stack.js +1 -1
- package/dist/data-structures/trie/trie.d.ts +6 -3
- package/dist/data-structures/trie/trie.js +7 -4
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/types/utils.d.ts +8 -10
- package/dist/utils/types/utils.js +0 -1
- package/dist/utils/utils.d.ts +18 -8
- package/dist/utils/utils.js +93 -47
- package/package.json +1 -1
- package/dist/utils/trampoline.d.ts +0 -14
- package/dist/utils/trampoline.js +0 -130
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Queue = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @license MIT
|
|
6
|
-
* @copyright
|
|
6
|
+
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
7
7
|
* @class
|
|
8
8
|
*/
|
|
9
9
|
var Queue = /** @class */ (function () {
|
|
@@ -29,11 +29,11 @@ var Queue = /** @class */ (function () {
|
|
|
29
29
|
return new Queue(elements);
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
|
-
* The
|
|
32
|
+
* The add function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
|
|
33
33
|
* @param {T} element - The `element` parameter represents the element that you want to add to the queue.
|
|
34
|
-
* @returns The `
|
|
34
|
+
* @returns The `add` method is returning a `Queue<T>` object.
|
|
35
35
|
*/
|
|
36
|
-
Queue.prototype.
|
|
36
|
+
Queue.prototype.add = function (element) {
|
|
37
37
|
this._nodes.push(element);
|
|
38
38
|
return this;
|
|
39
39
|
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
4
7
|
*/
|
|
5
8
|
export declare class TrieNode {
|
|
6
9
|
protected _value: string;
|
|
@@ -19,7 +22,7 @@ export declare class Trie {
|
|
|
19
22
|
protected _root: TrieNode;
|
|
20
23
|
get root(): TrieNode;
|
|
21
24
|
set root(v: TrieNode);
|
|
22
|
-
|
|
25
|
+
add(word: string): boolean;
|
|
23
26
|
has(input: string): boolean;
|
|
24
27
|
remove(word: string): boolean;
|
|
25
28
|
/**
|
|
@@ -13,8 +13,11 @@ var __values = (this && this.__values) || function(o) {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.Trie = exports.TrieNode = void 0;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* data-structure-typed
|
|
17
|
+
*
|
|
18
|
+
* @author Tyler Zeng
|
|
19
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
20
|
+
* @license MIT License
|
|
18
21
|
*/
|
|
19
22
|
var TrieNode = /** @class */ (function () {
|
|
20
23
|
function TrieNode(v) {
|
|
@@ -63,7 +66,7 @@ var Trie = /** @class */ (function () {
|
|
|
63
66
|
try {
|
|
64
67
|
for (var words_1 = __values(words), words_1_1 = words_1.next(); !words_1_1.done; words_1_1 = words_1.next()) {
|
|
65
68
|
var i = words_1_1.value;
|
|
66
|
-
this.
|
|
69
|
+
this.add(i);
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
72
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -85,7 +88,7 @@ var Trie = /** @class */ (function () {
|
|
|
85
88
|
enumerable: false,
|
|
86
89
|
configurable: true
|
|
87
90
|
});
|
|
88
|
-
Trie.prototype.
|
|
91
|
+
Trie.prototype.add = function (word) {
|
|
89
92
|
var e_2, _a;
|
|
90
93
|
var cur = this._root;
|
|
91
94
|
try {
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export type JSONSerializable = {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
};
|
|
4
|
+
export type JSONValue = string | number | boolean | undefined | JSONObject;
|
|
5
|
+
export interface JSONObject {
|
|
6
|
+
[key: string]: JSONValue;
|
|
7
|
+
}
|
|
1
8
|
export type AnyFunction<A extends any[] = any[], R = any> = (...args: A) => R;
|
|
2
9
|
export type Primitive = number | string | boolean | symbol | undefined | null | void | AnyFunction | Date;
|
|
3
10
|
export type Cast<T, TComplex> = {
|
|
@@ -6,13 +13,6 @@ export type Cast<T, TComplex> = {
|
|
|
6
13
|
export type DeepLeavesWrap<T, TComplex> = T extends string ? Cast<string, TComplex> : T extends number ? Cast<number, TComplex> : T extends boolean ? Cast<boolean, TComplex> : T extends undefined ? Cast<undefined, TComplex> : T extends null ? Cast<null, TComplex> : T extends void ? Cast<void, TComplex> : T extends symbol ? Cast<symbol, TComplex> : T extends AnyFunction ? Cast<AnyFunction, TComplex> : T extends Date ? Cast<Date, TComplex> : {
|
|
7
14
|
[K in keyof T]: T[K] extends (infer U)[] ? DeepLeavesWrap<U, TComplex>[] : DeepLeavesWrap<T[K], TComplex>;
|
|
8
15
|
};
|
|
9
|
-
export type JSONSerializable = {
|
|
10
|
-
[key: string]: any;
|
|
11
|
-
};
|
|
12
|
-
export type JSONValue = string | number | boolean | undefined | JSONObject;
|
|
13
|
-
export interface JSONObject {
|
|
14
|
-
[key: string]: JSONValue;
|
|
15
|
-
}
|
|
16
16
|
export type TypeName<T> = T extends string ? 'string' : T extends number ? 'number' : T extends boolean ? 'boolean' : T extends undefined ? 'undefined' : T extends AnyFunction ? 'function' : 'object';
|
|
17
17
|
export type JsonKeys<T> = keyof {
|
|
18
18
|
[P in keyof T]: number;
|
|
@@ -51,10 +51,8 @@ export type DeepProxyOnChange = (target: any, property: string | symbol, value:
|
|
|
51
51
|
export type DeepProxyOnGet = (target: any, property: string | symbol, value: any, receiver: any, descriptor: any, result: any) => void;
|
|
52
52
|
export type CurryFunc<T> = T extends (...args: infer Args) => infer R ? Args extends [infer Arg, ...infer RestArgs] ? (arg: Arg) => CurryFunc<(...args: RestArgs) => R> : R : T;
|
|
53
53
|
export type ToThunkFn = () => ReturnType<TrlFn>;
|
|
54
|
-
declare const THUNK_SYMBOL: unique symbol;
|
|
55
54
|
export type Thunk = () => ReturnType<ToThunkFn> & {
|
|
56
|
-
__THUNK__:
|
|
55
|
+
__THUNK__: Symbol;
|
|
57
56
|
};
|
|
58
57
|
export type TrlFn = (...args: any[]) => any;
|
|
59
58
|
export type TrlAsyncFn = (...args: any[]) => any;
|
|
60
|
-
export {};
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import { AnyFunction } from './types';
|
|
2
|
-
export type JSONSerializable = {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
};
|
|
5
|
-
export type JSONValue = string | number | boolean | undefined | JSONObject;
|
|
6
|
-
export interface JSONObject {
|
|
7
|
-
[key: string]: JSONValue;
|
|
8
|
-
}
|
|
1
|
+
import type { AnyFunction, JSONObject, JSONSerializable } from './types';
|
|
9
2
|
export declare function randomText(length: number): string;
|
|
10
3
|
export declare const uuidV4: () => string;
|
|
11
4
|
export declare class IncrementId {
|
|
@@ -103,3 +96,20 @@ export declare function zip<T = number, T1 = number>(array1: T[], array2: T1[],
|
|
|
103
96
|
x: T;
|
|
104
97
|
y: T1;
|
|
105
98
|
}[];
|
|
99
|
+
/**
|
|
100
|
+
* data-structure-typed
|
|
101
|
+
*
|
|
102
|
+
* @author Tyler Zeng
|
|
103
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
104
|
+
* @license MIT License
|
|
105
|
+
*/
|
|
106
|
+
import { Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from './types';
|
|
107
|
+
export declare const THUNK_SYMBOL: unique symbol;
|
|
108
|
+
export declare const isThunk: (fnOrValue: any) => boolean;
|
|
109
|
+
export declare const toThunk: (fn: ToThunkFn) => Thunk;
|
|
110
|
+
export declare const trampoline: (fn: TrlFn) => ((...args: [...Parameters<TrlFn>]) => any) & {
|
|
111
|
+
cont: (...args: [...Parameters<TrlFn>]) => Thunk;
|
|
112
|
+
};
|
|
113
|
+
export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Parameters<TrlAsyncFn>]) => Promise<any>) & {
|
|
114
|
+
cont: (...args: [...Parameters<TrlAsyncFn>]) => Thunk;
|
|
115
|
+
};
|
package/dist/utils/utils.js
CHANGED
|
@@ -10,29 +10,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
-
}
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -105,9 +82,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
105
82
|
}
|
|
106
83
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
107
84
|
};
|
|
85
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
86
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
87
|
+
};
|
|
108
88
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
109
|
-
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.wait = exports.WaitManager = exports.addDays = exports.isLeafParent = exports.isSameStructure = exports.reverseColor = exports.deepObjectStrictEqual = exports.strictObjectIsEqual = exports.strictEqual = exports.looseEqual = exports.isObject = exports.getValue = exports.incrementId = exports.IncrementId = exports.uuidV4 = exports.randomText = void 0;
|
|
110
|
-
var
|
|
89
|
+
exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = 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.wait = exports.WaitManager = exports.addDays = exports.isLeafParent = exports.isSameStructure = exports.reverseColor = exports.deepObjectStrictEqual = exports.strictObjectIsEqual = exports.strictEqual = exports.looseEqual = exports.isObject = exports.getValue = exports.incrementId = exports.IncrementId = exports.uuidV4 = exports.randomText = void 0;
|
|
90
|
+
var lodash_1 = __importDefault(require("lodash"));
|
|
111
91
|
function randomText(length) {
|
|
112
92
|
var result = '';
|
|
113
93
|
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
@@ -396,7 +376,7 @@ var comparerArray = function (otherArray, limitKeys) {
|
|
|
396
376
|
return function (current) {
|
|
397
377
|
return otherArray.filter(function (other) {
|
|
398
378
|
if (!limitKeys) {
|
|
399
|
-
return
|
|
379
|
+
return lodash_1.default.isEqual(current, other);
|
|
400
380
|
}
|
|
401
381
|
else {
|
|
402
382
|
// TODO
|
|
@@ -416,43 +396,43 @@ var StringUtil = /** @class */ (function () {
|
|
|
416
396
|
}
|
|
417
397
|
// camelCase
|
|
418
398
|
StringUtil.toCamelCase = function (str) {
|
|
419
|
-
return
|
|
399
|
+
return lodash_1.default.camelCase(str);
|
|
420
400
|
};
|
|
421
401
|
// snake_case
|
|
422
402
|
StringUtil.toSnakeCase = function (str) {
|
|
423
|
-
return
|
|
403
|
+
return lodash_1.default.snakeCase(str);
|
|
424
404
|
};
|
|
425
405
|
// PascalCase
|
|
426
406
|
StringUtil.toPascalCase = function (str) {
|
|
427
|
-
return
|
|
407
|
+
return lodash_1.default.startCase(lodash_1.default.camelCase(str)).replace(/ /g, '');
|
|
428
408
|
};
|
|
429
409
|
// CONSTANT_CASE
|
|
430
410
|
StringUtil.toConstantCase = function (str) {
|
|
431
|
-
return
|
|
411
|
+
return lodash_1.default.upperCase(str).replace(/ /g, '_');
|
|
432
412
|
};
|
|
433
413
|
// kebab-case
|
|
434
414
|
StringUtil.toKebabCase = function (str) {
|
|
435
|
-
return
|
|
415
|
+
return lodash_1.default.kebabCase(str);
|
|
436
416
|
};
|
|
437
417
|
// lowercase
|
|
438
418
|
StringUtil.toLowerCase = function (str) {
|
|
439
|
-
return
|
|
419
|
+
return lodash_1.default.lowerCase(str).replace(/ /g, '');
|
|
440
420
|
};
|
|
441
421
|
// Title Case
|
|
442
422
|
StringUtil.toTitleCase = function (str) {
|
|
443
|
-
return
|
|
423
|
+
return lodash_1.default.startCase(lodash_1.default.camelCase(str));
|
|
444
424
|
};
|
|
445
425
|
// Sentence case
|
|
446
426
|
StringUtil.toSentenceCase = function (str) {
|
|
447
|
-
return
|
|
427
|
+
return lodash_1.default.upperFirst(lodash_1.default.lowerCase(str));
|
|
448
428
|
};
|
|
449
429
|
// path/case
|
|
450
430
|
StringUtil.toPathCase = function (str) {
|
|
451
|
-
return
|
|
431
|
+
return lodash_1.default.lowerCase(str).replace(/ /g, '/');
|
|
452
432
|
};
|
|
453
433
|
// dot.case
|
|
454
434
|
StringUtil.toDotCase = function (str) {
|
|
455
|
-
return
|
|
435
|
+
return lodash_1.default.lowerCase(str).replace(/ /g, '.');
|
|
456
436
|
};
|
|
457
437
|
return StringUtil;
|
|
458
438
|
}());
|
|
@@ -508,27 +488,27 @@ var deepKeysConvert = function (obj, toType) {
|
|
|
508
488
|
};
|
|
509
489
|
exports.deepKeysConvert = deepKeysConvert;
|
|
510
490
|
var deepRemoveByKey = function (obj, keysToBeRemoved) {
|
|
511
|
-
var result =
|
|
512
|
-
if (
|
|
491
|
+
var result = lodash_1.default.transform(obj, function (result, value, key) {
|
|
492
|
+
if (lodash_1.default.isObject(value)) {
|
|
513
493
|
value = (0, exports.deepRemoveByKey)(value, keysToBeRemoved);
|
|
514
494
|
}
|
|
515
495
|
if (!keysToBeRemoved.includes(key)) {
|
|
516
|
-
|
|
496
|
+
lodash_1.default.isArray(obj) ? result.push(value) : result[key] = value;
|
|
517
497
|
}
|
|
518
498
|
});
|
|
519
499
|
return result;
|
|
520
500
|
};
|
|
521
501
|
exports.deepRemoveByKey = deepRemoveByKey;
|
|
522
502
|
var deepRenameKeys = function (obj, keysMap) {
|
|
523
|
-
return
|
|
503
|
+
return lodash_1.default.transform(obj, function (result, value, key) {
|
|
524
504
|
var currentKey = keysMap[key] || key;
|
|
525
|
-
result[currentKey] =
|
|
505
|
+
result[currentKey] = lodash_1.default.isObject(value) ? (0, exports.deepRenameKeys)(value, keysMap) : value;
|
|
526
506
|
});
|
|
527
507
|
};
|
|
528
508
|
exports.deepRenameKeys = deepRenameKeys;
|
|
529
509
|
var deepReplaceValues = function (obj, keyReducerMap) {
|
|
530
|
-
var newObject =
|
|
531
|
-
|
|
510
|
+
var newObject = lodash_1.default.clone(obj);
|
|
511
|
+
lodash_1.default.each(obj, function (val, key) {
|
|
532
512
|
for (var item in keyReducerMap) {
|
|
533
513
|
if (key === item) {
|
|
534
514
|
newObject[key] = keyReducerMap[item](newObject);
|
|
@@ -543,14 +523,14 @@ var deepReplaceValues = function (obj, keyReducerMap) {
|
|
|
543
523
|
exports.deepReplaceValues = deepReplaceValues;
|
|
544
524
|
// TODO determine depth and pass root node as a param through callback
|
|
545
525
|
var deepAdd = function (obj, keyReducerMap, isItemRootParent) {
|
|
546
|
-
var newObject =
|
|
547
|
-
if (
|
|
526
|
+
var newObject = lodash_1.default.clone(obj);
|
|
527
|
+
if (lodash_1.default.isObject(newObject) && !lodash_1.default.isArray(newObject)) {
|
|
548
528
|
for (var item in keyReducerMap) {
|
|
549
529
|
newObject[item] = keyReducerMap[item](newObject);
|
|
550
530
|
}
|
|
551
531
|
}
|
|
552
|
-
|
|
553
|
-
if (
|
|
532
|
+
lodash_1.default.each(obj, function (val, key) {
|
|
533
|
+
if (lodash_1.default.isObject(val)) {
|
|
554
534
|
for (var item in keyReducerMap) {
|
|
555
535
|
// @ts-ignore
|
|
556
536
|
newObject[key] = (0, exports.deepAdd)(val, keyReducerMap, isItemRootParent);
|
|
@@ -649,3 +629,69 @@ function zip(array1, array2, options) {
|
|
|
649
629
|
return isToObj ? zippedObjCoords : zipped;
|
|
650
630
|
}
|
|
651
631
|
exports.zip = zip;
|
|
632
|
+
exports.THUNK_SYMBOL = Symbol('thunk');
|
|
633
|
+
var isThunk = function (fnOrValue) {
|
|
634
|
+
return typeof fnOrValue === 'function' && fnOrValue.__THUNK__ === exports.THUNK_SYMBOL;
|
|
635
|
+
};
|
|
636
|
+
exports.isThunk = isThunk;
|
|
637
|
+
var toThunk = function (fn) {
|
|
638
|
+
var thunk = function () { return fn(); };
|
|
639
|
+
thunk.__THUNK__ = exports.THUNK_SYMBOL;
|
|
640
|
+
return thunk;
|
|
641
|
+
};
|
|
642
|
+
exports.toThunk = toThunk;
|
|
643
|
+
var trampoline = function (fn) {
|
|
644
|
+
var cont = function () {
|
|
645
|
+
var args = [];
|
|
646
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
647
|
+
args[_i] = arguments[_i];
|
|
648
|
+
}
|
|
649
|
+
return (0, exports.toThunk)(function () { return fn.apply(void 0, __spreadArray([], __read(args), false)); });
|
|
650
|
+
};
|
|
651
|
+
return Object.assign(function () {
|
|
652
|
+
var args = [];
|
|
653
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
654
|
+
args[_i] = arguments[_i];
|
|
655
|
+
}
|
|
656
|
+
var result = fn.apply(void 0, __spreadArray([], __read(args), false));
|
|
657
|
+
while ((0, exports.isThunk)(result) && typeof result === 'function') {
|
|
658
|
+
result = result();
|
|
659
|
+
}
|
|
660
|
+
return result;
|
|
661
|
+
}, { cont: cont });
|
|
662
|
+
};
|
|
663
|
+
exports.trampoline = trampoline;
|
|
664
|
+
var trampolineAsync = function (fn) {
|
|
665
|
+
var cont = function () {
|
|
666
|
+
var args = [];
|
|
667
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
668
|
+
args[_i] = arguments[_i];
|
|
669
|
+
}
|
|
670
|
+
return (0, exports.toThunk)(function () { return fn.apply(void 0, __spreadArray([], __read(args), false)); });
|
|
671
|
+
};
|
|
672
|
+
return Object.assign(function () {
|
|
673
|
+
var args = [];
|
|
674
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
675
|
+
args[_i] = arguments[_i];
|
|
676
|
+
}
|
|
677
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
678
|
+
var result;
|
|
679
|
+
return __generator(this, function (_a) {
|
|
680
|
+
switch (_a.label) {
|
|
681
|
+
case 0: return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(args), false))];
|
|
682
|
+
case 1:
|
|
683
|
+
result = _a.sent();
|
|
684
|
+
_a.label = 2;
|
|
685
|
+
case 2:
|
|
686
|
+
if (!((0, exports.isThunk)(result) && typeof result === 'function')) return [3 /*break*/, 4];
|
|
687
|
+
return [4 /*yield*/, result()];
|
|
688
|
+
case 3:
|
|
689
|
+
result = _a.sent();
|
|
690
|
+
return [3 /*break*/, 2];
|
|
691
|
+
case 4: return [2 /*return*/, result];
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
});
|
|
695
|
+
}, { cont: cont });
|
|
696
|
+
};
|
|
697
|
+
exports.trampolineAsync = trampolineAsync;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.21",
|
|
4
4
|
"description": "Explore our comprehensive Javascript Data Structure / TypeScript Data Structure Library, meticulously crafted to empower developers with a versatile set of essential data structures. Our library includes a wide range of data structures, such as Binary Tree, AVL Tree, Binary Search Tree (BST), Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Singly Linked List, Hash, CoordinateSet, CoordinateMap, Heap, Doubly Linked List, Priority Queue, Max Priority Queue, Min Priority Queue, Queue, ObjectDeque, ArrayDeque, Stack, and Trie. Each data structure is thoughtfully designed and implemented using TypeScript to provide efficient, reliable, and easy-to-use solutions for your programming needs. Whether you're optimizing algorithms, managing data, or enhancing performance, our TypeScript Data Structure Library is your go-to resource. Elevate your coding experience with these fundamental building blocks for software development.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
3
|
-
* @license MIT
|
|
4
|
-
*/
|
|
5
|
-
import { Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from './types';
|
|
6
|
-
export declare const THUNK_SYMBOL: unique symbol;
|
|
7
|
-
export declare const isThunk: (fnOrValue: any) => boolean;
|
|
8
|
-
export declare const toThunk: (fn: ToThunkFn) => Thunk;
|
|
9
|
-
export declare const trampoline: (fn: TrlFn) => ((...args: [...Parameters<TrlFn>]) => any) & {
|
|
10
|
-
cont: (...args: [...Parameters<TrlFn>]) => Thunk;
|
|
11
|
-
};
|
|
12
|
-
export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Parameters<TrlAsyncFn>]) => Promise<any>) & {
|
|
13
|
-
cont: (...args: [...Parameters<TrlAsyncFn>]) => Thunk;
|
|
14
|
-
};
|
package/dist/utils/trampoline.js
DELETED
|
@@ -1,130 +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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
-
if (!m) return o;
|
|
41
|
-
var i = m.call(o), r, ar = [], e;
|
|
42
|
-
try {
|
|
43
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
-
}
|
|
45
|
-
catch (error) { e = { error: error }; }
|
|
46
|
-
finally {
|
|
47
|
-
try {
|
|
48
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
-
}
|
|
50
|
-
finally { if (e) throw e.error; }
|
|
51
|
-
}
|
|
52
|
-
return ar;
|
|
53
|
-
};
|
|
54
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
55
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
56
|
-
if (ar || !(i in from)) {
|
|
57
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
58
|
-
ar[i] = from[i];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
62
|
-
};
|
|
63
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
-
exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = void 0;
|
|
65
|
-
exports.THUNK_SYMBOL = Symbol('thunk');
|
|
66
|
-
var isThunk = function (fnOrValue) {
|
|
67
|
-
return typeof fnOrValue === 'function' && fnOrValue.__THUNK__ === exports.THUNK_SYMBOL;
|
|
68
|
-
};
|
|
69
|
-
exports.isThunk = isThunk;
|
|
70
|
-
var toThunk = function (fn) {
|
|
71
|
-
var thunk = function () { return fn(); };
|
|
72
|
-
thunk.__THUNK__ = exports.THUNK_SYMBOL;
|
|
73
|
-
return thunk;
|
|
74
|
-
};
|
|
75
|
-
exports.toThunk = toThunk;
|
|
76
|
-
var trampoline = function (fn) {
|
|
77
|
-
var cont = function () {
|
|
78
|
-
var args = [];
|
|
79
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
80
|
-
args[_i] = arguments[_i];
|
|
81
|
-
}
|
|
82
|
-
return (0, exports.toThunk)(function () { return fn.apply(void 0, __spreadArray([], __read(args), false)); });
|
|
83
|
-
};
|
|
84
|
-
return Object.assign(function () {
|
|
85
|
-
var args = [];
|
|
86
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
87
|
-
args[_i] = arguments[_i];
|
|
88
|
-
}
|
|
89
|
-
var result = fn.apply(void 0, __spreadArray([], __read(args), false));
|
|
90
|
-
while ((0, exports.isThunk)(result) && typeof result === 'function') {
|
|
91
|
-
result = result();
|
|
92
|
-
}
|
|
93
|
-
return result;
|
|
94
|
-
}, { cont: cont });
|
|
95
|
-
};
|
|
96
|
-
exports.trampoline = trampoline;
|
|
97
|
-
var trampolineAsync = function (fn) {
|
|
98
|
-
var cont = function () {
|
|
99
|
-
var args = [];
|
|
100
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
101
|
-
args[_i] = arguments[_i];
|
|
102
|
-
}
|
|
103
|
-
return (0, exports.toThunk)(function () { return fn.apply(void 0, __spreadArray([], __read(args), false)); });
|
|
104
|
-
};
|
|
105
|
-
return Object.assign(function () {
|
|
106
|
-
var args = [];
|
|
107
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
108
|
-
args[_i] = arguments[_i];
|
|
109
|
-
}
|
|
110
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
111
|
-
var result;
|
|
112
|
-
return __generator(this, function (_a) {
|
|
113
|
-
switch (_a.label) {
|
|
114
|
-
case 0: return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(args), false))];
|
|
115
|
-
case 1:
|
|
116
|
-
result = _a.sent();
|
|
117
|
-
_a.label = 2;
|
|
118
|
-
case 2:
|
|
119
|
-
if (!((0, exports.isThunk)(result) && typeof result === 'function')) return [3 /*break*/, 4];
|
|
120
|
-
return [4 /*yield*/, result()];
|
|
121
|
-
case 3:
|
|
122
|
-
result = _a.sent();
|
|
123
|
-
return [3 /*break*/, 2];
|
|
124
|
-
case 4: return [2 /*return*/, result];
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
}, { cont: cont });
|
|
129
|
-
};
|
|
130
|
-
exports.trampolineAsync = trampolineAsync;
|