@rimbu/common 2.0.0 → 2.0.2
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/README.md +42 -42
- package/dist/bun/err.mts +1 -1
- package/dist/cjs/async-optlazy.cjs +60 -42
- package/dist/cjs/async-optlazy.cjs.map +1 -0
- package/dist/cjs/async-optlazy.d.cts +46 -0
- package/dist/cjs/collect.cjs +9 -31
- package/dist/cjs/collect.cjs.map +1 -0
- package/dist/cjs/collect.d.cts +29 -0
- package/dist/cjs/comp.cjs +518 -707
- package/dist/cjs/comp.cjs.map +1 -0
- package/dist/cjs/comp.d.cts +239 -0
- package/dist/cjs/eq.cjs +375 -203
- package/dist/cjs/eq.cjs.map +1 -0
- package/dist/cjs/err.cjs +57 -50
- package/dist/cjs/err.cjs.map +1 -0
- package/dist/cjs/index-range.cjs +105 -109
- package/dist/cjs/index-range.cjs.map +1 -0
- package/dist/cjs/index-range.d.cts +42 -0
- package/dist/cjs/index.cjs +9 -797
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +6 -0
- package/dist/cjs/internal.cjs +14 -797
- package/dist/cjs/internal.cjs.map +1 -0
- package/dist/cjs/internal.d.cts +11 -0
- package/dist/cjs/optlazy.cjs +43 -37
- package/dist/cjs/optlazy.cjs.map +1 -0
- package/dist/cjs/range.cjs +35 -49
- package/dist/cjs/range.cjs.map +1 -0
- package/dist/cjs/traverse-state.cjs +29 -46
- package/dist/cjs/traverse-state.cjs.map +1 -0
- package/dist/cjs/types.cjs +2 -17
- package/dist/cjs/types.cjs.map +1 -0
- package/dist/cjs/update.cjs +20 -32
- package/dist/cjs/update.cjs.map +1 -0
- package/dist/esm/eq.d.mts +196 -0
- package/dist/esm/err.d.mts +33 -0
- package/dist/esm/optlazy.d.mts +42 -0
- package/dist/esm/range.d.mts +35 -0
- package/dist/esm/traverse-state.d.mts +33 -0
- package/dist/esm/types.d.mts +31 -0
- package/dist/esm/update.d.mts +18 -0
- package/package.json +19 -12
- package/src/err.mts +1 -1
- /package/dist/{types/eq.d.mts → cjs/eq.d.cts} +0 -0
- /package/dist/{types/err.d.mts → cjs/err.d.cts} +0 -0
- /package/dist/{types/optlazy.d.mts → cjs/optlazy.d.cts} +0 -0
- /package/dist/{types/range.d.mts → cjs/range.d.cts} +0 -0
- /package/dist/{types/traverse-state.d.mts → cjs/traverse-state.d.cts} +0 -0
- /package/dist/{types/types.d.mts → cjs/types.d.cts} +0 -0
- /package/dist/{types/update.d.mts → cjs/update.d.cts} +0 -0
- /package/dist/{types → esm}/async-optlazy.d.mts +0 -0
- /package/dist/{types → esm}/collect.d.mts +0 -0
- /package/dist/{types → esm}/comp.d.mts +0 -0
- /package/dist/{types → esm}/index-range.d.mts +0 -0
- /package/dist/{types → esm}/index.d.mts +0 -0
- /package/dist/{types → esm}/internal.d.mts +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A range definition for any type of (orderable) value.
|
|
3
|
+
* If a start or end is defined, a tuple can be used where the second item is a boolean
|
|
4
|
+
* indicating whether that end is inclusive (true) or exclusive (false).<br/>
|
|
5
|
+
* A Range of type T can have one of the following forms:<br/>
|
|
6
|
+
* <br/>
|
|
7
|
+
* - { end: T }<br/>
|
|
8
|
+
* - { end: [T, boolean] }<br/>
|
|
9
|
+
* - { start: T }<br/>
|
|
10
|
+
* - { start: T, end: T }<br/>
|
|
11
|
+
* - { start: T, end: [T, boolean] }<br/>
|
|
12
|
+
* - { start: [T, boolean] }<br/>
|
|
13
|
+
* - { start: [T, boolean], end: T }<br/>
|
|
14
|
+
* - { start: [T, boolean], end: [T, boolean] }<br/>
|
|
15
|
+
*/
|
|
16
|
+
export type Range<T> = {
|
|
17
|
+
start: T | [T, boolean];
|
|
18
|
+
end?: T | [T, boolean];
|
|
19
|
+
amount?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
start?: T | [T, boolean];
|
|
22
|
+
end: T | [T, boolean];
|
|
23
|
+
amount?: undefined;
|
|
24
|
+
};
|
|
25
|
+
export declare namespace Range {
|
|
26
|
+
/**
|
|
27
|
+
* Simplifies a given `range` `Range` input for easier processing, by returning optional
|
|
28
|
+
* start and end ranges including whether they are inclusive or exclusive
|
|
29
|
+
* @param range - the `Range` to use
|
|
30
|
+
*/
|
|
31
|
+
function getNormalizedRange<T>(range: Range<T>): {
|
|
32
|
+
start?: [T, boolean] | undefined;
|
|
33
|
+
end?: [T, boolean] | undefined;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An object used to track the state of a traversal, e.g. a `forEach`.
|
|
3
|
+
*/
|
|
4
|
+
export interface TraverseState {
|
|
5
|
+
/**
|
|
6
|
+
* Returns true if the traversal has been halted by the user.
|
|
7
|
+
*/
|
|
8
|
+
readonly halted: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the current index of the traversal.
|
|
11
|
+
*/
|
|
12
|
+
readonly currentIndex: number;
|
|
13
|
+
/**
|
|
14
|
+
* Increases the `currentIndex` of this traversal
|
|
15
|
+
* @returns the next index that the traversal should use
|
|
16
|
+
*/
|
|
17
|
+
nextIndex(): number;
|
|
18
|
+
/**
|
|
19
|
+
* Sets the `halted` value to true.
|
|
20
|
+
*/
|
|
21
|
+
halt(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Sets the `halted` value to false, and resets the `currentIndex`
|
|
24
|
+
* value to its start value.
|
|
25
|
+
*/
|
|
26
|
+
reset(): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns a new `TraverseState` instance, using optionally given `startIndex` as a start
|
|
30
|
+
* index value.
|
|
31
|
+
* @param startIndex - (default: 0) the start index to use
|
|
32
|
+
*/
|
|
33
|
+
export declare function TraverseState(startIndex?: number): TraverseState;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accepts all types of T and U where T extends U,
|
|
3
|
+
* and result in the upper bound U.
|
|
4
|
+
*/
|
|
5
|
+
export type SuperOf<U, T> = T extends U ? U : never;
|
|
6
|
+
/**
|
|
7
|
+
* Accepts all types of T and S where S extends T,
|
|
8
|
+
* and results in the lower bound S.
|
|
9
|
+
*/
|
|
10
|
+
export type SubOf<S, T> = S extends T ? S : never;
|
|
11
|
+
/**
|
|
12
|
+
* Accepts all types of T and U where T extends U or U extends T.
|
|
13
|
+
*/
|
|
14
|
+
export type RelatedTo<T, U> = T | SuperOf<U, T>;
|
|
15
|
+
/**
|
|
16
|
+
* Accepts all arrays with at least one element.
|
|
17
|
+
*/
|
|
18
|
+
export type ArrayNonEmpty<T> = [T, ...T[]];
|
|
19
|
+
/**
|
|
20
|
+
* Accepts all strings with at least one character.
|
|
21
|
+
*/
|
|
22
|
+
export type StringNonEmpty<T> = T extends string ? '' extends T ? never : T : never;
|
|
23
|
+
/**
|
|
24
|
+
* Utility type to convert some object to a JSON serializable format.
|
|
25
|
+
* @typeparam V - the `value` type
|
|
26
|
+
* @typeparam D - the `dataType` tag string type
|
|
27
|
+
*/
|
|
28
|
+
export interface ToJSON<V, D extends string = string> {
|
|
29
|
+
readonly dataType: D;
|
|
30
|
+
readonly value: V;
|
|
31
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value of type T, or a function taking a value of type T and returning a new value of type T.
|
|
3
|
+
*/
|
|
4
|
+
export type Update<T> = T | ((value: T) => T);
|
|
5
|
+
/**
|
|
6
|
+
* Returns the result of given `update` parameter, where it can either directly give a new value,
|
|
7
|
+
* or it is a function receiving the given `value`, and returns a new value.
|
|
8
|
+
* @param value - the current value
|
|
9
|
+
* @param update - an `Update` value, either a new value or a function receiving the old value
|
|
10
|
+
* and returning a new one.
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* Update(1, 2) // => 2
|
|
14
|
+
* Update(1, () => 10) // => 10
|
|
15
|
+
* Update(1, v => v + 1) // => 2
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function Update<T>(value: T, update: Update<T>): T;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rimbu/common",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Common types and objects used in many other Rimbu packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"common",
|
|
@@ -31,14 +31,18 @@
|
|
|
31
31
|
"type": "module",
|
|
32
32
|
"main": "./dist/cjs/index.cjs",
|
|
33
33
|
"module": "./dist/esm/index.mjs",
|
|
34
|
-
"types": "./dist/
|
|
34
|
+
"types": "./dist/cjs/index.d.cts",
|
|
35
35
|
"exports": {
|
|
36
36
|
".": {
|
|
37
|
-
"types": "./dist/types/index.d.mts",
|
|
38
37
|
"bun": "./dist/bun/index.mts",
|
|
39
|
-
"import":
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/esm/index.d.mts",
|
|
40
|
+
"default": "./dist/esm/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./dist/cjs/index.d.cts",
|
|
44
|
+
"default": "./dist/cjs/index.cjs"
|
|
45
|
+
}
|
|
42
46
|
}
|
|
43
47
|
},
|
|
44
48
|
"files": [
|
|
@@ -46,19 +50,22 @@
|
|
|
46
50
|
"src"
|
|
47
51
|
],
|
|
48
52
|
"scripts": {
|
|
53
|
+
"b": "duel",
|
|
49
54
|
"build": "yarn clean && yarn bundle",
|
|
50
55
|
"build:deno": "yarn bundle:deno-prepare && yarn bundle:deno-convert && yarn bundle:deno-move && yarn bundle:deno-clean",
|
|
51
|
-
"bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:
|
|
52
|
-
"bundle:bun": "node ../../config/bunnify.mjs",
|
|
53
|
-
"bundle:cjs": "
|
|
56
|
+
"bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:bun",
|
|
57
|
+
"bundle:bun": "node ../../config/bunnify.mjs -mode bun",
|
|
58
|
+
"bundle:cjs": "yarn bundle:cjs-prepare && yarn bundle:cjs-build && yarn bundle:cjs-clean",
|
|
59
|
+
"bundle:cjs-prepare": "node ../../config/bunnify.mjs -mode cjs",
|
|
60
|
+
"bundle:cjs-build": "tsc -p tsconfig.cjs.json",
|
|
61
|
+
"bundle:cjs-clean": "rimraf _cjs_prepare",
|
|
54
62
|
"bundle:deno-prepare": "node ../../config/prepare-denoify.mjs",
|
|
55
63
|
"bundle:deno-convert": "denoify --src _deno_prepare/src",
|
|
56
64
|
"bundle:deno-move": "rimraf ../../deno_dist/common && mv deno_dist ../../deno_dist/common",
|
|
57
65
|
"bundle:deno-clean": "rimraf _deno_prepare",
|
|
58
66
|
"bundle:esm": "tsc --p tsconfig.esm.json",
|
|
59
|
-
"bundle:types": "tsc --p tsconfig.types.json",
|
|
60
67
|
"clean": "rimraf dist",
|
|
61
|
-
"extract-api": "
|
|
68
|
+
"extract-api": "tsx ../../config/api-extractor.ts config/api-extractor.main.json",
|
|
62
69
|
"format": "yarn format:base --write",
|
|
63
70
|
"format:base": "prettier \"{!CHANGELOG.md}|**/**/*.{ts,tsx,js,mts,mjs,json,md}\"",
|
|
64
71
|
"format:check": "yarn format:base --check",
|
|
@@ -75,5 +82,5 @@
|
|
|
75
82
|
"dependencies": {
|
|
76
83
|
"tslib": "^2.6.2"
|
|
77
84
|
},
|
|
78
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "f18ddf964507dbd10790da3cd4deef8f455a178e"
|
|
79
86
|
}
|
package/src/err.mts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|