@dereekb/util 12.1.0 → 12.1.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/fetch/package.json +1 -1
- package/index.cjs.js +253 -54
- package/index.esm.js +253 -55
- package/package.json +1 -1
- package/src/lib/boolean.d.ts +26 -22
- package/src/lib/date/date.d.ts +26 -1
- package/src/lib/date/time.d.ts +5 -1
- package/src/lib/hash.d.ts +32 -0
- package/src/lib/misc/host.d.ts +11 -4
- package/src/lib/set/set.allowed.d.ts +2 -2
- package/src/lib/storage/storage.d.ts +32 -4
- package/src/lib/storage/storage.error.d.ts +24 -0
- package/src/lib/storage/storage.memory.d.ts +39 -0
- package/src/lib/storage/storage.object.d.ts +42 -0
- package/src/lib/string/password.d.ts +3 -0
- package/src/lib/string/transform.d.ts +90 -26
- package/src/lib/tree/tree.array.d.ts +15 -4
- package/src/lib/tree/tree.d.ts +18 -2
- package/src/lib/tree/tree.expand.d.ts +45 -12
- package/src/lib/tree/tree.flatten.d.ts +21 -1
- package/test/CHANGELOG.md +4 -0
- package/test/package.json +1 -1
package/src/lib/tree/tree.d.ts
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Represents a node in a traversable tree structure.
|
|
3
|
+
*
|
|
4
|
+
* @template T The type of the value stored within the node.
|
|
5
|
+
* @template N The specific type of the tree node itself, allowing for recursive type definitions
|
|
6
|
+
* for `parent` and `children` properties. Defaults to `TreeNode<T, any>` if not specified,
|
|
7
|
+
* which is suitable for basic trees but can be overridden for custom node types.
|
|
3
8
|
*/
|
|
4
9
|
export interface TreeNode<T, N extends TreeNode<T, N> = TreeNode<T, any>> {
|
|
10
|
+
/** The depth of the node in the tree. The root node has a depth of 0. */
|
|
5
11
|
depth: number;
|
|
12
|
+
/** The value associated with this tree node. */
|
|
6
13
|
value: T;
|
|
14
|
+
/** A reference to the parent node, or undefined if this is the root node. */
|
|
7
15
|
parent?: N;
|
|
16
|
+
/** An array of child nodes, or undefined if this node has no children. */
|
|
8
17
|
children?: N[];
|
|
9
18
|
}
|
|
10
19
|
/**
|
|
11
|
-
* A
|
|
20
|
+
* A utility type representing a TreeNode before its children have been attached.
|
|
21
|
+
* This is often used during the tree construction process where a node is created
|
|
22
|
+
* and then its children are recursively generated and linked.
|
|
23
|
+
*
|
|
24
|
+
* It omits the 'children' property from the standard TreeNode interface.
|
|
25
|
+
*
|
|
26
|
+
* @template T The type of the value stored within the node.
|
|
27
|
+
* @template N The specific type of the tree node, as in TreeNode.
|
|
12
28
|
*/
|
|
13
29
|
export type TreeNodeWithoutChildren<T, N extends TreeNode<T, N> = TreeNode<T, any>> = Omit<TreeNode<T, N>, 'children'>;
|
|
@@ -1,40 +1,73 @@
|
|
|
1
1
|
import { type TreeNode, type TreeNodeWithoutChildren } from './tree';
|
|
2
2
|
import { type Maybe } from '../value/maybe.type';
|
|
3
3
|
/**
|
|
4
|
-
* ExpandTreeFunction
|
|
4
|
+
* Configuration for an ExpandTreeFunction, defining how to retrieve child values for a given value.
|
|
5
|
+
*
|
|
6
|
+
* @template T The type of the value being processed at each node in the tree.
|
|
5
7
|
*/
|
|
6
8
|
export interface ExpandTree<T> {
|
|
7
9
|
/**
|
|
8
|
-
* Returns child values from the value, if they exist.
|
|
9
|
-
*
|
|
10
|
+
* Returns child values from the input value, if they exist.
|
|
11
|
+
* These child values will be recursively processed to form child nodes.
|
|
12
|
+
*
|
|
13
|
+
* @param value The current value of type T to retrieve children for.
|
|
14
|
+
* @returns An array of child values of type T, or undefined/null if no children exist.
|
|
10
15
|
*/
|
|
11
16
|
getChildren(value: T): Maybe<T[]>;
|
|
12
17
|
}
|
|
13
18
|
/**
|
|
14
|
-
* Extended ExpandTree configuration
|
|
19
|
+
* Extended ExpandTree configuration that includes a custom node builder.
|
|
20
|
+
* This allows for creating tree nodes of a specific type N, potentially with additional properties beyond the basic TreeNode structure.
|
|
21
|
+
*
|
|
22
|
+
* @template T The type of the value being processed at each node.
|
|
23
|
+
* @template N The specific type of TreeNode to be created. Must extend TreeNode<T, N>.
|
|
15
24
|
*/
|
|
16
25
|
export interface ExpandTreeWithNodeBuilder<T, N extends TreeNode<T, N>> extends ExpandTree<T> {
|
|
17
26
|
/**
|
|
18
|
-
* Creates a
|
|
27
|
+
* Creates a tree node of type N (omitting the 'children' property, which is attached later).
|
|
28
|
+
* This function is called for each value being converted into a node in the tree.
|
|
29
|
+
*
|
|
30
|
+
* @param node A TreeNodeWithoutChildren<T, N> object containing the core properties (value, depth, parent).
|
|
31
|
+
* @returns An object of type Omit<N, 'children'>, representing the custom-built node without its children.
|
|
19
32
|
*/
|
|
20
33
|
makeNode: (node: TreeNodeWithoutChildren<T, N>) => Omit<N, 'children'>;
|
|
21
34
|
}
|
|
22
35
|
/**
|
|
23
|
-
*
|
|
36
|
+
* A function that expands an input value of type T into a TreeNode of type N.
|
|
37
|
+
*
|
|
38
|
+
* @template T The type of the input value to expand.
|
|
39
|
+
* @template N The type of the TreeNode to be created. Defaults to TreeNode<T, any>.
|
|
40
|
+
* @param value The input value of type T to expand into a tree node.
|
|
41
|
+
* @returns A tree node of type N representing the expanded value and its descendants.
|
|
24
42
|
*/
|
|
25
43
|
export type ExpandTreeFunction<T, N extends TreeNode<T, N> = TreeNode<T, any>> = (value: T) => N;
|
|
26
44
|
/**
|
|
27
|
-
* Creates an ExpandTreeFunction
|
|
45
|
+
* Creates an ExpandTreeFunction using a basic ExpandTree configuration.
|
|
46
|
+
* The resulting nodes will be of type TreeNode<T>.
|
|
28
47
|
*
|
|
29
|
-
* @
|
|
48
|
+
* @template T The type of the value being processed at each node.
|
|
49
|
+
* @param config An ExpandTree<T> configuration object.
|
|
50
|
+
* @returns An ExpandTreeFunction<T, TreeNode<T>>.
|
|
30
51
|
*/
|
|
31
52
|
export declare function expandTreeFunction<T>(config: ExpandTree<T>): ExpandTreeFunction<T, TreeNode<T>>;
|
|
53
|
+
/**
|
|
54
|
+
* Creates an ExpandTreeFunction using an ExpandTreeWithNodeBuilder configuration.
|
|
55
|
+
* This allows for the creation of custom tree nodes of type N.
|
|
56
|
+
*
|
|
57
|
+
* @template T The type of the value being processed at each node.
|
|
58
|
+
* @template N The specific type of TreeNode to be created.
|
|
59
|
+
* @param config An ExpandTreeWithNodeBuilder<T, N> configuration object.
|
|
60
|
+
* @returns An ExpandTreeFunction<T, N>.
|
|
61
|
+
*/
|
|
32
62
|
export declare function expandTreeFunction<T, N extends TreeNode<T, N>>(config: ExpandTreeWithNodeBuilder<T, N>): ExpandTreeFunction<T, N>;
|
|
33
63
|
/**
|
|
34
|
-
* Convenience function for expanding multiple values into
|
|
64
|
+
* Convenience function for expanding multiple root values into an array of trees.
|
|
65
|
+
* Each value in the input array is treated as a root for a new tree.
|
|
35
66
|
*
|
|
36
|
-
* @
|
|
37
|
-
* @
|
|
38
|
-
* @
|
|
67
|
+
* @template T The type of the input values.
|
|
68
|
+
* @template N The type of the TreeNode in the resulting trees. Must extend TreeNode<T, N>.
|
|
69
|
+
* @param values An array of root values of type T to expand.
|
|
70
|
+
* @param expandFn An ExpandTreeFunction<T, N> used to expand each value into a tree.
|
|
71
|
+
* @returns An array of N, where each N is the root node of an expanded tree.
|
|
39
72
|
*/
|
|
40
73
|
export declare function expandTrees<T, N extends TreeNode<T, N>>(values: T[], expandFn: ExpandTreeFunction<T, N>): N[];
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { type TreeNode } from './tree';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* A function that flattens a tree structure into an array of values.
|
|
4
|
+
*
|
|
5
|
+
* @template N The type of the tree node, extending TreeNode.
|
|
6
|
+
* @template V The type of values in the resulting flattened array.
|
|
7
|
+
* @param tree The root node of the tree to flatten.
|
|
8
|
+
* @param array Optional. An existing array to push the flattened values into. If not provided, a new array is created.
|
|
9
|
+
* @returns An array containing the flattened values from the tree.
|
|
4
10
|
*/
|
|
5
11
|
export type FlattenTreeFunction<N extends TreeNode<unknown>, V> = (tree: N, array?: V[]) => V[];
|
|
6
12
|
/**
|
|
@@ -15,7 +21,21 @@ export declare function flattenTree<N extends TreeNode<unknown> = TreeNode<unkno
|
|
|
15
21
|
* @returns
|
|
16
22
|
*/
|
|
17
23
|
export declare function flattenTreeToArray<N extends TreeNode<unknown> = TreeNode<unknown>>(tree: N, array: N[]): N[];
|
|
24
|
+
/**
|
|
25
|
+
* Creates a FlattenTreeFunction that flattens tree nodes themselves into an array.
|
|
26
|
+
*
|
|
27
|
+
* @template N The type of the tree node.
|
|
28
|
+
* @returns A FlattenTreeFunction that collects nodes of type N.
|
|
29
|
+
*/
|
|
18
30
|
export declare function flattenTreeToArrayFunction<N extends TreeNode<unknown>>(): FlattenTreeFunction<N, N>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a FlattenTreeFunction that flattens tree nodes into an array of mapped values.
|
|
33
|
+
*
|
|
34
|
+
* @template N The type of the tree node.
|
|
35
|
+
* @template V The type of the value to map each node to.
|
|
36
|
+
* @param mapNodeFn An optional function to transform each node N into a value V. If not provided, nodes are returned as is.
|
|
37
|
+
* @returns A FlattenTreeFunction that collects values of type V.
|
|
38
|
+
*/
|
|
19
39
|
export declare function flattenTreeToArrayFunction<N extends TreeNode<unknown, N>, V>(mapNodeFn?: (node: N) => V): FlattenTreeFunction<N, V>;
|
|
20
40
|
/**
|
|
21
41
|
* Convenience function for flattening multiple trees with a flatten function.
|
package/test/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [12.1.1](https://github.com/dereekb/dbx-components/compare/v12.1.0-dev...v12.1.1) (2025-05-12)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
5
9
|
# [12.1.0](https://github.com/dereekb/dbx-components/compare/v12.0.6-dev...v12.1.0) (2025-05-10)
|
|
6
10
|
|
|
7
11
|
|