@dereekb/util 13.0.7 → 13.2.0
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 +2 -2
- package/index.cjs.js +4107 -1516
- package/index.esm.js +4107 -1516
- package/package.json +1 -2
- package/src/lib/array/array.d.ts +92 -47
- package/src/lib/array/array.find.d.ts +14 -18
- package/src/lib/array/array.index.d.ts +43 -14
- package/src/lib/array/array.indexed.d.ts +66 -17
- package/src/lib/array/array.limit.d.ts +11 -0
- package/src/lib/array/array.make.d.ts +9 -3
- package/src/lib/array/array.map.d.ts +20 -8
- package/src/lib/array/array.number.d.ts +63 -5
- package/src/lib/array/array.random.d.ts +12 -9
- package/src/lib/array/array.set.d.ts +24 -1
- package/src/lib/array/array.string.d.ts +104 -0
- package/src/lib/array/array.unique.d.ts +60 -8
- package/src/lib/array/array.value.d.ts +20 -11
- package/src/lib/assertion/assertion.d.ts +30 -2
- package/src/lib/assertion/assertion.generic.d.ts +8 -0
- package/src/lib/assertion/assertion.number.d.ts +16 -0
- package/src/lib/auth/auth.role.claims.d.ts +14 -8
- package/src/lib/boolean.d.ts +54 -1
- package/src/lib/contact/domain.d.ts +22 -4
- package/src/lib/contact/random.d.ts +24 -0
- package/src/lib/date/date.d.ts +8 -13
- package/src/lib/date/hour.d.ts +51 -32
- package/src/lib/date/minute.d.ts +4 -4
- package/src/lib/date/time.d.ts +12 -3
- package/src/lib/date/week.d.ts +77 -10
- package/src/lib/error/error.d.ts +54 -3
- package/src/lib/error/error.server.d.ts +25 -2
- package/src/lib/filter/filter.d.ts +12 -7
- package/src/lib/function/function.boolean.d.ts +4 -4
- package/src/lib/function/function.d.ts +2 -5
- package/src/lib/function/function.forward.d.ts +19 -3
- package/src/lib/getter/getter.cache.d.ts +9 -5
- package/src/lib/getter/getter.d.ts +39 -22
- package/src/lib/getter/getter.map.d.ts +10 -4
- package/src/lib/getter/getter.util.d.ts +3 -3
- package/src/lib/grouping.d.ts +98 -31
- package/src/lib/hash.d.ts +15 -8
- package/src/lib/iterable/iterable.d.ts +62 -50
- package/src/lib/iterable/iterable.map.d.ts +4 -4
- package/src/lib/iterate.d.ts +17 -1
- package/src/lib/key.d.ts +32 -10
- package/src/lib/lifecycle.d.ts +10 -1
- package/src/lib/map/map.d.ts +17 -16
- package/src/lib/map/map.intersection.d.ts +5 -4
- package/src/lib/map/map.key.d.ts +16 -15
- package/src/lib/misc/host.d.ts +6 -3
- package/src/lib/model/id.batch.d.ts +7 -3
- package/src/lib/model/id.factory.d.ts +16 -1
- package/src/lib/model/model.conversion.d.ts +49 -6
- package/src/lib/model/model.conversion.field.d.ts +13 -3
- package/src/lib/model/model.copy.d.ts +11 -0
- package/src/lib/model/model.d.ts +174 -1
- package/src/lib/model/model.modify.d.ts +24 -5
- package/src/lib/nodejs/stream.d.ts +8 -6
- package/src/lib/number/bitwise.dencoder.d.ts +43 -3
- package/src/lib/number/bound.d.ts +34 -5
- package/src/lib/number/dollar.d.ts +13 -6
- package/src/lib/number/factory.d.ts +11 -3
- package/src/lib/number/number.d.ts +55 -32
- package/src/lib/number/random.d.ts +13 -3
- package/src/lib/number/round.d.ts +47 -26
- package/src/lib/number/sort.d.ts +7 -1
- package/src/lib/number/transform.d.ts +16 -0
- package/src/lib/object/object.array.d.ts +16 -2
- package/src/lib/object/object.array.delta.d.ts +6 -2
- package/src/lib/object/object.d.ts +33 -5
- package/src/lib/object/object.empty.d.ts +4 -2
- package/src/lib/object/object.equal.d.ts +21 -4
- package/src/lib/object/object.filter.tuple.d.ts +105 -3
- package/src/lib/object/object.key.d.ts +13 -6
- package/src/lib/object/object.map.d.ts +30 -19
- package/src/lib/page/page.d.ts +21 -0
- package/src/lib/page/page.filter.d.ts +16 -9
- package/src/lib/path/path.d.ts +101 -14
- package/src/lib/path/path.tree.d.ts +16 -0
- package/src/lib/promise/callback.d.ts +18 -0
- package/src/lib/promise/is.d.ts +10 -3
- package/src/lib/promise/map.d.ts +5 -3
- package/src/lib/promise/poll.d.ts +14 -4
- package/src/lib/promise/promise.d.ts +84 -18
- package/src/lib/promise/promise.factory.d.ts +18 -2
- package/src/lib/promise/promise.limit.d.ts +22 -2
- package/src/lib/promise/promise.loop.d.ts +69 -1
- package/src/lib/promise/promise.ref.d.ts +14 -2
- package/src/lib/promise/promise.task.d.ts +8 -4
- package/src/lib/promise/promise.type.d.ts +4 -4
- package/src/lib/promise/use.d.ts +6 -4
- package/src/lib/promise/wait.d.ts +5 -2
- package/src/lib/relation/relation.d.ts +98 -0
- package/src/lib/service/handler.config.d.ts +47 -9
- package/src/lib/service/handler.d.ts +43 -1
- package/src/lib/service/typed.service.d.ts +21 -2
- package/src/lib/set/set.allowed.d.ts +6 -4
- package/src/lib/set/set.d.ts +174 -46
- package/src/lib/set/set.decision.d.ts +4 -2
- package/src/lib/set/set.delta.d.ts +16 -3
- package/src/lib/set/set.hashset.d.ts +43 -0
- package/src/lib/set/set.selection.d.ts +7 -3
- package/src/lib/sort.d.ts +36 -16
- package/src/lib/string/char.d.ts +48 -34
- package/src/lib/string/dencoder.d.ts +84 -13
- package/src/lib/string/factory.d.ts +13 -4
- package/src/lib/string/html.d.ts +7 -6
- package/src/lib/string/mimetype.d.ts +65 -1
- package/src/lib/string/prefix.d.ts +21 -7
- package/src/lib/string/record.d.ts +7 -4
- package/src/lib/string/replace.d.ts +77 -33
- package/src/lib/string/search.d.ts +19 -9
- package/src/lib/string/sort.d.ts +10 -1
- package/src/lib/string/string.d.ts +74 -21
- package/src/lib/string/transform.d.ts +7 -0
- package/src/lib/string/tree.d.ts +91 -29
- package/src/lib/string/url.d.ts +148 -63
- package/src/lib/tree/tree.explore.d.ts +84 -17
- package/src/lib/tree/tree.flatten.d.ts +44 -7
- package/src/lib/type.d.ts +15 -12
- package/src/lib/value/address.d.ts +66 -17
- package/src/lib/value/bound.d.ts +253 -17
- package/src/lib/value/build.d.ts +30 -5
- package/src/lib/value/comparator.d.ts +53 -25
- package/src/lib/value/cron.d.ts +14 -6
- package/src/lib/value/decision.d.ts +57 -13
- package/src/lib/value/equal.d.ts +44 -13
- package/src/lib/value/indexed.d.ts +253 -82
- package/src/lib/value/label.d.ts +16 -5
- package/src/lib/value/map.d.ts +77 -20
- package/src/lib/value/maybe.d.ts +47 -49
- package/src/lib/value/modifier.d.ts +82 -27
- package/src/lib/value/point.d.ts +248 -54
- package/src/lib/value/url.d.ts +10 -3
- package/src/lib/value/use.d.ts +99 -8
- package/src/lib/value/vector.d.ts +71 -9
- package/test/index.cjs.js +86 -23
- package/test/index.esm.js +86 -23
- package/test/package.json +2 -2
- package/test/src/lib/shared/shared.d.ts +31 -5
- package/test/src/lib/shared/shared.fail.d.ts +72 -9
- package/test/src/lib/shared/shared.function.d.ts +40 -2
- package/test/src/lib/shared/shared.wrap.d.ts +20 -1
package/src/lib/string/char.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { type ArrayOrValue } from '../array/array';
|
|
2
2
|
import { type DecisionFunction } from '../value/decision';
|
|
3
|
+
/**
|
|
4
|
+
* Result describing the first and last index positions of a character within a string.
|
|
5
|
+
*/
|
|
3
6
|
export interface FirstAndLastCharacterOccurrence {
|
|
7
|
+
/**
|
|
8
|
+
* Index of the first occurrence, or -1 if the character was not found.
|
|
9
|
+
*/
|
|
4
10
|
readonly first: number | -1;
|
|
11
|
+
/**
|
|
12
|
+
* Index of the last occurrence, or -1 if the character was not found.
|
|
13
|
+
*/
|
|
5
14
|
readonly last: number | -1;
|
|
6
15
|
/**
|
|
7
16
|
* Total number of occurrences.
|
|
@@ -9,15 +18,20 @@ export interface FirstAndLastCharacterOccurrence {
|
|
|
9
18
|
readonly occurences: number;
|
|
10
19
|
}
|
|
11
20
|
/**
|
|
12
|
-
*
|
|
21
|
+
* Finds the first and last occurrence of a single character within the input string.
|
|
13
22
|
*
|
|
14
|
-
* @param input string to
|
|
15
|
-
* @param find character to find
|
|
16
|
-
* @returns
|
|
23
|
+
* @param input - string to search through
|
|
24
|
+
* @param find - single character to find
|
|
25
|
+
* @returns an object containing the first index, last index, and total occurrence count
|
|
26
|
+
* @throws Error if find is not exactly one character long
|
|
17
27
|
*/
|
|
18
28
|
export declare function firstAndLastCharacterOccurrence(input: string, find: string): FirstAndLastCharacterOccurrence;
|
|
19
29
|
/**
|
|
20
|
-
*
|
|
30
|
+
* Checks whether the input string contains the given substring.
|
|
31
|
+
*
|
|
32
|
+
* @param input - string to search within
|
|
33
|
+
* @param find - substring to search for
|
|
34
|
+
* @returns true if the substring is found within the input
|
|
21
35
|
*/
|
|
22
36
|
export declare function stringContains(input: string, find: string): boolean;
|
|
23
37
|
/**
|
|
@@ -25,48 +39,49 @@ export declare function stringContains(input: string, find: string): boolean;
|
|
|
25
39
|
*/
|
|
26
40
|
export type ReplaceLastCharacterIfIsFunction = (input: string) => string;
|
|
27
41
|
/**
|
|
28
|
-
*
|
|
42
|
+
* Creates a function that replaces the last character of a string with the replacement string
|
|
43
|
+
* if that character matches any of the specified values.
|
|
29
44
|
*
|
|
30
|
-
* @param
|
|
31
|
-
* @param replacement
|
|
32
|
-
* @
|
|
33
|
-
* @returns
|
|
45
|
+
* @param replacement - string to substitute for the last character
|
|
46
|
+
* @param is - character(s) that trigger the replacement
|
|
47
|
+
* @returns a function that conditionally replaces the last character
|
|
34
48
|
*/
|
|
35
49
|
export declare function replaceLastCharacterIfIsFunction(replacement: string, is: ArrayOrValue<string>): ReplaceLastCharacterIfIsFunction;
|
|
36
50
|
/**
|
|
37
|
-
* Replaces the last character with the replacement
|
|
51
|
+
* Replaces the last character of a string with the replacement if the decision function returns true for that character.
|
|
38
52
|
*
|
|
39
|
-
* @param input
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
42
|
-
* @returns
|
|
53
|
+
* @param input - string to potentially modify
|
|
54
|
+
* @param replacement - string to substitute for the last character
|
|
55
|
+
* @param decision - function that determines whether the last character should be replaced
|
|
56
|
+
* @returns the modified string, or the original if the decision is false or the string is empty
|
|
43
57
|
*/
|
|
44
58
|
export declare function replaceLastCharacterIf(input: string, replacement: string, decision: DecisionFunction<string>): string;
|
|
45
59
|
/**
|
|
46
|
-
* Replaces the character at the given index with the replacement string if the decision
|
|
60
|
+
* Replaces the character at the given index with the replacement string if the decision function returns true for that character.
|
|
47
61
|
*
|
|
48
|
-
* @param input
|
|
49
|
-
* @param index
|
|
50
|
-
* @param replacement
|
|
51
|
-
* @
|
|
62
|
+
* @param input - string to potentially modify
|
|
63
|
+
* @param index - character index to evaluate
|
|
64
|
+
* @param replacement - string to substitute at the index
|
|
65
|
+
* @param decision - function that determines whether the character should be replaced
|
|
66
|
+
* @returns the modified string, or the original if the decision is false
|
|
52
67
|
*/
|
|
53
68
|
export declare function replaceCharacterAtIndexIf(input: string, index: number, replacement: string, decision: DecisionFunction<string>): string;
|
|
54
69
|
/**
|
|
55
70
|
* Replaces the character at the given index with the replacement string.
|
|
56
71
|
*
|
|
57
|
-
* @param input
|
|
58
|
-
* @param index
|
|
59
|
-
* @param replacement
|
|
60
|
-
* @returns
|
|
72
|
+
* @param input - string to modify
|
|
73
|
+
* @param index - character index to replace
|
|
74
|
+
* @param replacement - string to substitute at the index
|
|
75
|
+
* @returns the string with the character at the index replaced
|
|
61
76
|
*/
|
|
62
77
|
export declare function replaceCharacterAtIndexWith(input: string, index: number, replacement: string): string;
|
|
63
78
|
/**
|
|
64
|
-
* Splits the input string at the given character index.
|
|
79
|
+
* Splits the input string into two parts at the given character index.
|
|
65
80
|
*
|
|
66
|
-
* @param input
|
|
67
|
-
* @param index
|
|
68
|
-
* @param
|
|
69
|
-
* @returns
|
|
81
|
+
* @param input - string to split
|
|
82
|
+
* @param index - character index at which to split
|
|
83
|
+
* @param inclusive - if true, the character at the index is included in the tail; if false (default), it is excluded from both parts
|
|
84
|
+
* @returns a tuple of [head, tail] substrings
|
|
70
85
|
*/
|
|
71
86
|
export declare function splitStringAtIndex(input: string, index: number, inclusive?: boolean): [string, string];
|
|
72
87
|
/**
|
|
@@ -84,11 +99,10 @@ export declare const UTF_8_START_CHARACTER = "\0";
|
|
|
84
99
|
*/
|
|
85
100
|
export declare const UTF_PRIVATE_USAGE_AREA_START = "\uF8FF";
|
|
86
101
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* The latest character index is used in collision cases.
|
|
102
|
+
* Creates a lookup record mapping each character in the input string to its index position.
|
|
103
|
+
* In case of duplicate characters, the last occurrence's index is used.
|
|
90
104
|
*
|
|
91
|
-
* @param chars
|
|
92
|
-
* @returns
|
|
105
|
+
* @param chars - string whose characters become keys in the record
|
|
106
|
+
* @returns a record mapping each character to its index in the input string
|
|
93
107
|
*/
|
|
94
108
|
export declare function stringCharactersToIndexRecord(chars: string): Record<string, number>;
|
|
@@ -7,25 +7,46 @@ import { type Maybe } from '../value/maybe.type';
|
|
|
7
7
|
export type PrimativeKeyDencoderValueMap<D extends PrimativeKey, E extends PrimativeKey> = {
|
|
8
8
|
[key in E]: D;
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* A tuple pairing an encoded value to its decoded counterpart.
|
|
12
|
+
*/
|
|
10
13
|
export type PrimativeKeyDencoderTuple<D extends PrimativeKey, E extends PrimativeKey> = [E, D];
|
|
14
|
+
/**
|
|
15
|
+
* An array of {@link PrimativeKeyDencoderTuple} values.
|
|
16
|
+
*/
|
|
11
17
|
export type PrimativeKeyDencoderTupleArray<D extends PrimativeKey, E extends PrimativeKey> = PrimativeKeyDencoderTuple<D, E>[];
|
|
12
18
|
/**
|
|
13
19
|
* PrimativeKeyDencoder values. No key or value should be repeated.
|
|
14
20
|
*/
|
|
15
21
|
export type PrimativeKeyDencoderValues<D extends PrimativeKey, E extends PrimativeKey> = PrimativeKeyDencoderTupleArray<D, E> | PrimativeKeyDencoderValueMap<D, E>;
|
|
22
|
+
/**
|
|
23
|
+
* A bidirectional Map that maps both encoded-to-decoded and decoded-to-encoded values.
|
|
24
|
+
* Also carries the original tuple array used to construct it.
|
|
25
|
+
*/
|
|
16
26
|
export type PrimativeKeyDencoderMap<D extends PrimativeKey, E extends PrimativeKey> = Map<D | E, E | D> & {
|
|
17
27
|
readonly _tuples: PrimativeKeyDencoderTupleArray<D, E>;
|
|
18
28
|
};
|
|
19
29
|
/**
|
|
20
|
-
* Creates a
|
|
21
|
-
*
|
|
22
|
-
* If any repeat values are found, an error will be thrown.
|
|
30
|
+
* Creates a bidirectional {@link PrimativeKeyDencoderMap} from the given values,
|
|
31
|
+
* allowing lookup in both directions (encoded-to-decoded and decoded-to-encoded).
|
|
23
32
|
*
|
|
24
|
-
* @param values
|
|
33
|
+
* @param values - encoder/decoder value pairs as tuples or a map object
|
|
34
|
+
* @returns a bidirectional Map for encoding/decoding
|
|
35
|
+
* @throws Error if any key or value is repeated
|
|
25
36
|
*/
|
|
26
37
|
export declare function primativeKeyDencoderMap<D extends PrimativeKey, E extends PrimativeKey>(values: PrimativeKeyDencoderValues<D, E>): PrimativeKeyDencoderMap<D, E>;
|
|
38
|
+
/**
|
|
39
|
+
* Configuration for creating a {@link PrimativeKeyDencoderFunction}.
|
|
40
|
+
*/
|
|
27
41
|
export interface PrimativeKeyDencoderConfig<D extends PrimativeKey, E extends PrimativeKey> {
|
|
42
|
+
/**
|
|
43
|
+
* The encode/decode value pairs.
|
|
44
|
+
*/
|
|
28
45
|
readonly values: PrimativeKeyDencoderValues<D, E>;
|
|
46
|
+
/**
|
|
47
|
+
* Optional factory to produce a fallback value when a lookup misses.
|
|
48
|
+
* If not provided or if it returns null, an error is thrown for unknown values.
|
|
49
|
+
*/
|
|
29
50
|
readonly defaultValue?: FactoryWithRequiredInput<D | E, D | E>;
|
|
30
51
|
}
|
|
31
52
|
/**
|
|
@@ -36,13 +57,23 @@ export interface PrimativeKeyDencoderConfig<D extends PrimativeKey, E extends Pr
|
|
|
36
57
|
export type PrimativeKeyDencoderFunction<D extends PrimativeKey, E extends PrimativeKey> = ((encodedValue: E) => D) & ((decodedValue: D) => E) & ((encodedValues: E[]) => D[]) & ((decodedValues: D[]) => E[]) & {
|
|
37
58
|
readonly _map: PrimativeKeyDencoderMap<D, E>;
|
|
38
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Default fallback factory for {@link PrimativeKeyDencoderFunction} that always returns null,
|
|
62
|
+
* causing an error to be thrown for unknown values.
|
|
63
|
+
*/
|
|
39
64
|
export declare const PRIMATIVE_KEY_DENCODER_VALUE: (input: unknown) => null;
|
|
40
65
|
/**
|
|
41
|
-
* Creates a new
|
|
66
|
+
* Creates a new {@link PrimativeKeyDencoderFunction} that can bidirectionally encode/decode
|
|
67
|
+
* primitive key values based on the configured value pairs.
|
|
68
|
+
*
|
|
69
|
+
* @param config - configuration with value pairs and optional default fallback
|
|
70
|
+
* @returns a function that encodes or decodes single values or arrays
|
|
71
|
+
* @throws Error if a single value lookup produces a null result and no default handles it
|
|
42
72
|
*/
|
|
43
73
|
export declare function primativeKeyDencoder<D extends PrimativeKey, E extends PrimativeKey>(config: PrimativeKeyDencoderConfig<D, E>): PrimativeKeyDencoderFunction<D, E>;
|
|
44
74
|
/**
|
|
45
|
-
*
|
|
75
|
+
* Configuration for creating a {@link PrimativeKeyStringDencoderFunction} that can encode/decode
|
|
76
|
+
* between a compact string representation and an array of values.
|
|
46
77
|
*/
|
|
47
78
|
export interface PrimativeKeyStringDencoderConfig<D extends PrimativeKey, E extends PrimativeKey> {
|
|
48
79
|
/**
|
|
@@ -61,10 +92,15 @@ export interface PrimativeKeyStringDencoderConfig<D extends PrimativeKey, E exte
|
|
|
61
92
|
*/
|
|
62
93
|
export type PrimativeKeyStringDencoderFunction<D extends PrimativeKey, E extends PrimativeKey, S extends string = string> = ((encodedValues: S) => (E | D)[]) & ((decodedValues: (E | D)[]) => S);
|
|
63
94
|
/**
|
|
64
|
-
* Creates a new PrimativeKeyStringDencoderFunction
|
|
95
|
+
* Creates a new {@link PrimativeKeyStringDencoderFunction} that converts between a compact string
|
|
96
|
+
* and an array of encoded/decoded values.
|
|
97
|
+
*
|
|
98
|
+
* When no splitter is defined, all encoded values must be exactly one character long so the string
|
|
99
|
+
* can be split character-by-character.
|
|
65
100
|
*
|
|
66
|
-
* @param config
|
|
67
|
-
* @returns
|
|
101
|
+
* @param config - configuration with dencoder and optional splitter
|
|
102
|
+
* @returns a bidirectional function for string-to-array and array-to-string conversion
|
|
103
|
+
* @throws Error if encoded values contain the splitter character, or if values exceed one character when no splitter is defined
|
|
68
104
|
*/
|
|
69
105
|
export declare function primativeKeyStringDencoder<D extends PrimativeKey, E extends PrimativeKey>(config: PrimativeKeyStringDencoderConfig<D, E>): PrimativeKeyStringDencoderFunction<D, E>;
|
|
70
106
|
/**
|
|
@@ -124,24 +160,59 @@ export interface NumberStringDencoder {
|
|
|
124
160
|
*/
|
|
125
161
|
decodeNumber(encodedNumber: NumberStringDencoderString): NumberStringDencoderNumber;
|
|
126
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Configuration for creating a {@link NumberStringDencoder}.
|
|
165
|
+
*/
|
|
127
166
|
export interface NumberStringDencoderConfig {
|
|
128
167
|
/**
|
|
129
168
|
* Optional negative prefix character. Should not be in the digits.
|
|
130
169
|
*/
|
|
131
170
|
readonly negativePrefix?: Maybe<string>;
|
|
171
|
+
/**
|
|
172
|
+
* The character set used for encoding. Length must be a power of 2.
|
|
173
|
+
*/
|
|
132
174
|
readonly digits: NumberStringDencoderDigits;
|
|
133
175
|
}
|
|
134
176
|
/**
|
|
135
|
-
* Creates an integer-type NumberStringDencoder
|
|
177
|
+
* Creates an integer-type {@link NumberStringDencoder} that can encode and decode integers
|
|
178
|
+
* using a custom character set (digit alphabet).
|
|
136
179
|
*
|
|
137
|
-
* If the config does not include a negative prefix,
|
|
180
|
+
* If the config does not include a negative prefix, negative numbers lose their sign during encoding.
|
|
138
181
|
*
|
|
139
|
-
* @param config
|
|
140
|
-
* @returns
|
|
182
|
+
* @param config - configuration with digit alphabet and optional negative prefix
|
|
183
|
+
* @returns a NumberStringDencoder capable of encoding/decoding integers
|
|
141
184
|
*/
|
|
142
185
|
export declare function numberStringDencoder(config: NumberStringDencoderConfig): NumberStringDencoder;
|
|
186
|
+
/**
|
|
187
|
+
* Pre-configured 64-character {@link NumberStringDencoder} using the default digit alphabet and negative prefix.
|
|
188
|
+
*/
|
|
143
189
|
export declare const NUMBER_STRING_DENCODER_64: NumberStringDencoder;
|
|
190
|
+
/**
|
|
191
|
+
* A bidirectional function that encodes a number to a string or decodes a string to a number,
|
|
192
|
+
* depending on the type of the input.
|
|
193
|
+
*/
|
|
144
194
|
export type NumberStringDencoderFunction = ((input: NumberStringDencoderString) => NumberStringDencoderNumber) & ((input: NumberStringDencoderNumber) => NumberStringDencoderString);
|
|
195
|
+
/**
|
|
196
|
+
* Creates a {@link NumberStringDencoderFunction} from the given dencoder.
|
|
197
|
+
* The returned function auto-detects the input type: numbers are encoded, strings are decoded.
|
|
198
|
+
*
|
|
199
|
+
* @param dencoder - the NumberStringDencoder to wrap
|
|
200
|
+
* @returns a bidirectional encode/decode function
|
|
201
|
+
*/
|
|
145
202
|
export declare function numberStringDencoderFunction(dencoder: NumberStringDencoder): NumberStringDencoderFunction;
|
|
203
|
+
/**
|
|
204
|
+
* Creates a function that always returns the encoded string form of the input.
|
|
205
|
+
* Numbers are encoded; strings are passed through as-is.
|
|
206
|
+
*
|
|
207
|
+
* @param dencoder - the NumberStringDencoder to use for encoding
|
|
208
|
+
* @returns a function that normalizes input to an encoded string
|
|
209
|
+
*/
|
|
146
210
|
export declare function numberStringDencoderEncodedStringValueFunction(dencoder: NumberStringDencoder): (input: NumberStringDencoderString | NumberStringDencoderNumber) => NumberStringDencoderString;
|
|
211
|
+
/**
|
|
212
|
+
* Creates a function that always returns the decoded number form of the input.
|
|
213
|
+
* Strings are decoded; numbers are passed through as-is.
|
|
214
|
+
*
|
|
215
|
+
* @param dencoder - the NumberStringDencoder to use for decoding
|
|
216
|
+
* @returns a function that normalizes input to a decoded number
|
|
217
|
+
*/
|
|
147
218
|
export declare function numberStringDencoderDecodedNumberValueFunction(dencoder: NumberStringDencoder): (input: NumberStringDencoderString | NumberStringDencoderNumber) => NumberStringDencoderNumber;
|
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
import { type FactoryWithInput, type Factory, type FactoryWithRequiredInput } from '../getter';
|
|
2
2
|
import { type Maybe } from '../value';
|
|
3
3
|
import { type TransformStringFunctionConfig } from './transform';
|
|
4
|
+
/**
|
|
5
|
+
* A factory that produces a string value with no input.
|
|
6
|
+
*/
|
|
4
7
|
export type StringFactory<K extends string = string> = Factory<K>;
|
|
8
|
+
/**
|
|
9
|
+
* A function that converts a value of type T to a string.
|
|
10
|
+
*/
|
|
5
11
|
export type ToStringFunction<T, K extends string = string> = FactoryWithRequiredInput<K, T>;
|
|
6
12
|
/**
|
|
7
|
-
* Wraps
|
|
13
|
+
* Wraps an existing factory with a {@link ToStringFunction} to produce strings from the factory's output.
|
|
8
14
|
*
|
|
9
|
-
* @param factory
|
|
10
|
-
* @param toStringFunction
|
|
11
|
-
* @returns
|
|
15
|
+
* @param factory - the original value factory
|
|
16
|
+
* @param toStringFunction - function to convert the factory's output to a string
|
|
17
|
+
* @returns a new factory that produces string values
|
|
12
18
|
*/
|
|
13
19
|
export declare function stringFactoryFromFactory<T, K extends string = string>(factory: Factory<T>, toStringFunction: ToStringFunction<T, K>): StringFactory<K>;
|
|
14
20
|
/**
|
|
15
21
|
* A factory that returns a string based on the input date.
|
|
16
22
|
*/
|
|
17
23
|
export type StringFromDateFactory = FactoryWithInput<string, Maybe<Date>>;
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for creating a {@link StringFromDateFactory}.
|
|
26
|
+
*/
|
|
18
27
|
export interface StringFromDateConfig {
|
|
19
28
|
/**
|
|
20
29
|
* The number of digits to return from the end of the generated string.
|
package/src/lib/string/html.d.ts
CHANGED
|
@@ -26,16 +26,17 @@ export type SpaceSeparatedCssStyles = string;
|
|
|
26
26
|
*/
|
|
27
27
|
export type CssClassesArray = ArrayOrValue<ArrayOrValue<SpaceSeparatedCssClasses>>;
|
|
28
28
|
/**
|
|
29
|
-
* Joins together various
|
|
29
|
+
* Joins together various arrays of CSS classes into a single space-separated string of unique class names.
|
|
30
30
|
*
|
|
31
|
-
* @param cssClasses
|
|
32
|
-
* @returns
|
|
31
|
+
* @param cssClasses - one or more CSS class values or arrays of class values
|
|
32
|
+
* @returns a space-separated string of unique CSS class names, or an empty string if input is null/undefined
|
|
33
33
|
*/
|
|
34
34
|
export declare function spaceSeparatedCssClasses(cssClasses: Maybe<CssClassesArray>): SpaceSeparatedCssClasses;
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* Parses and deduplicates CSS classes from various array/string inputs into a Set.
|
|
37
|
+
* Space-separated class strings are split into individual class names.
|
|
37
38
|
*
|
|
38
|
-
* @param cssClasses
|
|
39
|
-
* @returns
|
|
39
|
+
* @param cssClasses - one or more CSS class values or arrays of class values
|
|
40
|
+
* @returns a Set of unique CSS class names, or an empty Set if input is null/undefined
|
|
40
41
|
*/
|
|
41
42
|
export declare function cssClassesSet(cssClasses: Maybe<CssClassesArray>): Set<CssClass>;
|
|
@@ -28,35 +28,77 @@ export type ContentTypeMimeType = string;
|
|
|
28
28
|
* This is a non-exhaustive list of common image types.
|
|
29
29
|
*/
|
|
30
30
|
export type ImageFileExtension = 'jpeg' | 'jpg' | 'png' | 'webp' | 'gif' | 'svg' | 'raw' | 'heif' | 'tiff';
|
|
31
|
+
/** MIME type for JPEG images. */
|
|
31
32
|
export declare const JPEG_MIME_TYPE: MimeTypeWithoutParameters;
|
|
33
|
+
/** MIME type for PNG images. */
|
|
32
34
|
export declare const PNG_MIME_TYPE: MimeTypeWithoutParameters;
|
|
35
|
+
/** MIME type for WebP images. */
|
|
33
36
|
export declare const WEBP_MIME_TYPE: MimeTypeWithoutParameters;
|
|
37
|
+
/** MIME type for GIF images. */
|
|
34
38
|
export declare const GIF_MIME_TYPE: MimeTypeWithoutParameters;
|
|
39
|
+
/** MIME type for HEIF images. */
|
|
35
40
|
export declare const HEIF_MIME_TYPE: MimeTypeWithoutParameters;
|
|
41
|
+
/** MIME type for TIFF images. */
|
|
36
42
|
export declare const TIFF_MIME_TYPE: MimeTypeWithoutParameters;
|
|
43
|
+
/** MIME type for SVG images. */
|
|
37
44
|
export declare const SVG_MIME_TYPE: MimeTypeWithoutParameters;
|
|
45
|
+
/** MIME type for RAW images. */
|
|
38
46
|
export declare const RAW_MIME_TYPE: MimeTypeWithoutParameters;
|
|
47
|
+
/**
|
|
48
|
+
* Maps image file extensions to their corresponding MIME types.
|
|
49
|
+
*/
|
|
39
50
|
export declare const IMAGE_FILE_EXTENSION_TO_MIME_TYPES_RECORD: Record<ImageFileExtension, MimeTypeWithoutParameters>;
|
|
51
|
+
/**
|
|
52
|
+
* Maps image MIME types back to their corresponding file extensions.
|
|
53
|
+
*/
|
|
40
54
|
export declare const IMAGE_MIME_TYPES_TO_FILE_EXTENSIONS_RECORD: Record<MimeTypeWithoutParameters, ImageFileExtension>;
|
|
41
55
|
/**
|
|
42
|
-
* Returns the
|
|
56
|
+
* Returns the MIME type for the given image file extension, or undefined if the extension is not recognized.
|
|
57
|
+
*
|
|
58
|
+
* @param extension - the image file extension to look up
|
|
59
|
+
* @returns the corresponding MIME type, or undefined if the extension is not known
|
|
43
60
|
*/
|
|
44
61
|
export declare function mimeTypeForImageFileExtension(extension: ImageFileExtension): MimeTypeWithoutParameters;
|
|
45
62
|
export declare function mimeTypeForImageFileExtension(extension: SlashPathTypedFileExtension): Maybe<MimeTypeWithoutParameters>;
|
|
46
63
|
export declare function mimeTypeForImageFileExtension(extension: Maybe<ImageFileExtension | SlashPathTypedFileExtension>): Maybe<MimeTypeWithoutParameters>;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the image file extension for the given MIME type, or undefined if the MIME type is not a known image type.
|
|
66
|
+
*
|
|
67
|
+
* @param mimeType - the MIME type to look up
|
|
68
|
+
* @returns the corresponding image file extension, or undefined if not recognized
|
|
69
|
+
*/
|
|
47
70
|
export declare function imageFileExtensionForMimeType(mimeType: Maybe<MimeTypeWithoutParameters>): Maybe<ImageFileExtension>;
|
|
71
|
+
/**
|
|
72
|
+
* Non-exhaustive list of common document file extensions.
|
|
73
|
+
*/
|
|
48
74
|
export type DocumentFileExtension = 'pdf' | 'docx' | 'xlsx' | 'txt' | 'csv' | 'html' | 'xml' | 'json' | 'yaml' | 'md';
|
|
75
|
+
/** MIME type for PDF documents. */
|
|
49
76
|
export declare const PDF_MIME_TYPE: MimeTypeWithoutParameters;
|
|
77
|
+
/** MIME type for DOCX (Word) documents. */
|
|
50
78
|
export declare const DOCX_MIME_TYPE: MimeTypeWithoutParameters;
|
|
79
|
+
/** MIME type for XLSX (Excel) spreadsheets. */
|
|
51
80
|
export declare const XLSX_MIME_TYPE: MimeTypeWithoutParameters;
|
|
81
|
+
/** MIME type for plain text files. */
|
|
52
82
|
export declare const TXT_MIME_TYPE: MimeTypeWithoutParameters;
|
|
83
|
+
/** MIME type for CSV files. */
|
|
53
84
|
export declare const CSV_MIME_TYPE: MimeTypeWithoutParameters;
|
|
85
|
+
/** MIME type for HTML files. */
|
|
54
86
|
export declare const HTML_MIME_TYPE: MimeTypeWithoutParameters;
|
|
87
|
+
/** MIME type for XML files. */
|
|
55
88
|
export declare const XML_MIME_TYPE: MimeTypeWithoutParameters;
|
|
89
|
+
/** MIME type for JSON files. */
|
|
56
90
|
export declare const JSON_MIME_TYPE: MimeTypeWithoutParameters;
|
|
91
|
+
/** MIME type for YAML files. */
|
|
57
92
|
export declare const YAML_MIME_TYPE: MimeTypeWithoutParameters;
|
|
93
|
+
/** MIME type for Markdown files. */
|
|
58
94
|
export declare const MARKDOWN_MIME_TYPE: MimeTypeWithoutParameters;
|
|
95
|
+
/**
|
|
96
|
+
* Maps document file extensions to their corresponding MIME types.
|
|
97
|
+
*/
|
|
59
98
|
export declare const DOCUMENT_FILE_EXTENSION_TO_MIME_TYPES_RECORD: Record<DocumentFileExtension, MimeTypeWithoutParameters>;
|
|
99
|
+
/**
|
|
100
|
+
* Maps document MIME types back to their corresponding file extensions.
|
|
101
|
+
*/
|
|
60
102
|
export declare const DOCUMENT_MIME_TYPES_TO_FILE_EXTENSIONS_RECORD: Record<MimeTypeWithoutParameters, DocumentFileExtension>;
|
|
61
103
|
/**
|
|
62
104
|
* Returns the mimetype for the given document file extension, or undefined if the extension is not known/recognized.
|
|
@@ -74,9 +116,19 @@ export declare function mimeTypeForDocumentFileExtension(extension: Maybe<Docume
|
|
|
74
116
|
* @returns The document file extension for the given mimetype, or undefined if the mimetype is not known.
|
|
75
117
|
*/
|
|
76
118
|
export declare function documentFileExtensionForMimeType(mimeType: Maybe<MimeTypeWithoutParameters>): Maybe<DocumentFileExtension>;
|
|
119
|
+
/**
|
|
120
|
+
* Non-exhaustive list of common application file extensions.
|
|
121
|
+
*/
|
|
77
122
|
export type ApplicationFileExtension = 'zip';
|
|
123
|
+
/** MIME type for ZIP archive files. */
|
|
78
124
|
export declare const ZIP_FILE_MIME_TYPE: MimeTypeWithoutParameters;
|
|
125
|
+
/**
|
|
126
|
+
* Maps application file extensions to their corresponding MIME types.
|
|
127
|
+
*/
|
|
79
128
|
export declare const APPLICATION_FILE_EXTENSION_TO_MIME_TYPES_RECORD: Record<ApplicationFileExtension, MimeTypeWithoutParameters>;
|
|
129
|
+
/**
|
|
130
|
+
* Maps application MIME types back to their corresponding file extensions.
|
|
131
|
+
*/
|
|
80
132
|
export declare const APPLICATION_MIME_TYPES_TO_FILE_EXTENSIONS_RECORD: Record<MimeTypeWithoutParameters, ApplicationFileExtension>;
|
|
81
133
|
/**
|
|
82
134
|
* Returns the mimetype for the given application file extension, or undefined if the extension is not known/recognized.
|
|
@@ -87,6 +139,12 @@ export declare const APPLICATION_MIME_TYPES_TO_FILE_EXTENSIONS_RECORD: Record<Mi
|
|
|
87
139
|
export declare function mimeTypeForApplicationFileExtension(extension: ApplicationFileExtension): MimeTypeWithoutParameters;
|
|
88
140
|
export declare function mimeTypeForApplicationFileExtension(extension: SlashPathTypedFileExtension): Maybe<MimeTypeWithoutParameters>;
|
|
89
141
|
export declare function mimeTypeForApplicationFileExtension(extension: Maybe<ApplicationFileExtension | SlashPathTypedFileExtension>): Maybe<MimeTypeWithoutParameters>;
|
|
142
|
+
/**
|
|
143
|
+
* Returns the application file extension for the given MIME type, or undefined if the MIME type is not a known application type.
|
|
144
|
+
*
|
|
145
|
+
* @param mimeType - the MIME type to look up
|
|
146
|
+
* @returns the corresponding application file extension, or undefined if not recognized
|
|
147
|
+
*/
|
|
90
148
|
export declare function applicationFileExtensionForMimeType(mimeType: Maybe<MimeTypeWithoutParameters>): Maybe<ApplicationFileExtension>;
|
|
91
149
|
/**
|
|
92
150
|
* List of known file extensions supported by dbx-components.
|
|
@@ -103,6 +161,12 @@ export type DbxComponentsKnownFileExtension = ImageFileExtension | DocumentFileE
|
|
|
103
161
|
export declare function mimeTypeForFileExtension(extension: DbxComponentsKnownFileExtension): MimeTypeWithoutParameters;
|
|
104
162
|
export declare function mimeTypeForFileExtension(extension: SlashPathTypedFileExtension): Maybe<MimeTypeWithoutParameters>;
|
|
105
163
|
export declare function mimeTypeForFileExtension(extension: Maybe<DbxComponentsKnownFileExtension | SlashPathTypedFileExtension>): Maybe<MimeTypeWithoutParameters>;
|
|
164
|
+
/**
|
|
165
|
+
* Returns the file extension for the given MIME type by checking image, document, and application types in order.
|
|
166
|
+
*
|
|
167
|
+
* @param mimeType - the MIME type to look up
|
|
168
|
+
* @returns the corresponding file extension, or undefined if the MIME type is not recognized
|
|
169
|
+
*/
|
|
106
170
|
export declare function fileExtensionForMimeType(mimeType: Maybe<MimeTypeWithoutParameters>): Maybe<DbxComponentsKnownFileExtension>;
|
|
107
171
|
/**
|
|
108
172
|
* A content disposition string, which is used to determine how the browser should show the target content.
|
|
@@ -27,6 +27,12 @@ export type CharacterPrefixString<P extends CharacterPrefix = '', T extends stri
|
|
|
27
27
|
* A string that has a known suffix.
|
|
28
28
|
*/
|
|
29
29
|
export type CharacterSuffixString<S extends CharacterSuffix = '', T extends string = string> = CharacterPrefixSuffixString<'', S, T>;
|
|
30
|
+
/**
|
|
31
|
+
* Configuration for creating a {@link CharacterPrefixSuffixInstance} that manages adding and removing prefix/suffix strings.
|
|
32
|
+
*
|
|
33
|
+
* @template P - The prefix string type.
|
|
34
|
+
* @template S - The suffix string type.
|
|
35
|
+
*/
|
|
30
36
|
export interface CharacterPrefixSuffixInstanceConfiguration<P extends CharacterPrefix = '', S extends CharacterSuffix = ''> {
|
|
31
37
|
/**
|
|
32
38
|
* The prefix characters to add/remove to/from the start of the string.
|
|
@@ -45,28 +51,36 @@ export interface CharacterPrefixSuffixInstanceConfiguration<P extends CharacterP
|
|
|
45
51
|
*/
|
|
46
52
|
readonly suffixEmptyString?: boolean;
|
|
47
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Instance that can add or remove a configured prefix and/or suffix from strings.
|
|
56
|
+
*
|
|
57
|
+
* @template P - The prefix string type.
|
|
58
|
+
* @template S - The suffix string type.
|
|
59
|
+
*/
|
|
48
60
|
export interface CharacterPrefixSuffixInstance<P extends CharacterPrefix = '', S extends CharacterSuffix = ''> extends CharacterPrefixSuffixInstanceConfiguration<P, S> {
|
|
49
61
|
/**
|
|
50
|
-
* Adds the prefix and suffix to the input string.
|
|
62
|
+
* Adds the prefix and suffix to the input string. Cleans any existing prefix/suffix before adding.
|
|
51
63
|
*
|
|
52
|
-
* @param input
|
|
64
|
+
* @param input - The string to prefix and suffix.
|
|
65
|
+
* @returns The string with prefix and suffix applied.
|
|
53
66
|
*/
|
|
54
67
|
prefixSuffixString(input: ''): string;
|
|
55
68
|
prefixSuffixString<T extends string>(input: T | CharacterPrefixSuffixString<P, S, T> | CharacterPrefixString<P, T> | CharacterSuffixString<S, T>): CharacterPrefixSuffixString<P, S, T>;
|
|
56
69
|
prefixSuffixString(input: string): CharacterPrefixSuffixString<P, S>;
|
|
57
70
|
/**
|
|
58
|
-
* Removes the prefix and suffix from the input string.
|
|
71
|
+
* Removes the prefix and suffix from the input string, stripping repeated occurrences.
|
|
59
72
|
*
|
|
60
|
-
* @param input
|
|
73
|
+
* @param input - The string to clean.
|
|
74
|
+
* @returns The string with prefix and suffix removed.
|
|
61
75
|
*/
|
|
62
76
|
cleanString<T extends string>(input: T | CharacterPrefixSuffixString<P, S, T> | CharacterPrefixString<P, T> | CharacterSuffixString<S, T>): T;
|
|
63
77
|
cleanString(input: string): string;
|
|
64
78
|
}
|
|
65
79
|
/**
|
|
66
|
-
* Creates a CharacterPrefixSuffixInstance
|
|
80
|
+
* Creates a {@link CharacterPrefixSuffixInstance} that can add or remove configured prefix/suffix strings.
|
|
67
81
|
*
|
|
68
|
-
* @param config
|
|
69
|
-
* @returns
|
|
82
|
+
* @param config - Configuration specifying the prefix, suffix, and empty string behavior.
|
|
83
|
+
* @returns A new instance for managing prefix/suffix operations on strings.
|
|
70
84
|
*/
|
|
71
85
|
export declare function characterPrefixSuffixInstance<P extends CharacterPrefix = '', S extends CharacterSuffix = ''>(config: CharacterPrefixSuffixInstanceConfiguration<P, S>): CharacterPrefixSuffixInstance<P, S>;
|
|
72
86
|
/**
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A record where
|
|
2
|
+
* A record where both keys and values are typed strings.
|
|
3
|
+
*
|
|
4
|
+
* @template K - The key string type.
|
|
5
|
+
* @template V - The value string type.
|
|
3
6
|
*/
|
|
4
7
|
export type StringRecord<K extends string, V extends string> = Record<K, V>;
|
|
5
8
|
/**
|
|
6
|
-
* Inverts a string record
|
|
9
|
+
* Inverts a string record by swapping each entry's key and value.
|
|
7
10
|
*
|
|
8
|
-
* @param record
|
|
9
|
-
* @returns
|
|
11
|
+
* @param record - The record to invert.
|
|
12
|
+
* @returns A new record with the original values as keys and the original keys as values.
|
|
10
13
|
*/
|
|
11
14
|
export declare function invertStringRecord<K extends string, V extends string>(record: StringRecord<K, V>): StringRecord<V, K>;
|