@dereekb/util 13.2.2 → 13.3.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/index.cjs.js +17 -0
- package/fetch/index.esm.js +17 -1
- package/fetch/package.json +2 -2
- package/fetch/src/lib/fetch.url.d.ts +30 -0
- package/index.cjs.js +329 -50
- package/index.esm.js +318 -51
- package/package.json +1 -1
- package/src/lib/date/date.d.ts +4 -0
- package/src/lib/encryption/encryption.object.d.ts +111 -0
- package/src/lib/encryption/index.d.ts +1 -0
- package/src/lib/file/index.d.ts +1 -0
- package/src/lib/index.d.ts +1 -0
- package/src/lib/number/encoded.d.ts +70 -0
- package/src/lib/number/index.d.ts +1 -0
- package/src/lib/object/object.d.ts +4 -0
- package/src/lib/string/string.d.ts +182 -47
- package/src/lib/string/url.d.ts +5 -1
- package/src/lib/value/label.d.ts +6 -0
- package/test/index.cjs.js +2 -2
- package/test/index.esm.js +2 -2
- package/test/package.json +2 -2
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Branded type representing a string that has been encrypted.
|
|
3
|
+
*
|
|
4
|
+
* Use this type to distinguish encrypted ciphertext from plain strings at the type level.
|
|
5
|
+
* The actual encryption algorithm is determined by the {@link StringEncryptionProvider}.
|
|
6
|
+
*/
|
|
7
|
+
export type EncryptedString = string;
|
|
8
|
+
/**
|
|
9
|
+
* Encrypts a plaintext string to an encrypted string.
|
|
10
|
+
*/
|
|
11
|
+
export type EncryptStringFunction = (plaintext: string) => EncryptedString;
|
|
12
|
+
/**
|
|
13
|
+
* Decrypts an encrypted string back to plaintext.
|
|
14
|
+
*/
|
|
15
|
+
export type DecryptStringFunction = (ciphertext: EncryptedString) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Provider that can encrypt and decrypt strings.
|
|
18
|
+
*
|
|
19
|
+
* Implementations wrap a specific algorithm (e.g. AES-256-GCM) and key management
|
|
20
|
+
* behind a simple encrypt/decrypt interface for use with selective field encryption.
|
|
21
|
+
*/
|
|
22
|
+
export interface StringEncryptionProvider {
|
|
23
|
+
readonly encrypt: EncryptStringFunction;
|
|
24
|
+
readonly decrypt: DecryptStringFunction;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Configuration for selective object field encryption.
|
|
28
|
+
*
|
|
29
|
+
* @template T - The object type being encrypted.
|
|
30
|
+
* @template F - The union of field names to encrypt.
|
|
31
|
+
*/
|
|
32
|
+
export interface SelectiveFieldEncryptionConfig<T, F extends keyof T> {
|
|
33
|
+
/**
|
|
34
|
+
* The encryption provider for string encrypt/decrypt.
|
|
35
|
+
*/
|
|
36
|
+
readonly provider: StringEncryptionProvider;
|
|
37
|
+
/**
|
|
38
|
+
* Fields to encrypt/decrypt.
|
|
39
|
+
*/
|
|
40
|
+
readonly fields: F[];
|
|
41
|
+
/**
|
|
42
|
+
* Prefix marker for encrypted fields.
|
|
43
|
+
*
|
|
44
|
+
* @defaultValue '$'
|
|
45
|
+
*/
|
|
46
|
+
readonly prefix?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Default prefix used for encrypted field names.
|
|
50
|
+
*/
|
|
51
|
+
export declare const DEFAULT_ENCRYPTED_FIELD_PREFIX = "$";
|
|
52
|
+
/**
|
|
53
|
+
* Maps an object type so that specified fields are removed and replaced with
|
|
54
|
+
* prefixed encrypted string fields.
|
|
55
|
+
*
|
|
56
|
+
* Given `{ a: number; b: string; c: boolean }` with fields `['a', 'b']` and prefix `'$'`,
|
|
57
|
+
* produces `{ $a: EncryptedString; $b: EncryptedString; c: boolean }`.
|
|
58
|
+
*
|
|
59
|
+
* @template T - The original object type.
|
|
60
|
+
* @template F - Union of field names to encrypt.
|
|
61
|
+
* @template Prefix - The string prefix for encrypted field names.
|
|
62
|
+
*/
|
|
63
|
+
export type SelectivelyEncryptedObject<T, F extends keyof T, Prefix extends string = '$'> = Omit<T, F> & {
|
|
64
|
+
[K in F as `${Prefix}${string & K}`]: EncryptedString;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Instance that can encrypt/decrypt specific fields on an object.
|
|
68
|
+
*
|
|
69
|
+
* @template T - The original object type.
|
|
70
|
+
* @template F - Union of field names to encrypt.
|
|
71
|
+
*/
|
|
72
|
+
export interface SelectiveFieldEncryptor<T, F extends keyof T> {
|
|
73
|
+
/**
|
|
74
|
+
* Encrypts specified fields, producing an object with prefixed encrypted keys.
|
|
75
|
+
*
|
|
76
|
+
* Original field keys are removed and replaced with `${prefix}${fieldName}` keys
|
|
77
|
+
* whose values are encrypted strings.
|
|
78
|
+
*/
|
|
79
|
+
encrypt(input: T): SelectivelyEncryptedObject<T, F>;
|
|
80
|
+
/**
|
|
81
|
+
* Decrypts prefixed encrypted keys back to the original field names and values.
|
|
82
|
+
*
|
|
83
|
+
* Prefixed keys are removed and replaced with the original field keys. If a prefixed
|
|
84
|
+
* key is missing, the field is skipped (it wasn't present in the original).
|
|
85
|
+
*/
|
|
86
|
+
decrypt(input: SelectivelyEncryptedObject<T, F>): T;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Creates a selective field encryptor that encrypts/decrypts specific fields on an object.
|
|
90
|
+
*
|
|
91
|
+
* Each encrypted field's value is JSON.stringified before encryption and JSON.parsed after
|
|
92
|
+
* decryption, so fields can hold any JSON-serializable value (not just strings).
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const encryptor = selectiveFieldEncryptor({
|
|
97
|
+
* provider: myEncryptionProvider,
|
|
98
|
+
* fields: ['client_secret'] as const
|
|
99
|
+
* });
|
|
100
|
+
*
|
|
101
|
+
* const encrypted = encryptor.encrypt({ client_id: 'abc', client_secret: 's3cret' });
|
|
102
|
+
* // encrypted => { client_id: 'abc', $client_secret: '<ciphertext>' }
|
|
103
|
+
*
|
|
104
|
+
* const decrypted = encryptor.decrypt(encrypted);
|
|
105
|
+
* // decrypted => { client_id: 'abc', client_secret: 's3cret' }
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @param config - Encryption configuration specifying provider, fields, and optional prefix.
|
|
109
|
+
* @returns A selective field encryptor instance.
|
|
110
|
+
*/
|
|
111
|
+
export declare function selectiveFieldEncryptor<T extends object, F extends keyof T>(config: SelectiveFieldEncryptionConfig<T, F>): SelectiveFieldEncryptor<T, F>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './encryption.object';
|
package/src/lib/file/index.d.ts
CHANGED
package/src/lib/index.d.ts
CHANGED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A number encoded as a radix-36 string using digits 0-9 and letters a-z.
|
|
3
|
+
*
|
|
4
|
+
* Radix-36 encoding produces compact string representations of numbers,
|
|
5
|
+
* useful for URL-safe identifiers and short codes.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const encoded: Radix36EncodedNumber = 'z'; // represents 35
|
|
10
|
+
* const largeEncoded: Radix36EncodedNumber = '2s'; // represents 100
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export type Radix36EncodedNumber = string;
|
|
14
|
+
/**
|
|
15
|
+
* Encodes a number as a radix-36 string.
|
|
16
|
+
*
|
|
17
|
+
* Uses digits 0-9 and lowercase letters a-z, producing compact representations
|
|
18
|
+
* that are useful for URL-safe identifiers and short codes.
|
|
19
|
+
*
|
|
20
|
+
* @param number - The number to encode. Should be a non-negative integer for consistent results.
|
|
21
|
+
* @returns The radix-36 encoded string representation.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* encodeRadix36Number(0); // '0'
|
|
26
|
+
* encodeRadix36Number(35); // 'z'
|
|
27
|
+
* encodeRadix36Number(100); // '2s'
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function encodeRadix36Number(number: number): Radix36EncodedNumber;
|
|
31
|
+
/**
|
|
32
|
+
* Decodes a radix-36 encoded string back to a number.
|
|
33
|
+
*
|
|
34
|
+
* Parses a string containing digits 0-9 and letters a-z (case-insensitive)
|
|
35
|
+
* as a base-36 number.
|
|
36
|
+
*
|
|
37
|
+
* @param encoded - The radix-36 encoded string to decode.
|
|
38
|
+
* @returns The decoded numeric value. Returns `NaN` if the input is not a valid radix-36 string.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* decodeRadix36Number('0'); // 0
|
|
43
|
+
* decodeRadix36Number('z'); // 35
|
|
44
|
+
* decodeRadix36Number('2s'); // 100
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function decodeRadix36Number(encoded: Radix36EncodedNumber): number;
|
|
48
|
+
/**
|
|
49
|
+
* A string containing only hexadecimal characters (0-9, a-f or A-F).
|
|
50
|
+
*/
|
|
51
|
+
export type HexString = string;
|
|
52
|
+
/**
|
|
53
|
+
* Pattern that matches strings containing only hexadecimal characters (0-9, a-f, A-F).
|
|
54
|
+
*/
|
|
55
|
+
export declare const HEX_PATTERN: RegExp;
|
|
56
|
+
/**
|
|
57
|
+
* Checks whether the input string contains only valid hexadecimal characters.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* isHex('a1b2c3'); // true
|
|
62
|
+
* isHex('FF00AA'); // true
|
|
63
|
+
* isHex('hello'); // false
|
|
64
|
+
* isHex(''); // false
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @param value - The string to check.
|
|
68
|
+
* @returns True if the string is non-empty and contains only hex characters.
|
|
69
|
+
*/
|
|
70
|
+
export declare function isHex(value: string): value is HexString;
|
|
@@ -5,6 +5,10 @@ import { type KeyAsString } from '../type';
|
|
|
5
5
|
* Any valid Plain-old Javascript Object key.
|
|
6
6
|
*/
|
|
7
7
|
export type POJOKey = PrimativeKey | symbol;
|
|
8
|
+
/**
|
|
9
|
+
* This is an object that can be serialized to JSON and back and be equivalent.
|
|
10
|
+
*/
|
|
11
|
+
export type JsonSerializableObject = Record<PrimativeKey, any>;
|
|
8
12
|
/**
|
|
9
13
|
* String key of an object.
|
|
10
14
|
*/
|
|
@@ -9,6 +9,12 @@ export type MapStringFunction<T> = MapFunction<string, T>;
|
|
|
9
9
|
* Reads a string from the input value.
|
|
10
10
|
*/
|
|
11
11
|
export type ReadStringFunction<T, S extends string = string> = MapFunction<T, S>;
|
|
12
|
+
/**
|
|
13
|
+
* Represents a string that is made up of values separated by a delimiter.
|
|
14
|
+
*
|
|
15
|
+
* Optional generic typing exists for communicating what values are separated within the string.
|
|
16
|
+
*/
|
|
17
|
+
export type SeparatedString<T = unknown> = string;
|
|
12
18
|
/**
|
|
13
19
|
* Represents a string that is made up of comma-separated values.
|
|
14
20
|
*
|
|
@@ -16,7 +22,7 @@ export type ReadStringFunction<T, S extends string = string> = MapFunction<T, S>
|
|
|
16
22
|
*
|
|
17
23
|
* I.E. 0,1,2
|
|
18
24
|
*/
|
|
19
|
-
export type CommaSeparatedString<T = unknown> =
|
|
25
|
+
export type CommaSeparatedString<T = unknown> = SeparatedString<T>;
|
|
20
26
|
/**
|
|
21
27
|
* Represents a string that is made up of space-separated values.
|
|
22
28
|
*
|
|
@@ -24,20 +30,15 @@ export type CommaSeparatedString<T = unknown> = string;
|
|
|
24
30
|
*
|
|
25
31
|
* I.E. 0 1 2
|
|
26
32
|
*/
|
|
27
|
-
export type SpaceSeparatedString<T = unknown> =
|
|
33
|
+
export type SpaceSeparatedString<T = unknown> = SeparatedString<T>;
|
|
28
34
|
/**
|
|
29
35
|
* Default comma joiner character used by comma-related string functions.
|
|
30
36
|
*/
|
|
31
37
|
export declare const COMMA_JOINER = ",";
|
|
32
38
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* @param input - string to convert to lowercase
|
|
36
|
-
* @returns the lowercased string, or undefined if the input is undefined
|
|
39
|
+
* Default space joiner character used by space-related string functions.
|
|
37
40
|
*/
|
|
38
|
-
export declare
|
|
39
|
-
export declare function caseInsensitiveString(input: undefined): undefined;
|
|
40
|
-
export declare function caseInsensitiveString(input: Maybe<string>): Maybe<string>;
|
|
41
|
+
export declare const SPACE_JOINER = " ";
|
|
41
42
|
/**
|
|
42
43
|
* Joins an array of strings into a single string. Trims and omits empty values.
|
|
43
44
|
*
|
|
@@ -49,30 +50,137 @@ export declare function caseInsensitiveString(input: Maybe<string>): Maybe<strin
|
|
|
49
50
|
export declare function joinStrings(input: MaybeNot, joiner?: string, trim?: boolean): MaybeNot;
|
|
50
51
|
export declare function joinStrings(input: ArrayOrValue<Maybe<string>>, joiner?: string, trim?: boolean): string;
|
|
51
52
|
/**
|
|
52
|
-
*
|
|
53
|
+
* Splits a string like {@link String.prototype.split}, but joins overflow segments back together
|
|
54
|
+
* instead of discarding them. Useful when you only want to split on the first N-1 occurrences.
|
|
53
55
|
*
|
|
54
|
-
* @param input string
|
|
55
|
-
* @param
|
|
56
|
-
* @
|
|
56
|
+
* @param input - string to split
|
|
57
|
+
* @param separator - delimiter to split on
|
|
58
|
+
* @param limit - maximum number of resulting segments; overflow segments are rejoined with the separator
|
|
59
|
+
* @returns array of string segments, with length at most equal to limit
|
|
57
60
|
*/
|
|
58
|
-
export declare function
|
|
59
|
-
export declare function joinStringsWithCommas(input: ArrayOrValue<Maybe<string>>): string;
|
|
61
|
+
export declare function splitJoinRemainder(input: string, separator: string, limit: number): string[];
|
|
60
62
|
/**
|
|
61
|
-
*
|
|
63
|
+
* A callable instance that joins arrays of strings using a configured delimiter.
|
|
62
64
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @
|
|
65
|
+
* Can be called directly as a function or accessed for its configuration properties.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* const join = joinStringsInstance({ joiner: ',' });
|
|
70
|
+
* join(['a', 'b', 'c']); // 'a,b,c'
|
|
71
|
+
* join.joiner; // ','
|
|
72
|
+
* ```
|
|
66
73
|
*/
|
|
67
|
-
export
|
|
68
|
-
|
|
74
|
+
export interface JoinStringsInstance<T extends string = string> {
|
|
75
|
+
readonly joiner: string;
|
|
76
|
+
readonly trimByDefault: boolean;
|
|
77
|
+
(input: MaybeNot): MaybeNot;
|
|
78
|
+
(input: ArrayOrValue<Maybe<string>>): T;
|
|
79
|
+
(input: Maybe<ArrayOrValue<Maybe<string>>>, trim?: boolean): Maybe<T>;
|
|
80
|
+
}
|
|
69
81
|
/**
|
|
70
|
-
*
|
|
82
|
+
* Configuration for creating a {@link JoinStringsInstance}.
|
|
83
|
+
*/
|
|
84
|
+
export interface JoinStringsInstanceConfig {
|
|
85
|
+
/**
|
|
86
|
+
* The delimiter character to use for splitting and joining.
|
|
87
|
+
*/
|
|
88
|
+
readonly joiner: string;
|
|
89
|
+
/**
|
|
90
|
+
* Whether or not to trim values before joining.
|
|
91
|
+
*
|
|
92
|
+
* Defaults to false.
|
|
93
|
+
*/
|
|
94
|
+
readonly trimByDefault?: boolean;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Creates a {@link JoinStringsInstance} that joins arrays of strings using the configured delimiter.
|
|
71
98
|
*
|
|
72
|
-
* @
|
|
73
|
-
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* const joinWithPipe = joinStringsInstance({ joiner: '|' });
|
|
102
|
+
* joinWithPipe(['a', 'b']); // 'a|b'
|
|
103
|
+
* joinWithPipe(null); // null
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @param config - configuration for the delimiter and default trim behavior
|
|
107
|
+
* @returns a new callable {@link JoinStringsInstance}
|
|
74
108
|
*/
|
|
75
|
-
export declare function
|
|
109
|
+
export declare function joinStringsInstance<T extends string = string>(config: JoinStringsInstanceConfig): JoinStringsInstance<T>;
|
|
110
|
+
/**
|
|
111
|
+
* An instance that provides split and join operations for strings using a configured delimiter.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const instance = stringSplitJoinInstance({ joiner: ',' });
|
|
116
|
+
* instance.joinStrings(['a', 'b', 'c']); // 'a,b,c'
|
|
117
|
+
* instance.splitStrings('a,b,c'); // ['a', 'b', 'c']
|
|
118
|
+
* instance.splitStringsToSet('a,b,a'); // Set {'a', 'b'}
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export interface StringSplitJoinInstance<T extends string = string> extends Pick<JoinStringsInstance<T>, 'joiner' | 'trimByDefault'> {
|
|
122
|
+
/**
|
|
123
|
+
* Joins an array of strings into a single delimited string. Filters out null/undefined values.
|
|
124
|
+
*/
|
|
125
|
+
joinStrings(input: MaybeNot): MaybeNot;
|
|
126
|
+
joinStrings(input: ArrayOrValue<Maybe<string>>): T;
|
|
127
|
+
joinStrings(input: Maybe<ArrayOrValue<Maybe<string>>>, trim?: boolean): Maybe<T>;
|
|
128
|
+
/**
|
|
129
|
+
* Splits a delimited string into an array of trimmed strings, optionally mapping each value.
|
|
130
|
+
*/
|
|
131
|
+
splitStrings(input: T): string[];
|
|
132
|
+
splitStrings<O>(input: T, mapFn: MapStringFunction<O>): O[];
|
|
133
|
+
/**
|
|
134
|
+
* Splits a delimited string into a Set of unique trimmed string values.
|
|
135
|
+
*
|
|
136
|
+
* Returns an empty set if the input is null/undefined.
|
|
137
|
+
*/
|
|
138
|
+
splitStringsToSet(input: Maybe<T>): Set<string>;
|
|
139
|
+
/**
|
|
140
|
+
* Splits the input string by the configured delimiter, joining overflow segments back together
|
|
141
|
+
* instead of discarding them. Useful when you only want to split on the first N-1 occurrences.
|
|
142
|
+
*
|
|
143
|
+
* @param input - string to split
|
|
144
|
+
* @param limit - maximum number of resulting segments; overflow segments are rejoined with the delimiter
|
|
145
|
+
* @returns array of string segments, with length at most equal to limit
|
|
146
|
+
*/
|
|
147
|
+
splitJoinRemainder(input: string, limit: number): string[];
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Configuration for creating a {@link StringSplitJoinInstance}.
|
|
151
|
+
*/
|
|
152
|
+
export type StringSplitJoinInstanceConfig = JoinStringsInstanceConfig;
|
|
153
|
+
/**
|
|
154
|
+
* Creates a {@link StringSplitJoinInstance} that splits and joins strings using the configured delimiter.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* const pipeSplitJoin = stringSplitJoinInstance({ joiner: '|' });
|
|
159
|
+
* pipeSplitJoin.joinStrings(['a', 'b']); // 'a|b'
|
|
160
|
+
* pipeSplitJoin.splitStrings('a|b'); // ['a', 'b']
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @param config - configuration for the delimiter and default trim behavior
|
|
164
|
+
* @returns a new {@link StringSplitJoinInstance}
|
|
165
|
+
*/
|
|
166
|
+
export declare function stringSplitJoinInstance<T extends string = string>(config: StringSplitJoinInstanceConfig): StringSplitJoinInstance<T>;
|
|
167
|
+
/**
|
|
168
|
+
* Global {@link StringSplitJoinInstance} that uses commas as the delimiter.
|
|
169
|
+
*/
|
|
170
|
+
export declare const COMMA_STRING_SPLIT_JOIN: StringSplitJoinInstance<CommaSeparatedString>;
|
|
171
|
+
/**
|
|
172
|
+
* Global {@link StringSplitJoinInstance} that uses spaces as the delimiter, with trimming enabled by default.
|
|
173
|
+
*/
|
|
174
|
+
export declare const SPACE_STRING_SPLIT_JOIN: StringSplitJoinInstance<SpaceSeparatedString>;
|
|
175
|
+
/**
|
|
176
|
+
* Converts a string to its lowercase equivalent for case-insensitive comparison.
|
|
177
|
+
*
|
|
178
|
+
* @param input - string to convert to lowercase
|
|
179
|
+
* @returns the lowercased string, or undefined if the input is undefined
|
|
180
|
+
*/
|
|
181
|
+
export declare function caseInsensitiveString(input: string): string;
|
|
182
|
+
export declare function caseInsensitiveString(input: undefined): undefined;
|
|
183
|
+
export declare function caseInsensitiveString(input: Maybe<string>): Maybe<string>;
|
|
76
184
|
/**
|
|
77
185
|
* Adds a plus prefix to the input value and converts it to a string. If the value is negative or 0, no prefix is added.
|
|
78
186
|
*
|
|
@@ -97,24 +205,10 @@ export declare function capitalizeFirstLetter(value: string): string;
|
|
|
97
205
|
* @returns the input string with its first character lowercased
|
|
98
206
|
*/
|
|
99
207
|
export declare function lowercaseFirstLetter(value: string): string;
|
|
100
|
-
/**
|
|
101
|
-
* Splits a string like {@link String.prototype.split}, but joins overflow segments back together
|
|
102
|
-
* instead of discarding them. Useful when you only want to split on the first N-1 occurrences.
|
|
103
|
-
*
|
|
104
|
-
* @param input - string to split
|
|
105
|
-
* @param separator - delimiter to split on
|
|
106
|
-
* @param limit - maximum number of resulting segments; overflow segments are rejoined with the separator
|
|
107
|
-
* @returns array of string segments, with length at most equal to limit
|
|
108
|
-
*/
|
|
109
|
-
export declare function splitJoinRemainder(input: string, separator: string, limit: number): string[];
|
|
110
208
|
/**
|
|
111
209
|
* A tuple of [firstName, lastName] where lastName may be undefined if the input has no space.
|
|
112
210
|
*/
|
|
113
211
|
export type FirstNameLastNameTuple = [string, string | undefined];
|
|
114
|
-
/**
|
|
115
|
-
* Default space joiner character used by space-related string functions.
|
|
116
|
-
*/
|
|
117
|
-
export declare const SPACE_JOINER = " ";
|
|
118
212
|
/**
|
|
119
213
|
* Splits the input string into a first name and last name tuple using a space as the delimiter.
|
|
120
214
|
* If the name contains more than one space, the remainder is treated as the last name.
|
|
@@ -123,14 +217,6 @@ export declare const SPACE_JOINER = " ";
|
|
|
123
217
|
* @returns a tuple of [firstName, lastName], where lastName includes all text after the first space
|
|
124
218
|
*/
|
|
125
219
|
export declare function splitJoinNameString(input: string): FirstNameLastNameTuple;
|
|
126
|
-
/**
|
|
127
|
-
* Joins one or more strings together with spaces. Extra spaces are trimmed from the values.
|
|
128
|
-
*
|
|
129
|
-
* @param input string or array of strings
|
|
130
|
-
* @returns joined string, or null/undefined if the input is null/undefined
|
|
131
|
-
*/
|
|
132
|
-
export declare function joinStringsWithSpaces(input: MaybeNot): MaybeNot;
|
|
133
|
-
export declare function joinStringsWithSpaces(input: ArrayOrValue<Maybe<string>>): string;
|
|
134
220
|
/**
|
|
135
221
|
* Creates a string that repeats the given string a specified number of times.
|
|
136
222
|
*
|
|
@@ -200,3 +286,52 @@ export declare function flattenWhitespace(input: string): string;
|
|
|
200
286
|
* @returns the string with simplified whitespace and newlines
|
|
201
287
|
*/
|
|
202
288
|
export declare function simplifyWhitespace(input: string): string;
|
|
289
|
+
/**
|
|
290
|
+
* Joins an array of strings into a single string using commas. Does not trim empty values by default.
|
|
291
|
+
*
|
|
292
|
+
* Delegates to {@link COMMA_STRING_SPLIT_JOIN}.
|
|
293
|
+
*
|
|
294
|
+
* @param input string or array of strings
|
|
295
|
+
* @param trim whether or not to trim the strings before joining. Defaults to false.
|
|
296
|
+
* @returns joined string, or null/undefined if the input is null/undefined
|
|
297
|
+
*/
|
|
298
|
+
export declare const joinStringsWithCommas: {
|
|
299
|
+
(input: MaybeNot): MaybeNot;
|
|
300
|
+
(input: ArrayOrValue<Maybe<string>>): string;
|
|
301
|
+
(input: Maybe<ArrayOrValue<Maybe<string>>>, trim?: boolean): Maybe<string>;
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* Splits a comma-separated string into an array of strings.
|
|
305
|
+
*
|
|
306
|
+
* Delegates to {@link COMMA_STRING_SPLIT_JOIN}.
|
|
307
|
+
*
|
|
308
|
+
* @param input string to split
|
|
309
|
+
* @param mapFn function to map each split string to a value
|
|
310
|
+
* @returns array of strings
|
|
311
|
+
*/
|
|
312
|
+
export declare const splitCommaSeparatedString: {
|
|
313
|
+
(input: string): string[];
|
|
314
|
+
<O>(input: string, mapFn: MapStringFunction<O>): O[];
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* Splits a comma-separated string into a Set of unique trimmed string values.
|
|
318
|
+
*
|
|
319
|
+
* Delegates to {@link COMMA_STRING_SPLIT_JOIN}.
|
|
320
|
+
*
|
|
321
|
+
* @param input - comma-separated string to split, or null/undefined
|
|
322
|
+
* @returns a Set of unique string values; empty Set if input is null/undefined
|
|
323
|
+
*/
|
|
324
|
+
export declare const splitCommaSeparatedStringToSet: (input: Maybe<string>) => Set<string>;
|
|
325
|
+
/**
|
|
326
|
+
* Joins one or more strings together with spaces. Extra spaces are trimmed from the values.
|
|
327
|
+
*
|
|
328
|
+
* Delegates to {@link SPACE_STRING_SPLIT_JOIN}.
|
|
329
|
+
*
|
|
330
|
+
* @param input string or array of strings
|
|
331
|
+
* @returns joined string, or null/undefined if the input is null/undefined
|
|
332
|
+
*/
|
|
333
|
+
export declare const joinStringsWithSpaces: {
|
|
334
|
+
(input: MaybeNot): MaybeNot;
|
|
335
|
+
(input: ArrayOrValue<Maybe<string>>): string;
|
|
336
|
+
(input: Maybe<ArrayOrValue<Maybe<string>>>, trim?: boolean): Maybe<string>;
|
|
337
|
+
};
|
package/src/lib/string/url.d.ts
CHANGED
|
@@ -155,6 +155,10 @@ export interface WebsiteUrlDetails {
|
|
|
155
155
|
readonly hasHttpPrefix: boolean;
|
|
156
156
|
/** Whether the input contains a website domain. */
|
|
157
157
|
readonly hasWebsiteDomain: boolean;
|
|
158
|
+
/** Whether the input contains a port number. */
|
|
159
|
+
readonly hasPortNumber: boolean;
|
|
160
|
+
/** The port number, or `undefined` if none is present. */
|
|
161
|
+
readonly portNumber: PortNumber | undefined;
|
|
158
162
|
/** The domain and path split pair. */
|
|
159
163
|
readonly splitPair: WebsiteDomainAndPathPair;
|
|
160
164
|
/** The extracted domain. */
|
|
@@ -183,7 +187,7 @@ export type WebsiteUrlWithPrefix = string;
|
|
|
183
187
|
* @param input - The string to check.
|
|
184
188
|
* @returns Whether the input is a website URL with an HTTP prefix.
|
|
185
189
|
*/
|
|
186
|
-
export declare function isWebsiteUrlWithPrefix(input: string): input is
|
|
190
|
+
export declare function isWebsiteUrlWithPrefix(input: string): input is WebsiteUrlWithPrefix;
|
|
187
191
|
/**
|
|
188
192
|
* A "standard" internet accessible website url with a tld (.com/.net/etc) and optionally has the http/https protocol, but no other protocol.
|
|
189
193
|
*
|
package/src/lib/value/label.d.ts
CHANGED
|
@@ -29,3 +29,9 @@ export interface LabeledValue<T> extends LabelRef {
|
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
export declare function labeledValueMap<V extends LabeledValue<T>, T extends PrimativeKey>(values: V[]): Map<T, V>;
|
|
32
|
+
/**
|
|
33
|
+
* Pairs a value with a human-readable label and an optional description.
|
|
34
|
+
*/
|
|
35
|
+
export interface LabeledValueWithDescription<T> extends LabeledValue<T> {
|
|
36
|
+
description?: string;
|
|
37
|
+
}
|
package/test/index.cjs.js
CHANGED
|
@@ -377,7 +377,7 @@ function _ts_generator$2(thisArg, body) {
|
|
|
377
377
|
* @param config - fixture, test builder, and instance lifecycle functions
|
|
378
378
|
*/ function useTestContextFixture(config) {
|
|
379
379
|
var buildTests = config.buildTests, fixture = config.fixture, initInstance = config.initInstance, destroyInstance = config.destroyInstance;
|
|
380
|
-
var clearInstance;
|
|
380
|
+
var clearInstance = null;
|
|
381
381
|
var instance;
|
|
382
382
|
// Create an instance
|
|
383
383
|
beforeEach(function() {
|
|
@@ -433,7 +433,7 @@ function _ts_generator$2(thisArg, body) {
|
|
|
433
433
|
if (fixture.instance != null) {
|
|
434
434
|
console.warn('Expected instance to be set on fixture for cleanup but was set to something else.');
|
|
435
435
|
}
|
|
436
|
-
if (!destroyInstance) return [
|
|
436
|
+
if (!(destroyInstance && instance != null)) return [
|
|
437
437
|
3,
|
|
438
438
|
4
|
|
439
439
|
];
|
package/test/index.esm.js
CHANGED
|
@@ -375,7 +375,7 @@ function _ts_generator$2(thisArg, body) {
|
|
|
375
375
|
* @param config - fixture, test builder, and instance lifecycle functions
|
|
376
376
|
*/ function useTestContextFixture(config) {
|
|
377
377
|
var buildTests = config.buildTests, fixture = config.fixture, initInstance = config.initInstance, destroyInstance = config.destroyInstance;
|
|
378
|
-
var clearInstance;
|
|
378
|
+
var clearInstance = null;
|
|
379
379
|
var instance;
|
|
380
380
|
// Create an instance
|
|
381
381
|
beforeEach(function() {
|
|
@@ -431,7 +431,7 @@ function _ts_generator$2(thisArg, body) {
|
|
|
431
431
|
if (fixture.instance != null) {
|
|
432
432
|
console.warn('Expected instance to be set on fixture for cleanup but was set to something else.');
|
|
433
433
|
}
|
|
434
|
-
if (!destroyInstance) return [
|
|
434
|
+
if (!(destroyInstance && instance != null)) return [
|
|
435
435
|
3,
|
|
436
436
|
4
|
|
437
437
|
];
|