graph-typed 1.52.3 → 1.52.5

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 (74) hide show
  1. package/dist/data-structures/base/iterable-element-base.d.ts +1 -37
  2. package/dist/data-structures/base/iterable-element-base.js +1 -37
  3. package/dist/data-structures/base/iterable-entry-base.d.ts +2 -54
  4. package/dist/data-structures/base/iterable-entry-base.js +1 -49
  5. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
  6. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
  7. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -46
  8. package/dist/data-structures/binary-tree/avl-tree.js +0 -46
  9. package/dist/data-structures/binary-tree/binary-tree.d.ts +82 -147
  10. package/dist/data-structures/binary-tree/binary-tree.js +299 -331
  11. package/dist/data-structures/binary-tree/bst.d.ts +1 -40
  12. package/dist/data-structures/binary-tree/bst.js +12 -44
  13. package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -48
  14. package/dist/data-structures/binary-tree/rb-tree.js +2 -50
  15. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
  16. package/dist/data-structures/binary-tree/tree-multi-map.js +9 -41
  17. package/dist/data-structures/graph/abstract-graph.d.ts +0 -75
  18. package/dist/data-structures/graph/abstract-graph.js +0 -75
  19. package/dist/data-structures/graph/directed-graph.d.ts +0 -98
  20. package/dist/data-structures/graph/directed-graph.js +0 -98
  21. package/dist/data-structures/graph/undirected-graph.d.ts +0 -50
  22. package/dist/data-structures/graph/undirected-graph.js +0 -50
  23. package/dist/data-structures/hash/hash-map.d.ts +5 -92
  24. package/dist/data-structures/hash/hash-map.js +29 -115
  25. package/dist/data-structures/heap/heap.d.ts +0 -32
  26. package/dist/data-structures/heap/heap.js +0 -32
  27. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
  28. package/dist/data-structures/linked-list/doubly-linked-list.js +5 -88
  29. package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -83
  30. package/dist/data-structures/linked-list/singly-linked-list.js +2 -84
  31. package/dist/data-structures/linked-list/skip-linked-list.d.ts +1 -35
  32. package/dist/data-structures/linked-list/skip-linked-list.js +1 -35
  33. package/dist/data-structures/queue/deque.d.ts +1 -98
  34. package/dist/data-structures/queue/deque.js +3 -99
  35. package/dist/data-structures/queue/queue.d.ts +5 -58
  36. package/dist/data-structures/queue/queue.js +4 -57
  37. package/dist/data-structures/stack/stack.d.ts +1 -34
  38. package/dist/data-structures/stack/stack.js +1 -34
  39. package/dist/data-structures/tree/tree.js +2 -1
  40. package/dist/data-structures/trie/trie.d.ts +0 -64
  41. package/dist/data-structures/trie/trie.js +0 -64
  42. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
  43. package/dist/types/data-structures/binary-tree/binary-tree.js +6 -0
  44. package/dist/types/utils/utils.d.ts +13 -12
  45. package/dist/utils/number.d.ts +13 -0
  46. package/dist/utils/number.js +13 -0
  47. package/dist/utils/utils.d.ts +125 -3
  48. package/dist/utils/utils.js +177 -21
  49. package/package.json +2 -2
  50. package/src/data-structures/base/iterable-element-base.ts +2 -42
  51. package/src/data-structures/base/iterable-entry-base.ts +3 -62
  52. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
  53. package/src/data-structures/binary-tree/avl-tree.ts +0 -57
  54. package/src/data-structures/binary-tree/binary-tree.ts +329 -358
  55. package/src/data-structures/binary-tree/bst.ts +11 -54
  56. package/src/data-structures/binary-tree/rb-tree.ts +2 -62
  57. package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
  58. package/src/data-structures/graph/abstract-graph.ts +0 -92
  59. package/src/data-structures/graph/directed-graph.ts +0 -122
  60. package/src/data-structures/graph/undirected-graph.ts +0 -62
  61. package/src/data-structures/hash/hash-map.ts +31 -139
  62. package/src/data-structures/heap/heap.ts +0 -40
  63. package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
  64. package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
  65. package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
  66. package/src/data-structures/queue/deque.ts +2 -125
  67. package/src/data-structures/queue/queue.ts +5 -72
  68. package/src/data-structures/stack/stack.ts +1 -43
  69. package/src/data-structures/tree/tree.ts +1 -1
  70. package/src/data-structures/trie/trie.ts +0 -80
  71. package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
  72. package/src/types/utils/utils.ts +17 -15
  73. package/src/utils/number.ts +13 -0
  74. package/src/utils/utils.ts +174 -18
