@dereekb/util 10.1.9 → 10.1.11
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/CHANGELOG.md +8 -0
- package/fetch/package.json +1 -1
- package/index.cjs.js +1976 -1658
- package/index.esm.js +4162 -3795
- package/package.json +1 -1
- package/src/lib/date/hour.d.ts +57 -0
- package/src/lib/iterable/iterable.d.ts +26 -0
- package/src/lib/model/id.factory.d.ts +40 -0
- package/src/lib/model/index.d.ts +2 -1
- package/src/lib/string/char.d.ts +9 -0
- package/src/lib/string/dencoder.d.ts +79 -0
- package/src/lib/string/transform.d.ts +12 -1
- package/test/CHANGELOG.md +8 -0
- package/test/package.json +1 -1
package/package.json
CHANGED
package/src/lib/date/hour.d.ts
CHANGED
|
@@ -36,3 +36,60 @@ export interface ComputeFractionalHour {
|
|
|
36
36
|
readonly hours?: Maybe<Hours>;
|
|
37
37
|
}
|
|
38
38
|
export declare function computeNextFractionalHour(input: FractionalHour, change: ComputeFractionalHour): FractionalHour;
|
|
39
|
+
/**
|
|
40
|
+
* The minute of the day.
|
|
41
|
+
*
|
|
42
|
+
* Number from 0-1439.
|
|
43
|
+
*/
|
|
44
|
+
export type MinuteOfDay = number;
|
|
45
|
+
/**
|
|
46
|
+
* A pair of hours and minutes.
|
|
47
|
+
*/
|
|
48
|
+
export interface HoursAndMinutes {
|
|
49
|
+
readonly hour: number;
|
|
50
|
+
readonly minute: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Converts the input number of minutes to the equivalent in hours and minutes.
|
|
54
|
+
*
|
|
55
|
+
* @param inputMinutes
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
export declare function minutesToHoursAndMinutes(inputMinutes: Minutes): HoursAndMinutes;
|
|
59
|
+
/**
|
|
60
|
+
* Reads the hour and minutes of the Date.
|
|
61
|
+
*
|
|
62
|
+
* @param date
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
export declare function dateToHoursAndMinutes(date: Date): HoursAndMinutes;
|
|
66
|
+
/**
|
|
67
|
+
* Converts the input hours and minutes to a MinuteOfDay.
|
|
68
|
+
*
|
|
69
|
+
* @param hour
|
|
70
|
+
* @param minute
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
export declare function toMinuteOfDay(hour: Hours, minute: Minutes): MinuteOfDay;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new date from the minute of the day.
|
|
76
|
+
*
|
|
77
|
+
* @param minuteOfDay
|
|
78
|
+
* @param day
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
export declare function dateFromMinuteOfDay(minuteOfDay: Minutes | MinuteOfDay, day?: Date): Date;
|
|
82
|
+
/**
|
|
83
|
+
* Converts a Date to a MinuteOfDay.
|
|
84
|
+
*
|
|
85
|
+
* @param date
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
export declare function dateToMinuteOfDay(date: Date): MinuteOfDay;
|
|
89
|
+
/**
|
|
90
|
+
* Converts the input minutes to a MinuteOfDay.
|
|
91
|
+
*
|
|
92
|
+
* @param minutes
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
export declare function asMinuteOfDay(minutes: Minutes): MinuteOfDay;
|
|
@@ -8,7 +8,33 @@ import { type Maybe } from '../value/maybe.type';
|
|
|
8
8
|
*/
|
|
9
9
|
export type IterableOrValue<T> = T | Iterable<T>;
|
|
10
10
|
export declare function asIterable<T = unknown>(values: IterableOrValue<T>, treatStringAsIterable?: boolean): Iterable<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Converts the input IterableOrValue value to an array.
|
|
13
|
+
*
|
|
14
|
+
* By default will treat strings as a non-iterable value, using the string as a single value.
|
|
15
|
+
*
|
|
16
|
+
* @param values
|
|
17
|
+
* @param treatStringAsIterable
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
11
20
|
export declare function iterableToArray<T = unknown>(values: IterableOrValue<T>, treatStringAsIterable?: boolean): T[];
|
|
21
|
+
/**
|
|
22
|
+
* Converts the input IterableOrValue value to a Set.
|
|
23
|
+
*
|
|
24
|
+
* By default will treat strings as a non-iterable value, using the string as a single value.
|
|
25
|
+
*
|
|
26
|
+
* @param values
|
|
27
|
+
* @param treatStringAsIterable
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
export declare function iterableToSet<T = unknown>(values: IterableOrValue<T>, treatStringAsIterable?: boolean): Set<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Converts the input IterableOrValue value to a Map using the input readKey function.
|
|
33
|
+
*
|
|
34
|
+
* @param values
|
|
35
|
+
* @param readKey
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
12
38
|
export declare function iterableToMap<T, K extends PrimativeKey = PrimativeKey>(values: IterableOrValue<T>, readKey: ReadKeyFunction<T, K>): Map<Maybe<K>, T>;
|
|
13
39
|
/**
|
|
14
40
|
* Returns true if the input is an Iterable.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Factory } from '../getter/getter';
|
|
2
|
+
import { type NumberStringDencoderString, type NumberStringDencoder, type NumberStringDencoderNumber } from '../string/dencoder';
|
|
3
|
+
import { type IndexNumber } from '../value/indexed';
|
|
4
|
+
import { type Maybe } from '../value/maybe.type';
|
|
5
|
+
/**
|
|
6
|
+
* A factory for generating a unique model identifier.
|
|
7
|
+
*/
|
|
8
|
+
export type ModelIdFactory = Factory<string>;
|
|
9
|
+
export interface SequentialIncrementingNumberStringModelIdFactoryConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Optional transform function to modify the resulting value.
|
|
12
|
+
*/
|
|
13
|
+
readonly transform?: (encodedValue: NumberStringDencoderString, index: NumberStringDencoderNumber) => NumberStringDencoderString;
|
|
14
|
+
/**
|
|
15
|
+
* The dencoder to use.
|
|
16
|
+
*
|
|
17
|
+
* Default to NUMBER_STRING_DENCODER_64.
|
|
18
|
+
*/
|
|
19
|
+
readonly dencoder?: Maybe<NumberStringDencoder>;
|
|
20
|
+
/**
|
|
21
|
+
* The current index. Will start at this index + increaseBy.
|
|
22
|
+
*
|
|
23
|
+
* Is ignored if startAt is provided.
|
|
24
|
+
*/
|
|
25
|
+
readonly currentIndex?: Maybe<IndexNumber | NumberStringDencoderString>;
|
|
26
|
+
/**
|
|
27
|
+
* The index to start at.
|
|
28
|
+
*/
|
|
29
|
+
readonly startAt?: Maybe<IndexNumber | NumberStringDencoderString>;
|
|
30
|
+
/**
|
|
31
|
+
* The value to increase by for each generated value.
|
|
32
|
+
*
|
|
33
|
+
* Defaults to 1.
|
|
34
|
+
*/
|
|
35
|
+
readonly increaseBy?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a ModelIdFactory that generates sequential incrementing encoded NumberStringDencoderString values using the input configuration.
|
|
39
|
+
*/
|
|
40
|
+
export declare function sequentialIncrementingNumberStringModelIdFactory(config?: SequentialIncrementingNumberStringModelIdFactoryConfig): ModelIdFactory;
|
package/src/lib/model/index.d.ts
CHANGED
package/src/lib/string/char.d.ts
CHANGED
|
@@ -79,3 +79,12 @@ export declare const UTF_8_START_CHARACTER = "\0";
|
|
|
79
79
|
* https://firebase.google.com/docs/database/rest/retrieve-data#range-queries
|
|
80
80
|
*/
|
|
81
81
|
export declare const UTF_PRIVATE_USAGE_AREA_START = "\uF8FF";
|
|
82
|
+
/**
|
|
83
|
+
* Takes in a string and returns a Record that has the index value mapped to the property of the character.
|
|
84
|
+
*
|
|
85
|
+
* The latest character index is used in collision cases.
|
|
86
|
+
*
|
|
87
|
+
* @param chars
|
|
88
|
+
* @returns
|
|
89
|
+
*/
|
|
90
|
+
export declare function stringCharactersToIndexRecord(chars: string): Record<string, number>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type PrimativeKey } from '../key';
|
|
2
2
|
import { type FactoryWithRequiredInput } from '../getter/getter';
|
|
3
|
+
import { type Maybe } from '../value/maybe.type';
|
|
3
4
|
/**
|
|
4
5
|
* Map object of PrimativeKey dencoder values, keyed by the encoded value.
|
|
5
6
|
*/
|
|
@@ -66,3 +67,81 @@ export type PrimativeKeyStringDencoderFunction<D extends PrimativeKey, E extends
|
|
|
66
67
|
* @returns
|
|
67
68
|
*/
|
|
68
69
|
export declare function primativeKeyStringDencoder<D extends PrimativeKey, E extends PrimativeKey>(config: PrimativeKeyStringDencoderConfig<D, E>): PrimativeKeyStringDencoderFunction<D, E>;
|
|
70
|
+
/**
|
|
71
|
+
* An encodable number. This is typically a positive integer value.
|
|
72
|
+
*/
|
|
73
|
+
export type NumberStringDencoderNumber = number;
|
|
74
|
+
/**
|
|
75
|
+
* A number-encoded string. Little-Endian. Should Decode to the same value each time.
|
|
76
|
+
*/
|
|
77
|
+
export type NumberStringDencoderString = string;
|
|
78
|
+
/**
|
|
79
|
+
* Digits used when encoding/decoding a value.
|
|
80
|
+
*
|
|
81
|
+
* The number of digits/characters must be a factor of 2. I.E. 8, 16, 32, 64
|
|
82
|
+
*/
|
|
83
|
+
export type NumberStringDencoderDigits = string;
|
|
84
|
+
/**
|
|
85
|
+
* The number of "bits" given by the NumberStringDencoderDigits.
|
|
86
|
+
*/
|
|
87
|
+
export type NumberStringDencoderBitDepth = 2 | 4 | 8 | 16 | 32 | 64;
|
|
88
|
+
/**
|
|
89
|
+
* Default 64 NumberStringDencoderDigits value.
|
|
90
|
+
*/
|
|
91
|
+
export declare const NUMBER_STRING_DENCODER_64_DIGITS: NumberStringDencoderDigits;
|
|
92
|
+
/**
|
|
93
|
+
* The default negative prefix for negative numbers.
|
|
94
|
+
*/
|
|
95
|
+
export declare const NUMBER_STRING_DENCODER_64_DEFAULT_NEGATIVE_PREFIX = "!";
|
|
96
|
+
/**
|
|
97
|
+
* The NumberString dencoder type
|
|
98
|
+
* - positive_integer: can only encode/decode positive integers
|
|
99
|
+
* - integer: can only encode/decode integers
|
|
100
|
+
* - positive_decimal: can encoded/decode positive decimals
|
|
101
|
+
* - decimal: can encoded/decode decimals
|
|
102
|
+
*/
|
|
103
|
+
export type NumberStringDencoderType = 'positive_integer' | 'integer' | 'positive_decimal' | 'decimal';
|
|
104
|
+
/**
|
|
105
|
+
* A NumberString dencoder.
|
|
106
|
+
*
|
|
107
|
+
* Can encode/decode a number from the input string.
|
|
108
|
+
*/
|
|
109
|
+
export interface NumberStringDencoder {
|
|
110
|
+
readonly type: NumberStringDencoderType;
|
|
111
|
+
readonly digits: NumberStringDencoderDigits;
|
|
112
|
+
readonly bitDepth: NumberStringDencoderBitDepth;
|
|
113
|
+
readonly negativePrefix?: Maybe<string>;
|
|
114
|
+
/**
|
|
115
|
+
* Encodes the input number to the corresponding NumberStringDencoderString.
|
|
116
|
+
*
|
|
117
|
+
* @param number
|
|
118
|
+
*/
|
|
119
|
+
encodeNumber(number: NumberStringDencoderNumber): NumberStringDencoderString;
|
|
120
|
+
/**
|
|
121
|
+
* Decodes the input number to the corresponding NumberStringDencoderNumber.
|
|
122
|
+
*
|
|
123
|
+
* @param encodedNumber
|
|
124
|
+
*/
|
|
125
|
+
decodeNumber(encodedNumber: NumberStringDencoderString): NumberStringDencoderNumber;
|
|
126
|
+
}
|
|
127
|
+
export interface NumberStringDencoderConfig {
|
|
128
|
+
/**
|
|
129
|
+
* Optional negative prefix character. Should not be in the digits.
|
|
130
|
+
*/
|
|
131
|
+
readonly negativePrefix?: Maybe<string>;
|
|
132
|
+
readonly digits: NumberStringDencoderDigits;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Creates an integer-type NumberStringDencoder.
|
|
136
|
+
*
|
|
137
|
+
* If the config does not include a negative prefix, any negative number will be treated like a positive number.
|
|
138
|
+
*
|
|
139
|
+
* @param config
|
|
140
|
+
* @returns
|
|
141
|
+
*/
|
|
142
|
+
export declare function numberStringDencoder(config: NumberStringDencoderConfig): NumberStringDencoder;
|
|
143
|
+
export declare const NUMBER_STRING_DENCODER_64: NumberStringDencoder;
|
|
144
|
+
export type NumberStringDencoderFunction = ((input: NumberStringDencoderString) => NumberStringDencoderNumber) & ((input: NumberStringDencoderNumber) => NumberStringDencoderString);
|
|
145
|
+
export declare function numberStringDencoderFunction(dencoder: NumberStringDencoder): NumberStringDencoderFunction;
|
|
146
|
+
export declare function numberStringDencoderEncodedStringValueFunction(dencoder: NumberStringDencoder): (input: NumberStringDencoderString | NumberStringDencoderNumber) => NumberStringDencoderString;
|
|
147
|
+
export declare function numberStringDencoderDecodedNumberValueFunction(dencoder: NumberStringDencoder): (input: NumberStringDencoderString | NumberStringDencoderNumber) => NumberStringDencoderNumber;
|
|
@@ -46,7 +46,7 @@ export declare function addSuffix(suffix: string, input: string): string;
|
|
|
46
46
|
/**
|
|
47
47
|
* Function that adds a configured suffix to the input string if it does not exist on that string.
|
|
48
48
|
*/
|
|
49
|
-
export type AddSuffixFunction =
|
|
49
|
+
export type AddSuffixFunction = TransformStringFunction;
|
|
50
50
|
/**
|
|
51
51
|
* Creates an AddSuffixFunction
|
|
52
52
|
*
|
|
@@ -56,3 +56,14 @@ export type AddSuffixFunction = (input: string) => string;
|
|
|
56
56
|
* @returns
|
|
57
57
|
*/
|
|
58
58
|
export declare function addSuffixFunction(suffix: string): AddSuffixFunction;
|
|
59
|
+
/**
|
|
60
|
+
* Function that pads the start of a string to a minimum length.
|
|
61
|
+
*/
|
|
62
|
+
export type PadStartFunction = TransformStringFunction;
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @param minLength
|
|
66
|
+
* @param padCharacter
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
export declare function padStartFunction(minLength: number, padCharacter: string): PadStartFunction;
|
package/test/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [10.1.11](https://github.com/dereekb/dbx-components/compare/v10.1.10-dev...v10.1.11) (2024-04-27)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## [10.1.10](https://github.com/dereekb/dbx-components/compare/v10.1.9-dev...v10.1.10) (2024-04-12)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
5
13
|
## [10.1.9](https://github.com/dereekb/dbx-components/compare/v10.1.8-dev...v10.1.9) (2024-04-10)
|
|
6
14
|
|
|
7
15
|
|