graph-typed 1.44.1 → 1.45.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/hash/hash-map.d.ts +230 -37
- package/dist/data-structures/hash/hash-map.js +427 -115
- package/dist/types/data-structures/hash/hash-map.d.ts +15 -1
- package/dist/types/data-structures/hash/index.d.ts +6 -0
- package/dist/types/data-structures/hash/index.js +20 -0
- package/dist/utils/utils.d.ts +3 -0
- package/dist/utils/utils.js +15 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +7 -7
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -3
- package/src/data-structures/binary-tree/binary-tree.ts +39 -31
- package/src/data-structures/binary-tree/bst.ts +12 -8
- package/src/data-structures/binary-tree/rb-tree.ts +17 -6
- package/src/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/data-structures/binary-tree/tree-multimap.ts +12 -9
- package/src/data-structures/graph/abstract-graph.ts +46 -31
- package/src/data-structures/graph/directed-graph.ts +10 -5
- package/src/data-structures/graph/map-graph.ts +8 -8
- package/src/data-structures/graph/undirected-graph.ts +9 -9
- package/src/data-structures/hash/hash-map.ts +430 -123
- package/src/data-structures/hash/hash-table.ts +1 -1
- package/src/data-structures/hash/tree-map.ts +2 -1
- package/src/data-structures/hash/tree-set.ts +2 -1
- package/src/data-structures/heap/heap.ts +8 -5
- package/src/data-structures/heap/max-heap.ts +3 -3
- package/src/data-structures/heap/min-heap.ts +3 -3
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/matrix/matrix.ts +2 -2
- package/src/data-structures/matrix/matrix2d.ts +1 -1
- package/src/data-structures/matrix/navigator.ts +3 -3
- package/src/data-structures/matrix/vector2d.ts +2 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +3 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +3 -3
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/data-structures/queue/deque.ts +5 -4
- package/src/data-structures/queue/queue.ts +2 -2
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +1 -1
- package/src/interfaces/binary-tree.ts +2 -2
- package/src/interfaces/graph.ts +1 -1
- package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/bst.ts +2 -2
- package/src/types/data-structures/binary-tree/rb-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/tree-multimap.ts +2 -2
- package/src/types/data-structures/hash/hash-map.ts +17 -1
- package/src/types/data-structures/hash/index.ts +7 -0
- package/src/types/data-structures/matrix/navigator.ts +1 -1
- package/src/types/utils/utils.ts +1 -1
- package/src/types/utils/validate-type.ts +18 -4
- package/src/utils/utils.ts +16 -3
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* @license MIT License
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {Comparator, DFSOrderPattern} from '../../types';
|
|
8
|
+
import type { Comparator, DFSOrderPattern } from '../../types';
|
|
9
9
|
|
|
10
10
|
export class Heap<E = any> {
|
|
11
|
-
constructor(options: {comparator: Comparator<E>; nodes?: E[]}) {
|
|
11
|
+
constructor(options: { comparator: Comparator<E>; nodes?: E[] }) {
|
|
12
12
|
this._comparator = options.comparator;
|
|
13
13
|
if (options.nodes && options.nodes.length > 0) {
|
|
14
14
|
this._nodes = options.nodes;
|
|
@@ -48,7 +48,7 @@ export class Heap<E = any> {
|
|
|
48
48
|
* @returns A new Heap instance.
|
|
49
49
|
* @param options
|
|
50
50
|
*/
|
|
51
|
-
static heapify<E>(options: {nodes: E[]; comparator: Comparator<E>}): Heap<E> {
|
|
51
|
+
static heapify<E>(options: { nodes: E[]; comparator: Comparator<E> }): Heap<E> {
|
|
52
52
|
return new Heap<E>(options);
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -265,7 +265,7 @@ export class Heap<E = any> {
|
|
|
265
265
|
* @returns A new Heap instance containing the same elements.
|
|
266
266
|
*/
|
|
267
267
|
clone(): Heap<E> {
|
|
268
|
-
const clonedHeap = new Heap<E>({comparator: this.comparator});
|
|
268
|
+
const clonedHeap = new Heap<E>({ comparator: this.comparator });
|
|
269
269
|
clonedHeap._nodes = [...this.nodes];
|
|
270
270
|
return clonedHeap;
|
|
271
271
|
}
|
|
@@ -741,7 +741,10 @@ export class FibonacciHeap<E> {
|
|
|
741
741
|
protected consolidate(): void {
|
|
742
742
|
const A: (FibonacciHeapNode<E> | undefined)[] = new Array(this.size);
|
|
743
743
|
const nodes = this.consumeLinkedList(this.root);
|
|
744
|
-
let x: FibonacciHeapNode<E> | undefined,
|
|
744
|
+
let x: FibonacciHeapNode<E> | undefined,
|
|
745
|
+
y: FibonacciHeapNode<E> | undefined,
|
|
746
|
+
d: number,
|
|
747
|
+
t: FibonacciHeapNode<E> | undefined;
|
|
745
748
|
|
|
746
749
|
for (const node of nodes) {
|
|
747
750
|
x = node;
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {Heap} from './heap';
|
|
10
|
-
import type {Comparator} from '../../types';
|
|
9
|
+
import { Heap } from './heap';
|
|
10
|
+
import type { Comparator } from '../../types';
|
|
11
11
|
|
|
12
12
|
export class MaxHeap<E = any> extends Heap<E> {
|
|
13
13
|
constructor(
|
|
14
|
-
options: {comparator: Comparator<E>; nodes?: E[]} = {
|
|
14
|
+
options: { comparator: Comparator<E>; nodes?: E[] } = {
|
|
15
15
|
comparator: (a: E, b: E) => {
|
|
16
16
|
if (!(typeof a === 'number' && typeof b === 'number')) {
|
|
17
17
|
throw new Error('The a, b params of compare function must be number');
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {Heap} from './heap';
|
|
10
|
-
import type {Comparator} from '../../types';
|
|
9
|
+
import { Heap } from './heap';
|
|
10
|
+
import type { Comparator } from '../../types';
|
|
11
11
|
|
|
12
12
|
export class MinHeap<E = any> extends Heap<E> {
|
|
13
13
|
constructor(
|
|
14
|
-
options: {comparator: Comparator<E>; nodes?: E[]} = {
|
|
14
|
+
options: { comparator: Comparator<E>; nodes?: E[] } = {
|
|
15
15
|
comparator: (a: E, b: E) => {
|
|
16
16
|
if (!(typeof a === 'number' && typeof b === 'number')) {
|
|
17
17
|
throw new Error('The a, b params of compare function must be number');
|
|
@@ -826,7 +826,7 @@ export class DoublyLinkedList<E = any> {
|
|
|
826
826
|
/**
|
|
827
827
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
828
828
|
*/
|
|
829
|
-
*[Symbol.iterator]() {
|
|
829
|
+
* [Symbol.iterator]() {
|
|
830
830
|
let current = this.head;
|
|
831
831
|
|
|
832
832
|
while (current) {
|
|
@@ -773,7 +773,7 @@ export class SinglyLinkedList<E = any> {
|
|
|
773
773
|
/**
|
|
774
774
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
775
775
|
*/
|
|
776
|
-
*[Symbol.iterator]() {
|
|
776
|
+
* [Symbol.iterator]() {
|
|
777
777
|
let current = this.head;
|
|
778
778
|
|
|
779
779
|
while (current) {
|
|
@@ -14,8 +14,8 @@ export class MatrixNTI2D<V = any> {
|
|
|
14
14
|
* given initial value or 0 if not provided.
|
|
15
15
|
* @param options - An object containing the following properties:
|
|
16
16
|
*/
|
|
17
|
-
constructor(options: {row: number; col: number; initialVal?: V}) {
|
|
18
|
-
const {row, col, initialVal} = options;
|
|
17
|
+
constructor(options: { row: number; col: number; initialVal?: V }) {
|
|
18
|
+
const { row, col, initialVal } = options;
|
|
19
19
|
this._matrix = new Array(row).fill(undefined).map(() => new Array(col).fill(initialVal || 0));
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type {Direction, NavigatorParams, Turning} from '../../types';
|
|
8
|
+
import type { Direction, NavigatorParams, Turning } from '../../types';
|
|
9
9
|
|
|
10
10
|
export class Character {
|
|
11
11
|
direction: Direction;
|
|
@@ -37,7 +37,7 @@ export class Navigator<T = number> {
|
|
|
37
37
|
* in the matrix.
|
|
38
38
|
* @param - - `matrix`: a 2D array representing the grid or map
|
|
39
39
|
*/
|
|
40
|
-
constructor({matrix, turning, onMove, init: {cur, charDir, VISITED}}: NavigatorParams<T>) {
|
|
40
|
+
constructor({ matrix, turning, onMove, init: { cur, charDir, VISITED } }: NavigatorParams<T>) {
|
|
41
41
|
this._matrix = matrix;
|
|
42
42
|
this._cur = cur;
|
|
43
43
|
this._character = new Character(charDir, turning);
|
|
@@ -53,7 +53,7 @@ export class Navigator<T = number> {
|
|
|
53
53
|
*/
|
|
54
54
|
start() {
|
|
55
55
|
while (this.check(this._character.direction) || this.check(this._character.turn().direction)) {
|
|
56
|
-
const {direction} = this._character;
|
|
56
|
+
const { direction } = this._character;
|
|
57
57
|
if (this.check(direction)) {
|
|
58
58
|
this.move(direction);
|
|
59
59
|
} else if (this.check(this._character.turn().direction)) {
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import {PriorityQueue} from './priority-queue';
|
|
9
|
-
import type {Comparator} from '../../types';
|
|
8
|
+
import { PriorityQueue } from './priority-queue';
|
|
9
|
+
import type { Comparator } from '../../types';
|
|
10
10
|
|
|
11
11
|
export class MaxPriorityQueue<E = any> extends PriorityQueue<E> {
|
|
12
12
|
constructor(
|
|
13
|
-
options: {comparator: Comparator<E>; nodes?: E[]} = {
|
|
13
|
+
options: { comparator: Comparator<E>; nodes?: E[] } = {
|
|
14
14
|
comparator: (a: E, b: E) => {
|
|
15
15
|
if (!(typeof a === 'number' && typeof b === 'number')) {
|
|
16
16
|
throw new Error('The a, b params of compare function must be number');
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import {PriorityQueue} from './priority-queue';
|
|
9
|
-
import type {Comparator} from '../../types';
|
|
8
|
+
import { PriorityQueue } from './priority-queue';
|
|
9
|
+
import type { Comparator } from '../../types';
|
|
10
10
|
|
|
11
11
|
export class MinPriorityQueue<E = any> extends PriorityQueue<E> {
|
|
12
12
|
constructor(
|
|
13
|
-
options: {comparator: Comparator<E>; nodes?: E[]} = {
|
|
13
|
+
options: { comparator: Comparator<E>; nodes?: E[] } = {
|
|
14
14
|
comparator: (a: E, b: E) => {
|
|
15
15
|
if (!(typeof a === 'number' && typeof b === 'number')) {
|
|
16
16
|
throw new Error('The a, b params of compare function must be number');
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {Heap} from '../heap';
|
|
10
|
-
import {Comparator} from '../../types';
|
|
9
|
+
import { Heap } from '../heap';
|
|
10
|
+
import { Comparator } from '../../types';
|
|
11
11
|
|
|
12
12
|
export class PriorityQueue<E = any> extends Heap<E> {
|
|
13
|
-
constructor(options: {comparator: Comparator<E>; nodes?: E[]}) {
|
|
13
|
+
constructor(options: { comparator: Comparator<E>; nodes?: E[] }) {
|
|
14
14
|
super(options);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import {DoublyLinkedList} from '../linked-list';
|
|
8
|
+
import { DoublyLinkedList } from '../linked-list';
|
|
9
9
|
|
|
10
10
|
// O(n) time complexity of obtaining the value
|
|
11
11
|
// O(1) time complexity of adding at the beginning and the end
|
|
12
|
-
export class Deque<E = any> extends DoublyLinkedList<E> {
|
|
12
|
+
export class Deque<E = any> extends DoublyLinkedList<E> {
|
|
13
|
+
}
|
|
13
14
|
|
|
14
15
|
// O(1) time complexity of obtaining the value
|
|
15
16
|
// O(n) time complexity of adding at the beginning and the end
|
|
@@ -19,9 +20,9 @@ export class ObjectDeque<E = number> {
|
|
|
19
20
|
if (capacity !== undefined) this._capacity = capacity;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
protected _nodes: {[key: number]: E} = {};
|
|
23
|
+
protected _nodes: { [key: number]: E } = {};
|
|
23
24
|
|
|
24
|
-
get nodes(): {[p: number]: E} {
|
|
25
|
+
get nodes(): { [p: number]: E } {
|
|
25
26
|
return this._nodes;
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
4
4
|
* @class
|
|
5
5
|
*/
|
|
6
|
-
import {SinglyLinkedList} from '../linked-list';
|
|
6
|
+
import { SinglyLinkedList } from '../linked-list';
|
|
7
7
|
|
|
8
8
|
export class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
9
9
|
/**
|
|
@@ -300,7 +300,7 @@ export class Queue<E = any> {
|
|
|
300
300
|
return new Queue(this.nodes.slice(this.offset));
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
-
*[Symbol.iterator]() {
|
|
303
|
+
* [Symbol.iterator]() {
|
|
304
304
|
for (const item of this.nodes) {
|
|
305
305
|
yield item;
|
|
306
306
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {BinaryTreeNode} from '../data-structures';
|
|
2
|
-
import {BinaryTreeNodeNested, BiTreeDeleteResult, BTNCallback, BTNKey} from '../types';
|
|
1
|
+
import { BinaryTreeNode } from '../data-structures';
|
|
2
|
+
import { BinaryTreeNodeNested, BiTreeDeleteResult, BTNCallback, BTNKey } from '../types';
|
|
3
3
|
|
|
4
4
|
export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>> {
|
|
5
5
|
createNode(key: BTNKey, value?: N['value']): N;
|
package/src/interfaces/graph.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {AVLTreeNode} from '../../../data-structures';
|
|
2
|
-
import {BSTOptions} from './bst';
|
|
1
|
+
import { AVLTreeNode } from '../../../data-structures';
|
|
2
|
+
import { BSTOptions } from './bst';
|
|
3
3
|
|
|
4
4
|
export type AVLTreeNodeNested<T> = AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
5
5
|
export type AVLTreeOptions = BSTOptions & {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {BSTNode} from '../../../data-structures';
|
|
2
|
-
import type {BinaryTreeOptions, BTNKey} from './binary-tree';
|
|
1
|
+
import { BSTNode } from '../../../data-structures';
|
|
2
|
+
import type { BinaryTreeOptions, BTNKey } from './binary-tree';
|
|
3
3
|
|
|
4
4
|
export type BSTComparator = (a: BTNKey, b: BTNKey) => number;
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {TreeMultimapNode} from '../../../data-structures';
|
|
2
|
-
import {AVLTreeOptions} from './avl-tree';
|
|
1
|
+
import { TreeMultimapNode } from '../../../data-structures';
|
|
2
|
+
import { AVLTreeOptions } from './avl-tree';
|
|
3
3
|
|
|
4
4
|
export type TreeMultimapNodeNested<T> = TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
5
5
|
|
|
@@ -1 +1,17 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export const enum IterateDirection {
|
|
2
|
+
DEFAULT = 0,
|
|
3
|
+
REVERSE = 1
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export type HashMapOptions<T> = {
|
|
7
|
+
sizeFunction?: number | (() => number);
|
|
8
|
+
fixedLength?: number;
|
|
9
|
+
forEach: (callback: (el: T) => void) => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type HashMapLinkedNode<K, V> = {
|
|
13
|
+
key: K;
|
|
14
|
+
value: V;
|
|
15
|
+
next: HashMapLinkedNode<K, V>;
|
|
16
|
+
prev: HashMapLinkedNode<K, V>;
|
|
17
|
+
};
|
package/src/types/utils/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type ToThunkFn = () => ReturnType<TrlFn>;
|
|
2
|
-
export type Thunk = () => ReturnType<ToThunkFn> & {__THUNK__: symbol};
|
|
2
|
+
export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: symbol };
|
|
3
3
|
export type TrlFn = (...args: any[]) => any;
|
|
4
4
|
export type TrlAsyncFn = (...args: any[]) => any;
|
|
5
5
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type KeyValueObject = {[key: string]: any};
|
|
1
|
+
export type KeyValueObject = { [key: string]: any };
|
|
2
2
|
|
|
3
|
-
export type KeyValueObjectWithKey = {[key: string]: any; key: string | number | symbol};
|
|
3
|
+
export type KeyValueObjectWithKey = { [key: string]: any; key: string | number | symbol };
|
|
4
4
|
|
|
5
5
|
export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
|
|
6
6
|
|
|
@@ -16,6 +16,20 @@ export type ObjectWithNumberKey = {
|
|
|
16
16
|
key: number;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export type RestrictValByKey =
|
|
19
|
+
export type RestrictValByKey =
|
|
20
|
+
| NonNumberNonObjectButDefined
|
|
21
|
+
| ObjectWithoutKey
|
|
22
|
+
| ObjectWithNonNumberKey
|
|
23
|
+
| ObjectWithNumberKey;
|
|
20
24
|
|
|
21
|
-
export type DummyAny =
|
|
25
|
+
export type DummyAny =
|
|
26
|
+
| string
|
|
27
|
+
| number
|
|
28
|
+
| boolean
|
|
29
|
+
| null
|
|
30
|
+
| undefined
|
|
31
|
+
| object
|
|
32
|
+
| symbol
|
|
33
|
+
| void
|
|
34
|
+
| ((...args: []) => any)
|
|
35
|
+
| never;
|
package/src/utils/utils.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type {Thunk, ToThunkFn, TrlAsyncFn, TrlFn} from '../types';
|
|
8
|
+
import type { Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from '../types';
|
|
9
9
|
|
|
10
10
|
export const uuidV4 = function () {
|
|
11
11
|
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
|
|
@@ -57,7 +57,7 @@ export const trampoline = (fn: TrlFn) => {
|
|
|
57
57
|
|
|
58
58
|
return result;
|
|
59
59
|
},
|
|
60
|
-
{cont}
|
|
60
|
+
{ cont }
|
|
61
61
|
);
|
|
62
62
|
};
|
|
63
63
|
|
|
@@ -74,7 +74,7 @@ export const trampolineAsync = (fn: TrlAsyncFn) => {
|
|
|
74
74
|
|
|
75
75
|
return result;
|
|
76
76
|
},
|
|
77
|
-
{cont}
|
|
77
|
+
{ cont }
|
|
78
78
|
);
|
|
79
79
|
};
|
|
80
80
|
|
|
@@ -84,3 +84,16 @@ export const getMSB = (value: number): number => {
|
|
|
84
84
|
}
|
|
85
85
|
return 1 << (31 - Math.clz32(value));
|
|
86
86
|
};
|
|
87
|
+
|
|
88
|
+
export const rangeCheck = (index: number, min: number, max: number, message = 'Index out of bounds.'): void => {
|
|
89
|
+
if (index < min || index > max) throw new RangeError(message);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const throwRangeError = (message = 'The value is off-limits.'): void => {
|
|
93
|
+
throw new RangeError(message);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const isObjOrFunc = (input: unknown): input is Record<string, unknown> | ((...args: any[]) => any) => {
|
|
97
|
+
const inputType = typeof input;
|
|
98
|
+
return (inputType === 'object' && input !== null) || inputType === 'function';
|
|
99
|
+
};
|