@@ -23,3 +23,11 @@ export type BinaryTreeDeleteResult<NODE> = {
23
23
  needBalanced: OptBTNOrNull<NODE>;
24
24
  };
25
25
  export type BTNCallback<NODE, D = any> = (node: NODE) => D;
26
+ export declare enum DFSOperation {
27
+ VISIT = 0,
28
+ PROCESS = 1
29
+ }
30
+ export type DFSStackItem<NODE> = {
31
+ opt: DFSOperation;
32
+ node: OptBTNOrNull<NODE>;
33
+ };
@@ -1,2 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DFSOperation = void 0;
4
+ var DFSOperation;
5
+ (function (DFSOperation) {
6
+ DFSOperation[DFSOperation["VISIT"] = 0] = "VISIT";
7
+ DFSOperation[DFSOperation["PROCESS"] = 1] = "PROCESS";
8
+ })(DFSOperation = exports.DFSOperation || (exports.DFSOperation = {}));
@@ -1,17 +1,18 @@
1
- export type ToThunkFn = () => ReturnType<TrlFn>;
2
- export type Thunk = () => ReturnType<ToThunkFn> & {
3
- __THUNK__: symbol;
1
+ export type ToThunkFn<R = any> = () => R;
2
+ export type Thunk<R = any> = ToThunkFn<R> & {
3
+ __THUNK__?: symbol;
4
4
  };
5
- export type TrlFn = (...args: any[]) => any;
5
+ export type TrlFn<A extends any[] = any[], R = any> = (...args: A) => R;
6
6
  export type TrlAsyncFn = (...args: any[]) => any;
7
7
  export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
8
8
  export type Any = string | number | bigint | boolean | symbol | undefined | object;
9
- export type Comparable = number | string | bigint | boolean | ({
9
+ export type ComparablePrimitive = number | bigint | string | boolean;
10
+ export type ComparableObject = {
10
11
  [key in string]: any;
11
- } & {
12
- valueOf(): Comparable;
13
- }) | ({
14
- [key in string]: any;
15
- } & {
16
- toString(): Comparable;
17
- }) | (() => Comparable);
12
+ } & ({
13
+ valueOf: () => ComparablePrimitive | ComparableObject;
14
+ toString?: () => string;
15
+ } | {
16
+ toString: () => string;
17
+ });
18
+ export type Comparable = ComparablePrimitive | Date | ComparableObject;
@@ -1 +1,14 @@
1
+ /**
2
+ * The function `toBinaryString` converts a number to a binary string representation with a specified
3
+ * number of digits.
4
+ * @param {number} num - The `num` parameter in the `toBinaryString` function represents the number
5
+ * that you want to convert to a binary string.
6
+ * @param [digit=32] - The `digit` parameter in the `toBinaryString` function represents the number of
7
+ * digits the binary string should have. By default, it is set to 32, meaning that the binary string
8
+ * will be padded with zeros at the beginning to ensure it is 32 bits long. You can provide a
9
+ * @returns The function `toBinaryString` takes a number as input and converts it to a binary string
10
+ * representation with a specified number of digits (default is 32). The binary string is padded with
11
+ * zeros at the beginning to ensure it has the specified number of digits. The function returns the
12
+ * binary string representation of the input number.
13
+ */
1
14
  export declare function toBinaryString(num: number, digit?: number): string;
@@ -1,6 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toBinaryString = void 0;
4
+ /**
5
+ * The function `toBinaryString` converts a number to a binary string representation with a specified
6
+ * number of digits.
7
+ * @param {number} num - The `num` parameter in the `toBinaryString` function represents the number
8
+ * that you want to convert to a binary string.
9
+ * @param [digit=32] - The `digit` parameter in the `toBinaryString` function represents the number of
10
+ * digits the binary string should have. By default, it is set to 32, meaning that the binary string
11
+ * will be padded with zeros at the beginning to ensure it is 32 bits long. You can provide a
12
+ * @returns The function `toBinaryString` takes a number as input and converts it to a binary string
13
+ * representation with a specified number of digits (default is 32). The binary string is padded with
14
+ * zeros at the beginning to ensure it has the specified number of digits. The function returns the
15
+ * binary string representation of the input number.
16
+ */
4
17
  function toBinaryString(num, digit = 32) {
5
18
  // Convert number to binary string
6
19
  let binaryString = (num >>> 0).toString(2); // Use the unsigned right shift operator to ensure you get a binary representation of a 32-bit unsigned integer
@@ -6,21 +6,143 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import type { Comparable, Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from '../types';
9
+ /**
10
+ * The function generates a random UUID (Universally Unique Identifier) in TypeScript.
11
+ * @returns A randomly generated UUID (Universally Unique Identifier) in the format
12
+ * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' where each 'x' is replaced with a random hexadecimal
13
+ * character.
14
+ */
9
15
  export declare const uuidV4: () => string;
16
+ /**
17
+ * The `arrayRemove` function removes elements from an array based on a specified predicate function
18
+ * and returns the removed elements.
19
+ * @param {T[]} array - An array of elements that you want to filter based on the provided predicate
20
+ * function.
21
+ * @param predicate - The `predicate` parameter is a function that takes three arguments:
22
+ * @returns The `arrayRemove` function returns an array containing the elements that satisfy the given
23
+ * `predicate` function.
24
+ */
10
25
  export declare const arrayRemove: <T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean) => T[];
11
26
  export declare const THUNK_SYMBOL: unique symbol;
27
+ /**
28
+ * The function `isThunk` checks if a given value is a function with a specific symbol property.
29
+ * @param {any} fnOrValue - The `fnOrValue` parameter in the `isThunk` function can be either a
30
+ * function or a value that you want to check if it is a thunk. Thunks are functions that are wrapped
31
+ * around a value or computation for lazy evaluation. The function checks if the `fnOrValue` is
32
+ * @returns The function `isThunk` is checking if the input `fnOrValue` is a function and if it has a
33
+ * property `__THUNK__` equal to `THUNK_SYMBOL`. The return value will be `true` if both conditions are
34
+ * met, otherwise it will be `false`.
35
+ */
12
36
  export declare const isThunk: (fnOrValue: any) => boolean;
37
+ /**
38
+ * The `toThunk` function in TypeScript converts a function into a thunk by wrapping it in a closure.
39
+ * @param {ToThunkFn} fn - `fn` is a function that will be converted into a thunk.
40
+ * @returns A thunk function is being returned. Thunk functions are functions that delay the evaluation
41
+ * of an expression or operation until it is explicitly called or invoked. In this case, the `toThunk`
42
+ * function takes a function `fn` as an argument and returns a thunk function that, when called, will
43
+ * execute the `fn` function provided as an argument.
44
+ */
13
45
  export declare const toThunk: (fn: ToThunkFn) => Thunk;
46
+ /**
47
+ * The `trampoline` function in TypeScript enables tail call optimization by using thunks to avoid
48
+ * stack overflow.
49
+ * @param {TrlFn} fn - The `fn` parameter in the `trampoline` function is a function that takes any
50
+ * number of arguments and returns a value.
51
+ * @returns The `trampoline` function returns an object with two properties:
52
+ * 1. A function that executes the provided function `fn` and continues to execute any thunks returned
53
+ * by `fn` until a non-thunk value is returned.
54
+ * 2. A `cont` property that is a function which creates a thunk for the provided function `fn`.
55
+ */
14
56
  export declare const trampoline: (fn: TrlFn) => ((...args: [...Parameters<TrlFn>]) => any) & {
15
- cont: (...args: [...Parameters<TrlFn>]) => Thunk;
57
+ cont: (...args: [...Parameters<TrlFn>]) => ReturnType<TrlFn>;
16
58
  };
59
+ /**
60
+ * The `trampolineAsync` function in TypeScript allows for asynchronous trampolining of a given
61
+ * function.
62
+ * @param {TrlAsyncFn} fn - The `fn` parameter in the `trampolineAsync` function is expected to be a
63
+ * function that returns a Promise. This function will be called recursively until a non-thunk value is
64
+ * returned.
65
+ * @returns The `trampolineAsync` function returns an object with two properties:
66
+ * 1. An async function that executes the provided `TrlAsyncFn` function and continues to execute any
67
+ * thunks returned by the function until a non-thunk value is returned.
68
+ * 2. A `cont` property that is a function which wraps the provided `TrlAsyncFn` function in a thunk
69
+ * and returns it.
70
+ */
17
71
  export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Parameters<TrlAsyncFn>]) => Promise<any>) & {
18
- cont: (...args: [...Parameters<TrlAsyncFn>]) => Thunk;
72
+ cont: (...args: [...Parameters<TrlAsyncFn>]) => ReturnType<TrlAsyncFn>;
19
73
  };
