@dereekb/util 12.0.6 → 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/index.cjs.js +19 -1
- package/fetch/index.esm.js +19 -2
- package/fetch/package.json +1 -1
- package/fetch/src/lib/fetch.page.d.ts +4 -0
- package/fetch/src/lib/fetch.url.d.ts +5 -5
- 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/object/object.filter.tuple.d.ts +2 -2
- 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/string.d.ts +8 -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 +8 -0
- package/test/package.json +1 -1
package/src/lib/boolean.d.ts
CHANGED
|
@@ -14,39 +14,39 @@ export type IsModified = boolean;
|
|
|
14
14
|
/**
|
|
15
15
|
* Reduces an array of booleans with the logical AND operation.
|
|
16
16
|
*
|
|
17
|
-
* @param array - Array of boolean values to reduce
|
|
18
|
-
* @param emptyArrayValue - Value to return if the array is empty
|
|
19
|
-
* @returns The result of ANDing all boolean values in the array
|
|
17
|
+
* @param array - Array of boolean values to reduce.
|
|
18
|
+
* @param emptyArrayValue - Value to return if the array is empty. If not provided and the array is empty, a TypeError will be thrown.
|
|
19
|
+
* @returns The result of ANDing all boolean values in the array.
|
|
20
20
|
*/
|
|
21
21
|
export declare function reduceBooleansWithAnd(array: boolean[], emptyArrayValue?: boolean): boolean;
|
|
22
22
|
/**
|
|
23
23
|
* Reduces an array of booleans with the logical OR operation.
|
|
24
24
|
*
|
|
25
|
-
* @param array - Array of boolean values to reduce
|
|
26
|
-
* @param emptyArrayValue - Value to return if the array is empty
|
|
27
|
-
* @returns The result of ORing all boolean values in the array
|
|
25
|
+
* @param array - Array of boolean values to reduce.
|
|
26
|
+
* @param emptyArrayValue - Value to return if the array is empty. If not provided and the array is empty, a TypeError will be thrown.
|
|
27
|
+
* @returns The result of ORing all boolean values in the array.
|
|
28
28
|
*/
|
|
29
29
|
export declare function reduceBooleansWithOr(array: boolean[], emptyArrayValue?: boolean): boolean;
|
|
30
30
|
/**
|
|
31
31
|
* Creates a function that reduces an array of booleans with the logical AND operation.
|
|
32
32
|
*
|
|
33
|
-
* @param emptyArrayValue - Value to return if the array is empty
|
|
34
|
-
* @returns A function that takes an array of booleans and returns the result of ANDing them
|
|
33
|
+
* @param emptyArrayValue - Value to return if the array is empty. If not provided and the array is empty, the returned function will throw a TypeError.
|
|
34
|
+
* @returns A function that takes an array of booleans and returns the result of ANDing them.
|
|
35
35
|
*/
|
|
36
36
|
export declare function reduceBooleansWithAndFn(emptyArrayValue?: boolean): (array: boolean[]) => boolean;
|
|
37
37
|
/**
|
|
38
38
|
* Creates a function that reduces an array of booleans with the logical OR operation.
|
|
39
39
|
*
|
|
40
|
-
* @param emptyArrayValue - Value to return if the array is empty
|
|
41
|
-
* @returns A function that takes an array of booleans and returns the result of ORing them
|
|
40
|
+
* @param emptyArrayValue - Value to return if the array is empty. If not provided and the array is empty, the returned function will throw a TypeError.
|
|
41
|
+
* @returns A function that takes an array of booleans and returns the result of ORing them.
|
|
42
42
|
*/
|
|
43
43
|
export declare function reduceBooleansWithOrFn(emptyArrayValue?: boolean): (array: boolean[]) => boolean;
|
|
44
44
|
/**
|
|
45
45
|
* Creates a function that reduces an array of booleans using a custom reduce function.
|
|
46
46
|
*
|
|
47
|
-
* @param reduceFn - Function that takes two boolean values and returns a single boolean
|
|
48
|
-
* @param emptyArrayValue - Value to return if the array is empty
|
|
49
|
-
* @returns A function that takes an array of booleans and returns the result of reducing them
|
|
47
|
+
* @param reduceFn - Function that takes two boolean values and returns a single boolean.
|
|
48
|
+
* @param emptyArrayValue - Value to return if the array is empty. If not provided and the array is empty, the returned function will throw a TypeError because `Array.prototype.reduce` on an empty array without an initial value throws.
|
|
49
|
+
* @returns A function that takes an array of booleans and returns the result of reducing them.
|
|
50
50
|
*/
|
|
51
51
|
export declare function reduceBooleansFn(reduceFn: (a: boolean, b: boolean) => boolean, emptyArrayValue?: boolean): (array: boolean[]) => boolean;
|
|
52
52
|
/**
|
|
@@ -56,24 +56,28 @@ export type BooleanFactory = Factory<boolean>;
|
|
|
56
56
|
/**
|
|
57
57
|
* Number from 0.0 to 100.0 used for the chance to return true.
|
|
58
58
|
*/
|
|
59
|
-
export type
|
|
59
|
+
export type BooleanTrueChance = number;
|
|
60
|
+
/**
|
|
61
|
+
* Configuration for `booleanFactory`.
|
|
62
|
+
*/
|
|
60
63
|
export interface BooleanFactoryConfig {
|
|
61
64
|
/**
|
|
62
|
-
* Chance of returning true.
|
|
65
|
+
* Chance of returning true, expressed as a number from 0.0 to 100.0.
|
|
66
|
+
* For example, a value of 75 means a 75% chance of returning true.
|
|
63
67
|
*/
|
|
64
|
-
chance:
|
|
68
|
+
readonly chance: BooleanTrueChance;
|
|
65
69
|
}
|
|
66
70
|
/**
|
|
67
71
|
* Creates a new BooleanFactory that generates random boolean values based on chance.
|
|
68
72
|
*
|
|
69
|
-
* @param config - Configuration for the boolean factory, including the chance of returning true
|
|
70
|
-
* @returns A factory function that generates random boolean values
|
|
73
|
+
* @param config - Configuration for the boolean factory, including the chance of returning true.
|
|
74
|
+
* @returns A factory function (`BooleanFactory`) that generates random boolean values based on the configured chance.
|
|
71
75
|
*/
|
|
72
|
-
export declare function booleanFactory(config: BooleanFactoryConfig):
|
|
76
|
+
export declare function booleanFactory(config: BooleanFactoryConfig): BooleanFactory;
|
|
73
77
|
/**
|
|
74
78
|
* Returns a random boolean based on the specified chance.
|
|
75
79
|
*
|
|
76
|
-
* @param chance - Number between 0 and 100 representing the percentage chance of returning true (default: 50)
|
|
77
|
-
* @returns A random boolean value with the specified probability of being true
|
|
80
|
+
* @param chance - Number between 0.0 and 100.0 representing the percentage chance of returning true (default: 50, i.e., 50%).
|
|
81
|
+
* @returns A random boolean value with the specified probability of being true.
|
|
78
82
|
*/
|
|
79
|
-
export declare function randomBoolean(chance?:
|
|
83
|
+
export declare function randomBoolean(chance?: BooleanTrueChance): boolean;
|
package/src/lib/date/date.d.ts
CHANGED
|
@@ -209,10 +209,25 @@ export type UnixDateTimeNumber = number;
|
|
|
209
209
|
* A date or a unix timestamp
|
|
210
210
|
*/
|
|
211
211
|
export type DateOrUnixDateTimeNumber = Date | UnixDateTimeNumber;
|
|
212
|
+
/**
|
|
213
|
+
* Number of milliseconds.
|
|
214
|
+
*/
|
|
212
215
|
export type Milliseconds = number;
|
|
216
|
+
/**
|
|
217
|
+
* Number of seconds.
|
|
218
|
+
*/
|
|
213
219
|
export type Seconds = number;
|
|
220
|
+
/**
|
|
221
|
+
* Number of minutes.
|
|
222
|
+
*/
|
|
214
223
|
export type Minutes = number;
|
|
224
|
+
/**
|
|
225
|
+
* Number of hours.
|
|
226
|
+
*/
|
|
215
227
|
export type Hours = number;
|
|
228
|
+
/**
|
|
229
|
+
* Number of days.
|
|
230
|
+
*/
|
|
216
231
|
export type Days = number;
|
|
217
232
|
/**
|
|
218
233
|
* Number of hours in a day.
|
|
@@ -261,13 +276,23 @@ export type MonthOfYear = number;
|
|
|
261
276
|
*/
|
|
262
277
|
export type DateMonth = number;
|
|
263
278
|
/**
|
|
264
|
-
* Retrieves the MonthOfYear value (1-12) from the input Date.
|
|
279
|
+
* Retrieves the MonthOfYear value (1-12) from the input Date in the current system timezone.
|
|
280
|
+
*
|
|
265
281
|
* Converts JavaScript's 0-based month (0-11) to a 1-based month (1-12).
|
|
266
282
|
*
|
|
267
283
|
* @param date - The date to extract the month from
|
|
268
284
|
* @returns The month of year as a number from 1-12
|
|
269
285
|
*/
|
|
270
286
|
export declare function monthOfYearFromDate(date: Date): MonthOfYear;
|
|
287
|
+
/**
|
|
288
|
+
* Retrieves the MonthOfYear value (1-12) from the input Date in the UTC timezone.
|
|
289
|
+
*
|
|
290
|
+
* Converts JavaScript's 0-based month (0-11) to a 1-based month (1-12).
|
|
291
|
+
*
|
|
292
|
+
* @param date - The date to extract the month from
|
|
293
|
+
* @returns The month of year as a number from 1-12
|
|
294
|
+
*/
|
|
295
|
+
export declare function monthOfYearFromUTCDate(date: Date): MonthOfYear;
|
|
271
296
|
/**
|
|
272
297
|
* Converts a JavaScript Date month (0-11) to a MonthOfYear (1-12).
|
|
273
298
|
*
|
package/src/lib/date/time.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type TimePeriodCounter = (() => number) & {
|
|
|
20
20
|
readonly _reset: (start?: Date) => Date;
|
|
21
21
|
};
|
|
22
22
|
export declare function timePeriodCounter(timePeriodLength: number, lastTimePeriodStart?: Maybe<Date>): TimePeriodCounter;
|
|
23
|
-
export type TimerState = 'running' | 'paused' | 'complete';
|
|
23
|
+
export type TimerState = 'running' | 'paused' | 'complete' | 'cancelled';
|
|
24
24
|
/**
|
|
25
25
|
* Timer object that counts down a fixed duration amount.
|
|
26
26
|
*
|
|
@@ -61,6 +61,10 @@ export interface Timer extends Destroyable {
|
|
|
61
61
|
* If the timer is complete, this returns 0.
|
|
62
62
|
*/
|
|
63
63
|
readonly durationRemaining: Maybe<Milliseconds>;
|
|
64
|
+
/**
|
|
65
|
+
* Completes the timer immediately.
|
|
66
|
+
*/
|
|
67
|
+
completeNow(): void;
|
|
64
68
|
/**
|
|
65
69
|
* Starts the timer if it was not running. Does nothing if already running.
|
|
66
70
|
*/
|
package/src/lib/hash.d.ts
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a salt value used in hashing.
|
|
3
|
+
*/
|
|
1
4
|
export type HashSalt = string;
|
|
5
|
+
/**
|
|
6
|
+
* A Map used for decoding hashed string values.
|
|
7
|
+
*
|
|
8
|
+
* @template H The type of the hashed string (key).
|
|
9
|
+
* @template V The type of the original string (value).
|
|
10
|
+
*/
|
|
2
11
|
export type HashDecodeMap<H extends string = string, V extends string = string> = Map<H, V>;
|
|
12
|
+
/**
|
|
13
|
+
* Decodes a list of hashed string values using a provided list of potential original values and a hash function.
|
|
14
|
+
*
|
|
15
|
+
* @param hashedValues An array of hashed strings to decode.
|
|
16
|
+
* @param decodeValues An array of potential original string values.
|
|
17
|
+
* @param hashFn A function that takes a string and returns its hashed representation.
|
|
18
|
+
* @returns An array of decoded strings. Values that cannot be decoded are filtered out.
|
|
19
|
+
*/
|
|
3
20
|
export declare function decodeHashedValues(hashedValues: string[], decodeValues: string[], hashFn: (value: string) => string): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Creates a `HashDecodeMap` from a list of potential original string values and a hash function.
|
|
23
|
+
* The map's keys are the hashed versions of the `decodeValues`, and the values are the original `decodeValues`.
|
|
24
|
+
*
|
|
25
|
+
* @param decodeValues An array of potential original string values.
|
|
26
|
+
* @param hashFn A function that takes a string and returns its hashed representation.
|
|
27
|
+
* @returns A `HashDecodeMap` for decoding hashed values.
|
|
28
|
+
*/
|
|
4
29
|
export declare function makeHashDecodeMap(decodeValues: string[], hashFn: (value: string) => string): HashDecodeMap;
|
|
30
|
+
/**
|
|
31
|
+
* Decodes a list of hashed string values using a pre-built `HashDecodeMap`.
|
|
32
|
+
*
|
|
33
|
+
* @param hashedValues An array of hashed strings to decode.
|
|
34
|
+
* @param decodeMap A `HashDecodeMap` to use for looking up original values.
|
|
35
|
+
* @returns An array of decoded strings. Values that cannot be decoded are filtered out.
|
|
36
|
+
*/
|
|
5
37
|
export declare function decodeHashedValuesWithDecodeMap(hashedValues: string[], decodeMap: HashDecodeMap): string[];
|
package/src/lib/misc/host.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { type Maybe } from '../value/maybe.type';
|
|
2
|
-
export
|
|
3
|
-
host: string;
|
|
4
|
-
port: number | string;
|
|
5
|
-
}
|
|
2
|
+
export interface JoinHostAndPortConfig {
|
|
3
|
+
readonly host: string;
|
|
4
|
+
readonly port: number | string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Joins the host and port into a string.
|
|
8
|
+
*
|
|
9
|
+
* @param config
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare function joinHostAndPort(config: Maybe<JoinHostAndPortConfig>): Maybe<string>;
|
|
@@ -2,8 +2,8 @@ import { type FilterFunction } from '../filter/filter';
|
|
|
2
2
|
import { type KeyAsString } from '../type';
|
|
3
3
|
export type ForEachKeyValueTupleFunction<T extends object = object, K extends keyof T = keyof T> = (tuple: KeyValueTuple<T, K>, index: number) => void;
|
|
4
4
|
export interface ForEachKeyValue<T extends object = object, K extends keyof T = keyof T> {
|
|
5
|
-
filter?: FilterKeyValueTuplesInput<T, K>;
|
|
6
|
-
forEach: ForEachKeyValueTupleFunction<T, K>;
|
|
5
|
+
readonly filter?: FilterKeyValueTuplesInput<T, K>;
|
|
6
|
+
readonly forEach: ForEachKeyValueTupleFunction<T, K>;
|
|
7
7
|
}
|
|
8
8
|
export declare function forEachKeyValue<T extends object = object, K extends keyof T = keyof T>(obj: T, { forEach, filter }: ForEachKeyValue<T, K>): void;
|
|
9
9
|
export declare function filterKeyValueTuples<T extends object = object, K extends keyof T = keyof T>(obj: T, filter?: FilterKeyValueTuplesInput<T, K>): KeyValueTuple<T, K>[];
|
|
@@ -7,11 +7,11 @@ export interface AllowedSet<T> {
|
|
|
7
7
|
/**
|
|
8
8
|
* Values that are allowed. Hits against this set result in an initial true.
|
|
9
9
|
*/
|
|
10
|
-
allowed?: Maybe<Set<T>>;
|
|
10
|
+
readonly allowed?: Maybe<Set<T>>;
|
|
11
11
|
/**
|
|
12
12
|
* Values that are disallowed. Hits against this set result in false.
|
|
13
13
|
*/
|
|
14
|
-
disallowed?: Maybe<Set<T>>;
|
|
14
|
+
readonly disallowed?: Maybe<Set<T>>;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Determines whether the input values are "allowed" for the given AllowedSet.
|
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
import { type UnixDateTimeNumber } from '../date/date';
|
|
2
|
+
/**
|
|
3
|
+
* String representation of data that is stored.
|
|
4
|
+
*/
|
|
2
5
|
export type StoredDataString = string;
|
|
6
|
+
/**
|
|
7
|
+
* Key used for accessing stored data.
|
|
8
|
+
*/
|
|
3
9
|
export type StoredDataStorageKey = string;
|
|
10
|
+
/**
|
|
11
|
+
* Interface for data that has been stored, including metadata about its storage time.
|
|
12
|
+
*/
|
|
4
13
|
export interface StoredData {
|
|
5
|
-
|
|
6
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The Unix timestamp (in milliseconds) when the data was stored.
|
|
16
|
+
* Undefined if the storage time is not known or not applicable.
|
|
17
|
+
*/
|
|
18
|
+
readonly storedAt: UnixDateTimeNumber | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The actual data stored, as a string.
|
|
21
|
+
*/
|
|
22
|
+
readonly data: StoredDataString;
|
|
7
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Interface for retrieved stored data that has been processed.
|
|
26
|
+
* Extends StoredData with information about expiration and the converted data form.
|
|
27
|
+
*
|
|
28
|
+
* @template T The type of the converted data.
|
|
29
|
+
*/
|
|
8
30
|
export interface ReadStoredData<T> extends StoredData {
|
|
9
|
-
|
|
10
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Whether the stored data is considered expired.
|
|
33
|
+
*/
|
|
34
|
+
readonly expired: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* The data after being converted from its string representation to type T.
|
|
37
|
+
*/
|
|
38
|
+
readonly convertedData: T;
|
|
11
39
|
}
|
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
import { BaseError } from 'make-error';
|
|
2
2
|
import { type ReadStoredData } from './storage';
|
|
3
|
+
/**
|
|
4
|
+
* Base error class for storage-related issues.
|
|
5
|
+
*/
|
|
3
6
|
export declare class StoredDataError extends BaseError {
|
|
7
|
+
/**
|
|
8
|
+
* Creates an instance of StoredDataError.
|
|
9
|
+
* @param message Optional error message.
|
|
10
|
+
*/
|
|
4
11
|
constructor(message?: string);
|
|
5
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Error thrown when requested data does not exist in storage.
|
|
15
|
+
*/
|
|
6
16
|
export declare class DataDoesNotExistError extends StoredDataError {
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instance of DataDoesNotExistError.
|
|
19
|
+
* @param message Optional error message.
|
|
20
|
+
*/
|
|
7
21
|
constructor(message?: string);
|
|
8
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Error thrown when data exists in storage but is considered expired.
|
|
25
|
+
*
|
|
26
|
+
* @template T The type of the data that is expired.
|
|
27
|
+
*/
|
|
9
28
|
export declare class DataIsExpiredError<T> extends StoredDataError {
|
|
10
29
|
readonly data: ReadStoredData<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Creates an instance of DataIsExpiredError.
|
|
32
|
+
* @param data The expired data, including metadata.
|
|
33
|
+
* @param message Optional error message. If not provided, a default message will be used.
|
|
34
|
+
*/
|
|
11
35
|
constructor(data: ReadStoredData<T>, message?: string);
|
|
12
36
|
}
|
|
@@ -1,14 +1,53 @@
|
|
|
1
1
|
import { type Maybe } from '../value/maybe.type';
|
|
2
2
|
import { type StorageObject } from './storage.object';
|
|
3
|
+
/**
|
|
4
|
+
* A StorageObject implementation that stores data in memory.
|
|
5
|
+
* This is not persistent and will be cleared when the JavaScript context is lost.
|
|
6
|
+
*/
|
|
3
7
|
export declare class MemoryStorageInstance implements StorageObject {
|
|
4
8
|
private _length;
|
|
5
9
|
private _storage;
|
|
10
|
+
/**
|
|
11
|
+
* The number of items stored.
|
|
12
|
+
*/
|
|
6
13
|
get length(): number;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the key at the given index.
|
|
16
|
+
* @param index The index of the key to retrieve.
|
|
17
|
+
* @returns The key string if found, otherwise null.
|
|
18
|
+
*/
|
|
7
19
|
key(index: number): string;
|
|
20
|
+
/**
|
|
21
|
+
* Checks if a key exists in the storage.
|
|
22
|
+
* @param key The key to check.
|
|
23
|
+
* @returns True if the key exists, false otherwise.
|
|
24
|
+
*/
|
|
8
25
|
hasKey(key: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves an item from storage.
|
|
28
|
+
* @param key The key of the item to retrieve.
|
|
29
|
+
* @returns The item string if found, otherwise null or undefined.
|
|
30
|
+
*/
|
|
9
31
|
getItem(key: string): Maybe<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Sets an item in storage.
|
|
34
|
+
* If the item is null or undefined, the key will be removed.
|
|
35
|
+
* @param key The key of the item to set.
|
|
36
|
+
* @param item The item string to store.
|
|
37
|
+
*/
|
|
10
38
|
setItem(key: string, item: Maybe<string>): void;
|
|
39
|
+
/**
|
|
40
|
+
* Removes an item from storage.
|
|
41
|
+
* @param key The key of the item to remove.
|
|
42
|
+
*/
|
|
11
43
|
removeItem(key: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* Clears all items from the storage.
|
|
46
|
+
*/
|
|
12
47
|
clear(): void;
|
|
13
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* A shared, global instance of MemoryStorageInstance.
|
|
51
|
+
* Useful for singleton-like access to an in-memory store throughout an application.
|
|
52
|
+
*/
|
|
14
53
|
export declare const SHARED_MEMORY_STORAGE: MemoryStorageInstance;
|
|
@@ -4,8 +4,22 @@ import { type StoredDataStorageKey } from './storage';
|
|
|
4
4
|
* Limited Class/Interface for storing string values synchronously.
|
|
5
5
|
*/
|
|
6
6
|
export declare abstract class SimpleStorageObject {
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves an item from storage.
|
|
9
|
+
* @param key The key of the item to retrieve.
|
|
10
|
+
* @returns The item string if found, otherwise null or undefined.
|
|
11
|
+
*/
|
|
7
12
|
abstract getItem(key: StoredDataStorageKey): Maybe<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Sets an item in storage.
|
|
15
|
+
* @param key The key of the item to set.
|
|
16
|
+
* @param item The item string to store. If null or undefined, the item may be removed depending on implementation.
|
|
17
|
+
*/
|
|
8
18
|
abstract setItem(key: StoredDataStorageKey, item: Maybe<string>): void;
|
|
19
|
+
/**
|
|
20
|
+
* Removes an item from storage.
|
|
21
|
+
* @param key The key of the item to remove.
|
|
22
|
+
*/
|
|
9
23
|
abstract removeItem(key: StoredDataStorageKey): void;
|
|
10
24
|
}
|
|
11
25
|
/**
|
|
@@ -14,19 +28,47 @@ export declare abstract class SimpleStorageObject {
|
|
|
14
28
|
* Has the same interface as localStorage for the web.
|
|
15
29
|
*/
|
|
16
30
|
export declare abstract class StorageObject extends SimpleStorageObject {
|
|
31
|
+
/**
|
|
32
|
+
* The number of items stored in the storage object.
|
|
33
|
+
*/
|
|
17
34
|
abstract readonly length: number;
|
|
18
35
|
/**
|
|
19
36
|
* Returns the string key for the index.
|
|
20
37
|
*
|
|
21
38
|
* Returns null if no key available.
|
|
39
|
+
* @param index The index of the key to retrieve.
|
|
40
|
+
* @returns The key string if found, otherwise null.
|
|
22
41
|
*/
|
|
23
42
|
abstract key(index: number): string | null;
|
|
24
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Extended synchronous Class/Interface for storing string values with additional properties.
|
|
46
|
+
*/
|
|
25
47
|
export declare abstract class FullStorageObject extends StorageObject {
|
|
48
|
+
/**
|
|
49
|
+
* Whether or not the storage is persistant.
|
|
50
|
+
*/
|
|
26
51
|
abstract readonly isPersistant: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Whether or not the storage is available for use.
|
|
54
|
+
*/
|
|
27
55
|
abstract readonly isAvailable: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Removes all items from storage.
|
|
58
|
+
* @returns An array of keys that were removed.
|
|
59
|
+
*/
|
|
28
60
|
abstract removeAll(): string[];
|
|
29
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Utility class for working with StorageObject instances.
|
|
64
|
+
*/
|
|
30
65
|
export declare class StorageObjectUtility {
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves all keys from a StorageObject, optionally filtering by a prefix.
|
|
68
|
+
*
|
|
69
|
+
* @param storageObject The StorageObject to retrieve keys from.
|
|
70
|
+
* @param prefix Optional prefix to filter keys by.
|
|
71
|
+
* @returns An array of StoredDataStorageKey.
|
|
72
|
+
*/
|
|
31
73
|
static allKeysFromStorageObject(storageObject: StorageObject, prefix?: string): StoredDataStorageKey[];
|
|
32
74
|
}
|
|
@@ -16,6 +16,14 @@ export type ReadStringFunction<T, S extends string = string> = MapFunction<T, S>
|
|
|
16
16
|
* I.E. 0,1,2
|
|
17
17
|
*/
|
|
18
18
|
export type CommaSeparatedString<T = unknown> = string;
|
|
19
|
+
/**
|
|
20
|
+
* Represents a string that is made up of space-separated values.
|
|
21
|
+
*
|
|
22
|
+
* Optional generic typing exists for communicating what values are separated within the string.
|
|
23
|
+
*
|
|
24
|
+
* I.E. 0 1 2
|
|
25
|
+
*/
|
|
26
|
+
export type SpaceSeparatedString<T = unknown> = string;
|
|
19
27
|
export declare function caseInsensitiveString(input: string): string;
|
|
20
28
|
export declare function caseInsensitiveString(input: undefined): undefined;
|
|
21
29
|
export declare function caseInsensitiveString(input: Maybe<string>): Maybe<string>;
|
|
@@ -1,32 +1,96 @@
|
|
|
1
1
|
import { type MapFunction } from '../value/map';
|
|
2
2
|
import { type Maybe } from '../value/maybe.type';
|
|
3
|
+
/**
|
|
4
|
+
* Trims leading and trailing whitespace from a string.
|
|
5
|
+
* @param input The string to trim.
|
|
6
|
+
* @returns The trimmed string.
|
|
7
|
+
*/
|
|
3
8
|
export declare function stringTrimFunction(input: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Converts a string to uppercase.
|
|
11
|
+
* @param input The string to convert.
|
|
12
|
+
* @returns The uppercase string.
|
|
13
|
+
*/
|
|
4
14
|
export declare function stringToUppercaseFunction(input: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a string to lowercase.
|
|
17
|
+
* @param input The string to convert.
|
|
18
|
+
* @returns The lowercase string.
|
|
19
|
+
*/
|
|
5
20
|
export declare function stringToLowercaseFunction(input: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Configuration for transforming a string.
|
|
23
|
+
* Defines operations like trimming, case conversion, or applying a custom transform function.
|
|
24
|
+
*
|
|
25
|
+
* @template S The specific string type, defaults to `string`.
|
|
26
|
+
*/
|
|
6
27
|
export type TransformStringFunctionConfig<S extends string = string> = {
|
|
7
28
|
/**
|
|
8
|
-
*
|
|
29
|
+
* If true, the string will be trimmed of leading/trailing whitespace.
|
|
30
|
+
* Trimming occurs before other transformations like case conversion or a custom `transform` function.
|
|
9
31
|
*/
|
|
10
|
-
trim?: boolean;
|
|
32
|
+
readonly trim?: boolean;
|
|
11
33
|
/**
|
|
12
|
-
*
|
|
34
|
+
* If true, the string will be converted to lowercase.
|
|
35
|
+
* This is ignored if a custom `transform` function is provided.
|
|
13
36
|
*/
|
|
14
|
-
toLowercase?: boolean;
|
|
37
|
+
readonly toLowercase?: boolean;
|
|
15
38
|
/**
|
|
16
|
-
*
|
|
39
|
+
* If true, the string will be converted to uppercase.
|
|
40
|
+
* This is ignored if a custom `transform` function is provided and takes precedence over `toLowercase` if both are true.
|
|
17
41
|
*/
|
|
18
|
-
toUppercase?: boolean;
|
|
42
|
+
readonly toUppercase?: boolean;
|
|
19
43
|
/**
|
|
20
|
-
*
|
|
44
|
+
* An optional custom function to transform the string.
|
|
45
|
+
* If provided, `toLowercase` and `toUppercase` are ignored. Trimming (if `trim` is true) occurs before this custom transform.
|
|
21
46
|
*/
|
|
22
|
-
transform?: TransformStringFunction<S>;
|
|
47
|
+
readonly transform?: TransformStringFunction<S>;
|
|
23
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* A reference object holding a `TransformStringFunctionConfig`.
|
|
51
|
+
*
|
|
52
|
+
* @template S The specific string type, defaults to `string`.
|
|
53
|
+
*/
|
|
24
54
|
export interface TransformStringFunctionConfigRef<S extends string = string> {
|
|
25
|
-
|
|
55
|
+
/** The string transformation configuration. */
|
|
56
|
+
readonly transform: TransformStringFunctionConfig<S>;
|
|
26
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* A function that maps a string of type S to another string of type S.
|
|
60
|
+
*
|
|
61
|
+
* @template S The specific string type, defaults to `string`.
|
|
62
|
+
*/
|
|
27
63
|
export type TransformStringFunction<S extends string = string> = MapFunction<S, S>;
|
|
64
|
+
/**
|
|
65
|
+
* Input type for string transformation configuration.
|
|
66
|
+
* Can be a full `TransformStringFunctionConfig` object or a direct `TransformStringFunction`.
|
|
67
|
+
*
|
|
68
|
+
* @template S The specific string type, defaults to `string`.
|
|
69
|
+
*/
|
|
28
70
|
export type TransformStringFunctionConfigInput<S extends string = string> = TransformStringFunctionConfig<S> | TransformStringFunction<S>;
|
|
71
|
+
/**
|
|
72
|
+
* Normalizes a `TransformStringFunctionConfigInput` into a `TransformStringFunctionConfig` object.
|
|
73
|
+
* If the input is a function, it's wrapped into a config object with that function as the `transform` property.
|
|
74
|
+
* If the input is undefined, it returns undefined.
|
|
75
|
+
*
|
|
76
|
+
* @template S The specific string type, defaults to `string`.
|
|
77
|
+
* @param config The configuration input to normalize.
|
|
78
|
+
* @returns A `TransformStringFunctionConfig` object, or `undefined` if the input config is undefined.
|
|
79
|
+
*/
|
|
29
80
|
export declare function transformStringFunctionConfig<S extends string = string>(config?: TransformStringFunctionConfigInput<S>): Maybe<TransformStringFunctionConfig<S>>;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a string transformation function based on the provided configuration.
|
|
83
|
+
* The resulting function will apply transformations in a specific order:
|
|
84
|
+
* 1. Trimming (if `config.trim` is true).
|
|
85
|
+
* 2. Custom `config.transform` function (if provided).
|
|
86
|
+
* 3. Uppercase conversion (if `config.toUppercase` is true and no `config.transform`).
|
|
87
|
+
* 4. Lowercase conversion (if `config.toLowercase` is true and no `config.transform` or `config.toUppercase`).
|
|
88
|
+
* If no transformations are specified, the identity function is returned.
|
|
89
|
+
*
|
|
90
|
+
* @template S The specific string type, defaults to `string`.
|
|
91
|
+
* @param config The `TransformStringFunctionConfig` detailing the transformations.
|
|
92
|
+
* @returns A `TransformStringFunction` that applies the configured transformations.
|
|
93
|
+
*/
|
|
30
94
|
export declare function transformStringFunction<S extends string = string>(config: TransformStringFunctionConfig<S>): TransformStringFunction<S>;
|
|
31
95
|
export declare function addPrefix(prefix: string, input: string): string;
|
|
32
96
|
/**
|
|
@@ -34,26 +98,26 @@ export declare function addPrefix(prefix: string, input: string): string;
|
|
|
34
98
|
*/
|
|
35
99
|
export type AddPrefixFunction = (input: string) => string;
|
|
36
100
|
/**
|
|
37
|
-
* Creates
|
|
38
|
-
*
|
|
39
|
-
* @
|
|
40
|
-
* @param replacement
|
|
41
|
-
* @param is
|
|
42
|
-
* @returns
|
|
101
|
+
* Creates a function that adds a configured prefix to the input string if it does not exist on that string.
|
|
102
|
+
* @param prefix The prefix to add.
|
|
103
|
+
* @returns A function that adds the prefix to a string.
|
|
43
104
|
*/
|
|
44
105
|
export declare function addPrefixFunction(prefix: string): AddPrefixFunction;
|
|
45
|
-
export declare function addSuffix(suffix: string, input: string): string;
|
|
46
106
|
/**
|
|
47
107
|
* Function that adds a configured suffix to the input string if it does not exist on that string.
|
|
48
108
|
*/
|
|
49
109
|
export type AddSuffixFunction = TransformStringFunction;
|
|
50
110
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* @param input
|
|
54
|
-
* @
|
|
55
|
-
|
|
56
|
-
|
|
111
|
+
* Adds a suffix to a string if it does not already end with that suffix.
|
|
112
|
+
* @param suffix The suffix to add.
|
|
113
|
+
* @param input The string to modify.
|
|
114
|
+
* @returns The modified string.
|
|
115
|
+
*/
|
|
116
|
+
export declare function addSuffix(suffix: string, input: string): string;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a function that adds a configured suffix to the input string if it does not exist on that string.
|
|
119
|
+
* @param suffix The suffix to add.
|
|
120
|
+
* @returns A function that adds the suffix to a string.
|
|
57
121
|
*/
|
|
58
122
|
export declare function addSuffixFunction(suffix: string): AddSuffixFunction;
|
|
59
123
|
/**
|
|
@@ -61,9 +125,9 @@ export declare function addSuffixFunction(suffix: string): AddSuffixFunction;
|
|
|
61
125
|
*/
|
|
62
126
|
export type PadStartFunction = TransformStringFunction;
|
|
63
127
|
/**
|
|
64
|
-
*
|
|
65
|
-
* @param minLength
|
|
66
|
-
* @param padCharacter
|
|
67
|
-
* @returns
|
|
128
|
+
* Pads the start of a string to a minimum length.
|
|
129
|
+
* @param minLength The minimum length of the string.
|
|
130
|
+
* @param padCharacter The character to use for padding.
|
|
131
|
+
* @returns A function that pads the start of a string.
|
|
68
132
|
*/
|
|
69
133
|
export declare function padStartFunction(minLength: number, padCharacter: string): PadStartFunction;
|
|
@@ -3,13 +3,24 @@ import { type ExpandTreeFunction } from './tree.expand';
|
|
|
3
3
|
import { type FlattenTreeFunction } from './tree.flatten';
|
|
4
4
|
/**
|
|
5
5
|
* Function that expands the input values into a tree, and then flattens the tree to produce a single array of values of another type.
|
|
6
|
+
*
|
|
7
|
+
* @template T The type of the initial input values.
|
|
8
|
+
* @template V The type of the values in the final flattened output array.
|
|
9
|
+
* @param values An array of input values of type T.
|
|
10
|
+
* @returns An array of output values of type V.
|
|
6
11
|
*/
|
|
7
12
|
export type ExpandFlattenTreeFunction<T, V> = (values: T[]) => V[];
|
|
8
13
|
/**
|
|
9
|
-
* Creates an
|
|
14
|
+
* Creates an ExpandFlattenTreeFunction by composing an expansion function and a flattening function.
|
|
15
|
+
*
|
|
16
|
+
* This higher-order function takes a function to expand an array of values `T` into a list of trees (`N[]` where `N` is a TreeNode)
|
|
17
|
+
* and another function to flatten these trees into a single array of values `V`.
|
|
10
18
|
*
|
|
11
|
-
* @
|
|
12
|
-
* @
|
|
13
|
-
* @
|
|
19
|
+
* @template T The type of the initial input values.
|
|
20
|
+
* @template V The type of the values in the final flattened output array.
|
|
21
|
+
* @template N The type of the intermediate tree nodes. Must extend TreeNode with value T and children of type N.
|
|
22
|
+
* @param expand An ExpandTreeFunction (values: T[]) => N[] that converts an array of T into an array of tree nodes N.
|
|
23
|
+
* @param flatten A FlattenTreeFunction (tree: N, array?: V[]) => V[] that flattens a tree of N nodes into an array of V values.
|
|
24
|
+
* @returns An ExpandFlattenTreeFunction (values: T[]) => V[] that performs the combined expansion and flattening.
|
|
14
25
|
*/
|
|
15
26
|
export declare function expandFlattenTreeFunction<T, V, N extends TreeNode<T, N> = TreeNode<T, any>>(expand: ExpandTreeFunction<T, N>, flatten: FlattenTreeFunction<N, V>): ExpandFlattenTreeFunction<T, V>;
|