74
+ /**
75
+ * The function `getMSB` returns the most significant bit of a given number.
76
+ * @param {number} value - The `value` parameter is a number for which we want to find the position of
77
+ * the Most Significant Bit (MSB). The function `getMSB` takes this number as input and calculates the
78
+ * position of the MSB in its binary representation.
79
+ * @returns The function `getMSB` returns the most significant bit (MSB) of the input `value`. If the
80
+ * input value is less than or equal to 0, it returns 0. Otherwise, it calculates the position of the
81
+ * MSB using the `Math.clz32` function and bitwise left shifts 1 to that position.
82
+ */
20
83
  export declare const getMSB: (value: number) => number;
84
+ /**
85
+ * The `rangeCheck` function in TypeScript is used to validate if an index is within a specified range
86
+ * and throws a `RangeError` with a custom message if it is out of bounds.
87
+ * @param {number} index - The `index` parameter represents the value that you want to check if it
88
+ * falls within a specified range.
89
+ * @param {number} min - The `min` parameter represents the minimum value that the `index` should be
90
+ * compared against in the `rangeCheck` function.
91
+ * @param {number} max - The `max` parameter in the `rangeCheck` function represents the maximum value
92
+ * that the `index` parameter is allowed to have. If the `index` is greater than this `max` value, a
93
+ * `RangeError` will be thrown.
94
+ * @param [message=Index out of bounds.] - The `message` parameter is a string that represents the
95
+ * error message to be thrown if the index is out of bounds. By default, if no message is provided when
96
+ * calling the `rangeCheck` function, the message "Index out of bounds." will be used.
97
+ */
21
98
  export declare const rangeCheck: (index: number, min: number, max: number, message?: string) => void;
99
+ /**
100
+ * The function `throwRangeError` throws a RangeError with a custom message if called.
101
+ * @param [message=The value is off-limits.] - The `message` parameter is a string that represents the
102
+ * error message to be displayed when a `RangeError` is thrown. If no message is provided, the default
103
+ * message is 'The value is off-limits.'.
104
+ */
22
105
  export declare const throwRangeError: (message?: string) => void;
106
+ /**
107
+ * The function `isWeakKey` checks if the input is an object or a function in TypeScript.
108
+ * @param {unknown} input - The `input` parameter in the `isWeakKey` function is of type `unknown`,
109
+ * which means it can be any type. The function checks if the `input` is an object (excluding `null`)
110
+ * or a function, and returns a boolean indicating whether the `input` is a weak
111
+ * @returns The function `isWeakKey` returns a boolean value indicating whether the input is an object
112
+ * or a function.
113
+ */
23
114
  export declare const isWeakKey: (input: unknown) => input is object;
115
+ /**
116
+ * The function `calcMinUnitsRequired` calculates the minimum number of units required to accommodate a
117
+ * given total quantity based on a specified unit size.
118
+ * @param {number} totalQuantity - The `totalQuantity` parameter represents the total quantity of items
119
+ * that need to be processed or handled.
120
+ * @param {number} unitSize - The `unitSize` parameter represents the size of each unit or package. It
121
+ * is used in the `calcMinUnitsRequired` function to calculate the minimum number of units required to
122
+ * accommodate a total quantity of items.
123
+ */
24
124
  export declare const calcMinUnitsRequired: (totalQuantity: number, unitSize: number) => number;
125
+ /**
126
+ * The `roundFixed` function in TypeScript rounds a number to a specified number of decimal places.
127
+ * @param {number} num - The `num` parameter is a number that you want to round to a certain number of
128
+ * decimal places.
129
+ * @param {number} [digit=10] - The `digit` parameter in the `roundFixed` function specifies the number
130
+ * of decimal places to round the number to. By default, it is set to 10 if not provided explicitly.
131
+ * @returns The function `roundFixed` returns a number that is rounded to the specified number of
132
+ * decimal places (default is 10 decimal places).
133
+ */
25
134
  export declare const roundFixed: (num: number, digit?: number) => number;
26
- export declare function isComparable(key: any): key is Comparable;
135
+ /**
136
+ * The function `isComparable` in TypeScript checks if a value is comparable, handling primitive values
137
+ * and objects with optional force comparison.
138
+ * @param {unknown} value - The `value` parameter in the `isComparable` function represents the value
139
+ * that you want to check if it is comparable. It can be of any type (`unknown`), and the function will
140
+ * determine if it is comparable based on certain conditions.
141
+ * @param [isForceObjectComparable=false] - The `isForceObjectComparable` parameter in the
142
+ * `isComparable` function is a boolean flag that determines whether to treat non-primitive values as
143
+ * comparable objects. When set to `true`, it forces the function to consider non-primitive values as
144
+ * comparable objects, regardless of their type.
145
+ * @returns The function `isComparable` returns a boolean value indicating whether the `value` is
146
+ * considered comparable or not.
147
+ */
148
+ export declare function isComparable(value: unknown, isForceObjectComparable?: boolean): value is Comparable;
@@ -10,6 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.isComparable = exports.roundFixed = exports.calcMinUnitsRequired = exports.isWeakKey = exports.throwRangeError = exports.rangeCheck = exports.getMSB = exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.arrayRemove = exports.uuidV4 = void 0;
13
+ /**
14
+ * The function generates a random UUID (Universally Unique Identifier) in TypeScript.
15
+ * @returns A randomly generated UUID (Universally Unique Identifier) in the format
16
+ * 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' where each 'x' is replaced with a random hexadecimal
17
+ * character.
18
+ */
13
19
  const uuidV4 = function () {
14
20
  return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
15
21
  const r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
@@ -17,6 +23,15 @@ const uuidV4 = function () {
17
23
  });
18
24
  };
19
25
  exports.uuidV4 = uuidV4;
26
+ /**
27
+ * The `arrayRemove` function removes elements from an array based on a specified predicate function
28
+ * and returns the removed elements.
29
+ * @param {T[]} array - An array of elements that you want to filter based on the provided predicate
30
+ * function.
31
+ * @param predicate - The `predicate` parameter is a function that takes three arguments:
32
+ * @returns The `arrayRemove` function returns an array containing the elements that satisfy the given
33
+ * `predicate` function.
34
+ */
20
35
  const arrayRemove = function (array, predicate) {
21
36
  let i = -1, len = array ? array.length : 0;
22
37
  const result = [];
@@ -32,16 +47,43 @@ const arrayRemove = function (array, predicate) {
32
47
  };
33
48
  exports.arrayRemove = arrayRemove;
34
49
  exports.THUNK_SYMBOL = Symbol('thunk');
50
+ /**
51
+ * The function `isThunk` checks if a given value is a function with a specific symbol property.
52
+ * @param {any} fnOrValue - The `fnOrValue` parameter in the `isThunk` function can be either a
53
+ * function or a value that you want to check if it is a thunk. Thunks are functions that are wrapped
54
+ * around a value or computation for lazy evaluation. The function checks if the `fnOrValue` is
55
+ * @returns The function `isThunk` is checking if the input `fnOrValue` is a function and if it has a
56
+ * property `__THUNK__` equal to `THUNK_SYMBOL`. The return value will be `true` if both conditions are
57
+ * met, otherwise it will be `false`.
58
+ */
35
59
  const isThunk = (fnOrValue) => {
36
60
  return typeof fnOrValue === 'function' && fnOrValue.__THUNK__ === exports.THUNK_SYMBOL;
37
61
  };
38
62
  exports.isThunk = isThunk;
63
+ /**
64
+ * The `toThunk` function in TypeScript converts a function into a thunk by wrapping it in a closure.
65
+ * @param {ToThunkFn} fn - `fn` is a function that will be converted into a thunk.
66
+ * @returns A thunk function is being returned. Thunk functions are functions that delay the evaluation
67
+ * of an expression or operation until it is explicitly called or invoked. In this case, the `toThunk`
68
+ * function takes a function `fn` as an argument and returns a thunk function that, when called, will
69
+ * execute the `fn` function provided as an argument.
70
+ */
39
71
  const toThunk = (fn) => {
40
72
  const thunk = () => fn();
41
73
  thunk.__THUNK__ = exports.THUNK_SYMBOL;
42
74
  return thunk;
43
75
  };
44
76
  exports.toThunk = toThunk;
77
+ /**
78
+ * The `trampoline` function in TypeScript enables tail call optimization by using thunks to avoid
79
+ * stack overflow.
80
+ * @param {TrlFn} fn - The `fn` parameter in the `trampoline` function is a function that takes any
81
+ * number of arguments and returns a value.
82
+ * @returns The `trampoline` function returns an object with two properties:
83
+ * 1. A function that executes the provided function `fn` and continues to execute any thunks returned
84
+ * by `fn` until a non-thunk value is returned.
85
+ * 2. A `cont` property that is a function which creates a thunk for the provided function `fn`.
86
+ */
45
87
  const trampoline = (fn) => {
46
88
  const cont = (...args) => (0, exports.toThunk)(() => fn(...args));
47
89
  return Object.assign((...args) => {
@@ -53,6 +95,18 @@ const trampoline = (fn) => {
53
95
  }, { cont });
54
96
  };
55
97
  exports.trampoline = trampoline;
98
+ /**
99
+ * The `trampolineAsync` function in TypeScript allows for asynchronous trampolining of a given
100
+ * function.
101
+ * @param {TrlAsyncFn} fn - The `fn` parameter in the `trampolineAsync` function is expected to be a
102
+ * function that returns a Promise. This function will be called recursively until a non-thunk value is
103
+ * returned.
104
+ * @returns The `trampolineAsync` function returns an object with two properties:
105
+ * 1. An async function that executes the provided `TrlAsyncFn` function and continues to execute any
106
+ * thunks returned by the function until a non-thunk value is returned.
107
+ * 2. A `cont` property that is a function which wraps the provided `TrlAsyncFn` function in a thunk
108
+ * and returns it.
109
+ */
56
110
  const trampolineAsync = (fn) => {
57
111
  const cont = (...args) => (0, exports.toThunk)(() => fn(...args));
58
112
  return Object.assign((...args) => __awaiter(void 0, void 0, void 0, function* () {
@@ -64,6 +118,15 @@ const trampolineAsync = (fn) => {
64
118
  }), { cont });
65
119
  };
66
120
  exports.trampolineAsync = trampolineAsync;
121
+ /**
122
+ * The function `getMSB` returns the most significant bit of a given number.
123
+ * @param {number} value - The `value` parameter is a number for which we want to find the position of
124
+ * the Most Significant Bit (MSB). The function `getMSB` takes this number as input and calculates the
125
+ * position of the MSB in its binary representation.
126
+ * @returns The function `getMSB` returns the most significant bit (MSB) of the input `value`. If the
127
+ * input value is less than or equal to 0, it returns 0. Otherwise, it calculates the position of the
128
+ * MSB using the `Math.clz32` function and bitwise left shifts 1 to that position.
129
+ */
67
130
  const getMSB = (value) => {
68
131
  if (value <= 0) {
69
132
  return 0;
@@ -71,50 +134,143 @@ const getMSB = (value) => {
71
134
  return 1 << (31 - Math.clz32(value));
72
135
  };
73
136
  exports.getMSB = getMSB;
137
+ /**
138
+ * The `rangeCheck` function in TypeScript is used to validate if an index is within a specified range
139
+ * and throws a `RangeError` with a custom message if it is out of bounds.
140
+ * @param {number} index - The `index` parameter represents the value that you want to check if it
141
+ * falls within a specified range.
142
+ * @param {number} min - The `min` parameter represents the minimum value that the `index` should be
143
+ * compared against in the `rangeCheck` function.
144
+ * @param {number} max - The `max` parameter in the `rangeCheck` function represents the maximum value
145
+ * that the `index` parameter is allowed to have. If the `index` is greater than this `max` value, a
146
+ * `RangeError` will be thrown.
147
+ * @param [message=Index out of bounds.] - The `message` parameter is a string that represents the
148
+ * error message to be thrown if the index is out of bounds. By default, if no message is provided when
149
+ * calling the `rangeCheck` function, the message "Index out of bounds." will be used.
150
+ */
74
151
  const rangeCheck = (index, min, max, message = 'Index out of bounds.') => {
75
152
  if (index < min || index > max)
76
153
  throw new RangeError(message);
77
154
  };
78
155
  exports.rangeCheck = rangeCheck;
156
+ /**
157
+ * The function `throwRangeError` throws a RangeError with a custom message if called.
158
+ * @param [message=The value is off-limits.] - The `message` parameter is a string that represents the
159
+ * error message to be displayed when a `RangeError` is thrown. If no message is provided, the default
160
+ * message is 'The value is off-limits.'.
161
+ */
79
162
  const throwRangeError = (message = 'The value is off-limits.') => {
80
163
  throw new RangeError(message);
81
164
  };
82
165
  exports.throwRangeError = throwRangeError;
166
+ /**
167
+ * The function `isWeakKey` checks if the input is an object or a function in TypeScript.
168
+ * @param {unknown} input - The `input` parameter in the `isWeakKey` function is of type `unknown`,
169
+ * which means it can be any type. The function checks if the `input` is an object (excluding `null`)
170
+ * or a function, and returns a boolean indicating whether the `input` is a weak
171
+ * @returns The function `isWeakKey` returns a boolean value indicating whether the input is an object
172
+ * or a function.
173
+ */
83
174
  const isWeakKey = (input) => {
84
175
  const inputType = typeof input;
85
176
  return (inputType === 'object' && input !== null) || inputType === 'function';
86
177
  };
87
178
  exports.isWeakKey = isWeakKey;
179
+ /**
180
+ * The function `calcMinUnitsRequired` calculates the minimum number of units required to accommodate a
181
+ * given total quantity based on a specified unit size.
182
+ * @param {number} totalQuantity - The `totalQuantity` parameter represents the total quantity of items
183
+ * that need to be processed or handled.
184
+ * @param {number} unitSize - The `unitSize` parameter represents the size of each unit or package. It
185
+ * is used in the `calcMinUnitsRequired` function to calculate the minimum number of units required to
186
+ * accommodate a total quantity of items.
187
+ */
88
188
  const calcMinUnitsRequired = (totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize);
89
189
  exports.calcMinUnitsRequired = calcMinUnitsRequired;
190
+ /**
191
+ * The `roundFixed` function in TypeScript rounds a number to a specified number of decimal places.
192
+ * @param {number} num - The `num` parameter is a number that you want to round to a certain number of
193
+ * decimal places.
194
+ * @param {number} [digit=10] - The `digit` parameter in the `roundFixed` function specifies the number
195
+ * of decimal places to round the number to. By default, it is set to 10 if not provided explicitly.
196
+ * @returns The function `roundFixed` returns a number that is rounded to the specified number of
197
+ * decimal places (default is 10 decimal places).
198
+ */
90
199
  const roundFixed = (num, digit = 10) => {
91
200
  const multiplier = Math.pow(10, digit);
92
201
  return Math.round(num * multiplier) / multiplier;
93
202
  };
94
203
  exports.roundFixed = roundFixed;
95
- function isComparable(key) {
96
- const keyType = typeof key;
97
- if (keyType === 'number')
98
- return !isNaN(key);
99
- if (keyType === 'string')
100
- return true;
101
- if (keyType === 'bigint')
102
- return true;
103
- if (keyType === 'boolean')
104
- return true;
105
- if (keyType === 'symbol')
204
+ /**
205
+ * The function `isPrimitiveComparable` checks if a value is a primitive type that can be compared.
206
+ * @param {unknown} value - The `value` parameter in the `isPrimitiveComparable` function is of type
207
+ * `unknown`, which means it can be any type. The function checks if the `value` is a primitive type
208
+ * that can be compared, such as number, bigint, string, or boolean.
209
+ * @returns The function `isPrimitiveComparable` returns a boolean value indicating whether the input
210
+ * `value` is a primitive value that can be compared using standard comparison operators (<, >, <=,
211
+ * >=).
212
+ */
213
+ function isPrimitiveComparable(value) {
214
+ const valueType = typeof value;
215
+ if (valueType === 'number')
216
+ return !Number.isNaN(value);
217
+ return valueType === 'bigint' || valueType === 'string' || valueType === 'boolean';
218
+ }
219
+ /**
220
+ * The function `tryObjectToPrimitive` attempts to convert an object to a comparable primitive value by
221
+ * first checking the `valueOf` method and then the `toString` method.
222
+ * @param {object} obj - The `obj` parameter in the `tryObjectToPrimitive` function is an object that
223
+ * you want to convert to a primitive value. The function attempts to convert the object to a primitive
224
+ * value by first checking if the object has a `valueOf` method. If the `valueOf` method exists, it
225
+ * @returns The function `tryObjectToPrimitive` returns a value of type `ComparablePrimitive` if a
226
+ * primitive comparable value is found within the object, or a string value if the object has a custom
227
+ * `toString` method that does not return `'[object Object]'`. If neither condition is met, the
228
+ * function returns `null`.
229
+ */
230
+ function tryObjectToPrimitive(obj) {
231
+ if (typeof obj.valueOf === 'function') {
232
+ const valueOfResult = obj.valueOf();
233
+ if (valueOfResult !== obj) {
234
+ if (isPrimitiveComparable(valueOfResult))
235
+ return valueOfResult;
236
+ if (typeof valueOfResult === 'object' && valueOfResult !== null)
237
+ return tryObjectToPrimitive(valueOfResult);
238
+ }
239
+ }
240
+ if (typeof obj.toString === 'function') {
241
+ const stringResult = obj.toString();
242
+ if (stringResult !== '[object Object]')
243
+ return stringResult;
244
+ }
245
+ return null;
246
+ }
247
+ /**
248
+ * The function `isComparable` in TypeScript checks if a value is comparable, handling primitive values
249
+ * and objects with optional force comparison.
250
+ * @param {unknown} value - The `value` parameter in the `isComparable` function represents the value
251
+ * that you want to check if it is comparable. It can be of any type (`unknown`), and the function will
252
+ * determine if it is comparable based on certain conditions.
253
+ * @param [isForceObjectComparable=false] - The `isForceObjectComparable` parameter in the
254
+ * `isComparable` function is a boolean flag that determines whether to treat non-primitive values as
255
+ * comparable objects. When set to `true`, it forces the function to consider non-primitive values as
256
+ * comparable objects, regardless of their type.
257
+ * @returns The function `isComparable` returns a boolean value indicating whether the `value` is
258
+ * considered comparable or not.
259
+ */
260
+ function isComparable(value, isForceObjectComparable = false) {
261
+ if (value === null || value === undefined)
106
262
  return false;
107
- if (keyType === 'undefined')
263
+ if (isPrimitiveComparable(value))
264
+ return true;
265
+ if (typeof value !== 'object')
108
266
  return false;
109
- if (keyType === 'function')
110
- return isComparable(key());
111
- if (keyType === 'object') {
112
- if (key === null)
113
- return true;
114
- // if (typeof key.valueOf === 'function') return isComparable(key.valueOf()); // This will keep recursing because every object has a valueOf method.
115
- // if (typeof key.toString === 'function') return isComparable(key.toString()); // This will also keep recursing because every string type has a toString method.
267
+ if (value instanceof Date)
268
+ return !Number.isNaN(value.getTime());
269
+ if (isForceObjectComparable)
270
+ return true;
271
+ const comparableValue = tryObjectToPrimitive(value);
272
+ if (comparableValue === null || comparableValue === undefined)
116
273
  return false;
117
- }
118
- return false;
274
+ return isPrimitiveComparable(comparableValue);
119
275
  }
120
276
  exports.isComparable = isComparable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graph-typed",
3
- "version": "1.52.3",
3
+ "version": "1.52.5",
4
4
  "description": "Graph. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -136,6 +136,6 @@
136
136
  "typescript": "^4.9.5"
137
137
  },
138
138
  "dependencies": {
139
- "data-structure-typed": "^1.52.3"
139
+ "data-structure-typed": "^1.52.5"
140
140
  }
141
141
  }
@@ -29,10 +29,6 @@ export abstract class IterableElementBase<E, R, C> {
29
29
  return this._toElementFn;
30
30
  }
31
31
 
32
- /**
33
- * Time Complexity: O(n)
34
- * Space Complexity: O(1)
35
- */
36
32
  /**
37
33
  * Time Complexity: O(n)
38
34
  * Space Complexity: O(1)
@@ -46,10 +42,6 @@ export abstract class IterableElementBase<E, R, C> {
46
42
  yield* this._getIterator(...args);
47
43
  }
48
44
 
49
- /**
50
- * Time Complexity: O(n)
51
- * Space Complexity: O(n)
52
- */
53
45
  /**
54
46
  * Time Complexity: O(n)
55
47
  * Space Complexity: O(n)
@@ -62,10 +54,6 @@ export abstract class IterableElementBase<E, R, C> {
62
54
  }
63
55
  }
64
56
 
65
- /**
66
- * Time Complexity: O(n)
67
- * Space Complexity: O(1)
68
- */
69
57
  /**
70
58
  * Time Complexity: O(n)
71
59
  * Space Complexity: O(1)
@@ -90,15 +78,6 @@ export abstract class IterableElementBase<E, R, C> {
90
78
  return true;
91
79
  }
92
80
 
93
- /**
94
- * Time Complexity: O(n)
95
- * Space Complexity: O(1)
96
- */
97
-
98
- /**
99
- * Time Complexity: O(n)
100
- * Space Complexity: O(1)
101
- */
102
81
  /**
103
82
  * Time Complexity: O(n)
104
83
  * Space Complexity: O(1)
@@ -123,11 +102,6 @@ export abstract class IterableElementBase<E, R, C> {
123
102
  return false;
124
103
  }
125
104
 
126
- /**
127
- * Time Complexity: O(n)
128
- * Space Complexity: O(1)
129
- */
130
-
131
105
  /**
132
106
  * Time Complexity: O(n)
133
107
  * Space Complexity: O(1)
@@ -148,11 +122,6 @@ export abstract class IterableElementBase<E, R, C> {
148
122
  }
149
123
  }
150
124
 
151
- /**
152
- * Time Complexity: O(n)
153
- * Space Complexity: O(1)
154
- */
155
-
156
125
  /**
157
126
  * Time Complexity: O(n)
158
127
  * Space Complexity: O(1)
@@ -195,10 +164,6 @@ export abstract class IterableElementBase<E, R, C> {
195
164
  return false;
196
165
  }
197
166
 
198
- /**
199
- * Time Complexity: O(n)
200
- * Space Complexity: O(1)
201
- */
202
167
  /**
203
168
  * Time Complexity: O(n)
204
169
  * Space Complexity: O(1)
@@ -221,19 +186,14 @@ export abstract class IterableElementBase<E, R, C> {
221
186
  return accumulator;
222
187
  }
223
188
 
224
- /**
225
- * Time Complexity: O(n)
226
- * Space Complexity: O(n)
227
- */
228
-
229
189
  /**
230
190
  * Time Complexity: O(n)
231
191
  * Space Complexity: O(n)
232
192
  *
233
193
  * The print function logs the elements of an array to the console.
234
194
  */
235
- print(): void {
236
- console.log([...this]);
195
+ print(): E[] {
196
+ return [...this];
237
197
  }
238
198
 
239
199
  abstract isEmpty(): boolean;