@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/boolean.d.ts
CHANGED
|
@@ -30,6 +30,14 @@ export declare function invertMaybeBoolean(x: Maybe<boolean>): Maybe<boolean>;
|
|
|
30
30
|
* @param array - Array of boolean values to reduce.
|
|
31
31
|
* @param emptyArrayValue - Value to return if the array is empty. If not provided and the array is empty, a TypeError will be thrown.
|
|
32
32
|
* @returns The result of ANDing all boolean values in the array.
|
|
33
|
+
* @throws {TypeError} If the array is empty and no emptyArrayValue is provided.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* reduceBooleansWithAnd([true, true, true]); // true
|
|
38
|
+
* reduceBooleansWithAnd([true, false, true]); // false
|
|
39
|
+
* reduceBooleansWithAnd([], true); // true (emptyArrayValue)
|
|
40
|
+
* ```
|
|
33
41
|
*/
|
|
34
42
|
export declare function reduceBooleansWithAnd(array: boolean[], emptyArrayValue?: boolean): boolean;
|
|
35
43
|
/**
|
|
@@ -38,6 +46,7 @@ export declare function reduceBooleansWithAnd(array: boolean[], emptyArrayValue?
|
|
|
38
46
|
* @param array - Array of boolean values to reduce.
|
|
39
47
|
* @param emptyArrayValue - Value to return if the array is empty. If not provided and the array is empty, a TypeError will be thrown.
|
|
40
48
|
* @returns The result of ORing all boolean values in the array.
|
|
49
|
+
* @throws {TypeError} If the array is empty and no emptyArrayValue is provided.
|
|
41
50
|
*/
|
|
42
51
|
export declare function reduceBooleansWithOr(array: boolean[], emptyArrayValue?: boolean): boolean;
|
|
43
52
|
/**
|
|
@@ -45,6 +54,14 @@ export declare function reduceBooleansWithOr(array: boolean[], emptyArrayValue?:
|
|
|
45
54
|
*
|
|
46
55
|
* @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.
|
|
47
56
|
* @returns A function that takes an array of booleans and returns the result of ANDing them.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const reduceAnd = reduceBooleansWithAndFn(true);
|
|
61
|
+
* reduceAnd([true, true]); // true
|
|
62
|
+
* reduceAnd([true, false]); // false
|
|
63
|
+
* reduceAnd([]); // true (emptyArrayValue)
|
|
64
|
+
* ```
|
|
48
65
|
*/
|
|
49
66
|
export declare function reduceBooleansWithAndFn(emptyArrayValue?: boolean): (array: boolean[]) => boolean;
|
|
50
67
|
/**
|
|
@@ -52,6 +69,14 @@ export declare function reduceBooleansWithAndFn(emptyArrayValue?: boolean): (arr
|
|
|
52
69
|
*
|
|
53
70
|
* @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.
|
|
54
71
|
* @returns A function that takes an array of booleans and returns the result of ORing them.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const reduceOr = reduceBooleansWithOrFn(false);
|
|
76
|
+
* reduceOr([false, true]); // true
|
|
77
|
+
* reduceOr([false, false]); // false
|
|
78
|
+
* reduceOr([]); // false (emptyArrayValue)
|
|
79
|
+
* ```
|
|
55
80
|
*/
|
|
56
81
|
export declare function reduceBooleansWithOrFn(emptyArrayValue?: boolean): (array: boolean[]) => boolean;
|
|
57
82
|
/**
|
|
@@ -60,6 +85,13 @@ export declare function reduceBooleansWithOrFn(emptyArrayValue?: boolean): (arra
|
|
|
60
85
|
* @param reduceFn - Function that takes two boolean values and returns a single boolean.
|
|
61
86
|
* @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.
|
|
62
87
|
* @returns A function that takes an array of booleans and returns the result of reducing them.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* const xorReduce = reduceBooleansFn((a, b) => a !== b, false);
|
|
92
|
+
* xorReduce([true, false]); // true
|
|
93
|
+
* xorReduce([]); // false (emptyArrayValue)
|
|
94
|
+
* ```
|
|
63
95
|
*/
|
|
64
96
|
export declare function reduceBooleansFn(reduceFn: (a: boolean, b: boolean) => boolean, emptyArrayValue?: boolean): (array: boolean[]) => boolean;
|
|
65
97
|
/**
|
|
@@ -85,6 +117,15 @@ export interface BooleanFactoryConfig {
|
|
|
85
117
|
*
|
|
86
118
|
* @param config - Configuration for the boolean factory, including the chance of returning true.
|
|
87
119
|
* @returns A factory function (`BooleanFactory`) that generates random boolean values based on the configured chance.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* const alwaysTrue = booleanFactory({ chance: 100 });
|
|
124
|
+
* alwaysTrue(); // true
|
|
125
|
+
*
|
|
126
|
+
* const coinFlip = booleanFactory({ chance: 50 });
|
|
127
|
+
* coinFlip(); // true or false with equal probability
|
|
128
|
+
* ```
|
|
88
129
|
*/
|
|
89
130
|
export declare function booleanFactory(config: BooleanFactoryConfig): BooleanFactory;
|
|
90
131
|
/**
|
|
@@ -102,12 +143,24 @@ export declare function randomBoolean(chance?: BooleanTrueChance): boolean;
|
|
|
102
143
|
* @param value - The string to convert to a boolean.
|
|
103
144
|
* @param defaultValue - The default value to return if the string cannot be converted to a boolean (default: undefined).
|
|
104
145
|
* @returns The boolean value corresponding to the string, or the default value if the string cannot be converted.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* stringToBoolean('yes'); // true
|
|
150
|
+
* stringToBoolean('FALSE'); // false
|
|
151
|
+
* stringToBoolean('maybe'); // undefined
|
|
152
|
+
* stringToBoolean('maybe', true); // true (defaultValue)
|
|
153
|
+
* ```
|
|
105
154
|
*/
|
|
106
155
|
export declare function stringToBoolean(value: Maybe<string | boolean>): Maybe<boolean>;
|
|
107
156
|
export declare function stringToBoolean(value: Maybe<string>, defaultValue: boolean): boolean;
|
|
108
157
|
export declare function stringToBoolean(value: Maybe<string>, defaultValue?: Maybe<boolean>): Maybe<boolean>;
|
|
109
158
|
/**
|
|
110
|
-
* Converts
|
|
159
|
+
* Converts a boolean to its `'true'` or `'false'` string representation.
|
|
160
|
+
* Returns null/undefined if the input is nullish.
|
|
161
|
+
*
|
|
162
|
+
* @param value - The boolean value to convert.
|
|
163
|
+
* @returns The string `'true'` or `'false'`, or the nullish input unchanged.
|
|
111
164
|
*/
|
|
112
165
|
export declare function trueOrFalseString(value: boolean): TrueOrFalseString;
|
|
113
166
|
export declare function trueOrFalseString(value?: MaybeNot): MaybeNot;
|
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
import { type EmailAddress } from './email';
|
|
2
|
+
/**
|
|
3
|
+
* Domain name portion of an email address (e.g., "example.com").
|
|
4
|
+
*/
|
|
2
5
|
export type EmailAddressDomain = string;
|
|
6
|
+
/**
|
|
7
|
+
* Extracts unique domain names from a list of email addresses (case-insensitive).
|
|
8
|
+
*
|
|
9
|
+
* @param addresses - Array of email addresses to extract domains from
|
|
10
|
+
* @returns Array of unique lowercase domain strings
|
|
11
|
+
*/
|
|
3
12
|
export declare function readDomainsFromEmailAddresses(addresses: EmailAddress[]): EmailAddressDomain[];
|
|
13
|
+
/**
|
|
14
|
+
* Extracts the domain portion from a single email address.
|
|
15
|
+
*
|
|
16
|
+
* @param address - The email address to extract the domain from
|
|
17
|
+
* @returns The lowercase domain string
|
|
18
|
+
*/
|
|
4
19
|
export declare function readDomainFromEmailAddress(address: EmailAddress): EmailAddressDomain;
|
|
5
20
|
/**
|
|
6
|
-
* Reads a domain from
|
|
21
|
+
* Reads a domain from various input formats including URLs, email addresses, and raw domains.
|
|
7
22
|
*
|
|
8
|
-
*
|
|
23
|
+
* Supported formats:
|
|
24
|
+
* - A url: www.test.com
|
|
9
25
|
* - A url with the protocol (://): https://www.test.com
|
|
10
26
|
* - An email address: test@test.com
|
|
11
27
|
* - A domain: test.com
|
|
12
28
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
29
|
+
* The "www." prefix is stripped from URL-style inputs since emails typically don't use it.
|
|
30
|
+
*
|
|
31
|
+
* @param urlLikeInput - A URL, email address, or domain string
|
|
32
|
+
* @returns The extracted domain
|
|
15
33
|
*/
|
|
16
34
|
export declare function readEmailDomainFromUrlOrEmailAddress(urlLikeInput: string | EmailAddress | EmailAddressDomain): EmailAddressDomain;
|
|
@@ -4,6 +4,9 @@ import { type EmailAddressDomain } from './domain';
|
|
|
4
4
|
import { type EmailAddress } from './email';
|
|
5
5
|
import { type Factory } from '../getter';
|
|
6
6
|
import { type NumberFactory } from '../number/factory';
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for generating random email addresses.
|
|
9
|
+
*/
|
|
7
10
|
export interface RandomEmailFactoryConfig {
|
|
8
11
|
/**
|
|
9
12
|
* Set of email prefixes to use
|
|
@@ -18,9 +21,21 @@ export interface RandomEmailFactoryConfig {
|
|
|
18
21
|
*/
|
|
19
22
|
numberFactory?: NumberFactory;
|
|
20
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Default configuration that uses incrementing numbers and a test domain for safety in tests.
|
|
26
|
+
*/
|
|
21
27
|
export declare const DEFAULT_RANDOM_EMAIL_FACTORY_CONFIG: RandomEmailFactoryConfig;
|
|
22
28
|
export type RandomEmailFactory = Factory<EmailAddress>;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a factory that generates random email addresses using configurable prefixes, domains, and number generators.
|
|
31
|
+
*
|
|
32
|
+
* @param inputConfig - Optional configuration overrides
|
|
33
|
+
* @returns A factory function that produces random email address strings
|
|
34
|
+
*/
|
|
23
35
|
export declare function randomEmailFactory(inputConfig?: RandomEmailFactoryConfig): RandomEmailFactory;
|
|
36
|
+
/**
|
|
37
|
+
* Configuration for generating random E.164 phone numbers.
|
|
38
|
+
*/
|
|
24
39
|
export interface RandomPhoneNumberFactoryConfig {
|
|
25
40
|
/**
|
|
26
41
|
* Set of interntional numbers to use.
|
|
@@ -31,6 +46,15 @@ export interface RandomPhoneNumberFactoryConfig {
|
|
|
31
46
|
*/
|
|
32
47
|
numberFactory?: NumberFactory;
|
|
33
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Default configuration using US area codes and random 7-digit number generation.
|
|
51
|
+
*/
|
|
34
52
|
export declare const DEFAULT_RANDOM_PHONE_NUMBER_FACTORY_CONFIG: RandomPhoneNumberFactoryConfig;
|
|
35
53
|
export type RandomPhoneNumberFactory = Factory<E164PhoneNumber>;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a factory that generates random E.164 phone numbers using configurable area codes and number generators.
|
|
56
|
+
*
|
|
57
|
+
* @param inputConfig - Optional configuration overrides
|
|
58
|
+
* @returns A factory function that produces random E.164 phone number strings
|
|
59
|
+
*/
|
|
36
60
|
export declare function randomPhoneNumberFactory(inputConfig?: RandomPhoneNumberFactoryConfig): RandomPhoneNumberFactory;
|
package/src/lib/date/date.d.ts
CHANGED
|
@@ -136,31 +136,26 @@ export declare const ISO8601_DAY_STRING_START_REGEX: RegExp;
|
|
|
136
136
|
*
|
|
137
137
|
* I.E. 2022-01-02T04:00:00.000Z in GMT-6 returns 2022-01-02
|
|
138
138
|
*
|
|
139
|
-
* @param date
|
|
140
|
-
* @returns
|
|
139
|
+
* @param date - The date to get the start of day for
|
|
140
|
+
* @returns A new Date set to midnight UTC of the input date's UTC day
|
|
141
141
|
*/
|
|
142
142
|
export declare function startOfDayForUTCDateInUTC(date: Date): Date;
|
|
143
143
|
/**
|
|
144
|
-
* Returns the system's date in UTC.
|
|
144
|
+
* Returns the start of the system's local date in UTC.
|
|
145
145
|
*
|
|
146
146
|
* I.E. 2022-01-02T04:00:00.000Z in GMT-6 (10PM Jan 1st CST) returns 2022-01-01
|
|
147
147
|
*
|
|
148
|
-
* @param date
|
|
149
|
-
* @returns
|
|
148
|
+
* @param date - The date to get the start of local day for
|
|
149
|
+
* @returns A new Date set to midnight UTC of the input date's local day
|
|
150
150
|
*/
|
|
151
151
|
export declare function startOfDayForSystemDateInUTC(date: Date): Date;
|
|
152
152
|
/**
|
|
153
|
-
* Parses
|
|
153
|
+
* Parses an ISO8601DayString (YYYY-MM-DD) to a UTC Date at midnight.
|
|
154
154
|
*
|
|
155
|
-
* @param inputDateString
|
|
156
|
-
* @returns
|
|
155
|
+
* @param inputDateString - The ISO8601 day string to parse (e.g., '2022-01-15')
|
|
156
|
+
* @returns A Date object set to midnight UTC on the specified day
|
|
157
157
|
*/
|
|
158
158
|
export declare function parseISO8601DayStringToUTCDate(inputDateString: ISO8601DayString): Date;
|
|
159
|
-
/**
|
|
160
|
-
* Returns true if the input date is strictly a
|
|
161
|
-
* @param input
|
|
162
|
-
* @returns
|
|
163
|
-
*/
|
|
164
159
|
/**
|
|
165
160
|
* Determines if a string is a valid ISO8601 day string (YYYY-MM-DD format).
|
|
166
161
|
*
|
package/src/lib/date/hour.d.ts
CHANGED
|
@@ -13,28 +13,47 @@ import { type Hours, type Minutes } from './date';
|
|
|
13
13
|
* - 15 minutes : 0.25
|
|
14
14
|
*/
|
|
15
15
|
export type FractionalHour = number;
|
|
16
|
+
/**
|
|
17
|
+
* Precision function that rounds fractional hour values to 3 decimal places.
|
|
18
|
+
*/
|
|
16
19
|
export declare const FRACTIONAL_HOURS_PRECISION_FUNCTION: import("..").CutValueToPrecisionFunction;
|
|
17
20
|
/**
|
|
18
|
-
* Converts the number of
|
|
21
|
+
* Converts the number of minutes to a fractional hour.
|
|
22
|
+
*
|
|
23
|
+
* Minutes are rounded down before conversion.
|
|
19
24
|
*
|
|
20
|
-
*
|
|
25
|
+
* @param minutes - Number of minutes to convert
|
|
26
|
+
* @returns The equivalent fractional hour value
|
|
21
27
|
*/
|
|
22
28
|
export declare function minutesToFractionalHours(minutes: Minutes): FractionalHour;
|
|
23
29
|
/**
|
|
24
|
-
* Converts
|
|
30
|
+
* Converts a fractional hour value to the equivalent number of minutes.
|
|
31
|
+
*
|
|
32
|
+
* @param hours - Fractional hour value to convert
|
|
33
|
+
* @returns The equivalent number of minutes (rounded)
|
|
25
34
|
*/
|
|
26
35
|
export declare function fractionalHoursToMinutes(hours: FractionalHour): Minutes;
|
|
27
36
|
/**
|
|
28
|
-
* Rounds the input hour to the nearest FractionalHour.
|
|
37
|
+
* Rounds the input hour to the nearest FractionalHour precision (3 decimal places).
|
|
29
38
|
*
|
|
30
|
-
* @param hour
|
|
31
|
-
* @returns
|
|
39
|
+
* @param hour - The hour value to round
|
|
40
|
+
* @returns The rounded fractional hour
|
|
32
41
|
*/
|
|
33
42
|
export declare function hourToFractionalHour(hour: Hours): FractionalHour;
|
|
43
|
+
/**
|
|
44
|
+
* Input for computing the next fractional hour by adding minutes and/or hours.
|
|
45
|
+
*/
|
|
34
46
|
export interface ComputeFractionalHour {
|
|
35
47
|
readonly minutes?: Maybe<Minutes>;
|
|
36
48
|
readonly hours?: Maybe<Hours>;
|
|
37
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Computes the next fractional hour by adding the specified hours and minutes to the input value.
|
|
52
|
+
*
|
|
53
|
+
* @param input - The starting fractional hour value
|
|
54
|
+
* @param change - The hours and/or minutes to add
|
|
55
|
+
* @returns The resulting fractional hour
|
|
56
|
+
*/
|
|
38
57
|
export declare function computeNextFractionalHour(input: FractionalHour, change: ComputeFractionalHour): FractionalHour;
|
|
39
58
|
/**
|
|
40
59
|
* The minute of the day.
|
|
@@ -45,10 +64,10 @@ export type MinuteOfDay = number;
|
|
|
45
64
|
export declare const MINUTE_OF_DAY_MINIUMUM = 0;
|
|
46
65
|
export declare const MINUTE_OF_DAY_MAXMIMUM: number;
|
|
47
66
|
/**
|
|
48
|
-
* Returns true if the input
|
|
67
|
+
* Returns true if the input value is a valid MinuteOfDay (0-1439).
|
|
49
68
|
*
|
|
50
|
-
* @param input
|
|
51
|
-
* @returns
|
|
69
|
+
* @param input - The number to validate
|
|
70
|
+
* @returns True if the input is within the valid MinuteOfDay range
|
|
52
71
|
*/
|
|
53
72
|
export declare function isMinuteOfDay(input: number): input is MinuteOfDay;
|
|
54
73
|
/**
|
|
@@ -61,57 +80,57 @@ export interface HoursAndMinutes {
|
|
|
61
80
|
/**
|
|
62
81
|
* Converts the input number of minutes to the equivalent in hours and minutes.
|
|
63
82
|
*
|
|
64
|
-
* @param inputMinutes
|
|
65
|
-
* @returns
|
|
83
|
+
* @param inputMinutes - Total minutes to convert
|
|
84
|
+
* @returns An object with the hour and minute components
|
|
66
85
|
*/
|
|
67
86
|
export declare function minutesToHoursAndMinutes(inputMinutes: Minutes): HoursAndMinutes;
|
|
68
87
|
/**
|
|
69
|
-
* Reads the hour and minutes of the Date.
|
|
88
|
+
* Reads the hour and minutes of the Date in the local timezone.
|
|
70
89
|
*
|
|
71
|
-
* @param date
|
|
72
|
-
* @returns
|
|
90
|
+
* @param date - The date to extract hours and minutes from
|
|
91
|
+
* @returns An object with the hour and minute components
|
|
73
92
|
*/
|
|
74
93
|
export declare function dateToHoursAndMinutes(date: Date): HoursAndMinutes;
|
|
75
94
|
/**
|
|
76
95
|
* Converts the input hours and minutes to a MinuteOfDay.
|
|
77
96
|
*
|
|
78
|
-
* @param hour
|
|
79
|
-
* @param minute
|
|
80
|
-
* @returns
|
|
97
|
+
* @param hour - The hour component (0-23)
|
|
98
|
+
* @param minute - The minute component (0-59)
|
|
99
|
+
* @returns The corresponding MinuteOfDay value
|
|
81
100
|
*/
|
|
82
101
|
export declare function toMinuteOfDay(hour: Hours, minute: Minutes): MinuteOfDay;
|
|
83
102
|
/**
|
|
84
|
-
* Creates a new date
|
|
103
|
+
* Creates a new date with the time set to the given minute of the day.
|
|
85
104
|
*
|
|
86
|
-
* @param minuteOfDay
|
|
87
|
-
* @param day
|
|
88
|
-
* @returns
|
|
105
|
+
* @param minuteOfDay - The minute of the day (0-1439)
|
|
106
|
+
* @param day - Optional base date to use (defaults to the current date)
|
|
107
|
+
* @returns A Date with the time set to the specified minute of day
|
|
89
108
|
*/
|
|
90
109
|
export declare function dateFromMinuteOfDay(minuteOfDay: Minutes | MinuteOfDay, day?: Date): Date;
|
|
91
110
|
/**
|
|
92
|
-
* Converts a Date to a MinuteOfDay.
|
|
111
|
+
* Converts a Date to a MinuteOfDay based on the local timezone.
|
|
93
112
|
*
|
|
94
|
-
* @param date
|
|
95
|
-
* @returns
|
|
113
|
+
* @param date - The date to convert
|
|
114
|
+
* @returns The MinuteOfDay for the given date
|
|
96
115
|
*/
|
|
97
116
|
export declare function dateToMinuteOfDay(date: Date): MinuteOfDay;
|
|
98
117
|
/**
|
|
99
|
-
* Converts the input minutes to a MinuteOfDay.
|
|
118
|
+
* Converts the input minutes to a valid MinuteOfDay by wrapping around the day boundary.
|
|
100
119
|
*
|
|
101
|
-
* @param minutes
|
|
102
|
-
* @returns
|
|
120
|
+
* @param minutes - The minutes value to convert
|
|
121
|
+
* @returns A MinuteOfDay value (0-1439)
|
|
103
122
|
*/
|
|
104
123
|
export declare function asMinuteOfDay(minutes: Minutes): MinuteOfDay;
|
|
105
124
|
/**
|
|
106
|
-
* Returns a string that represents the input hours and minutes.
|
|
125
|
+
* Returns a human-readable string that represents the input hours and minutes.
|
|
107
126
|
*
|
|
108
127
|
* Examples:
|
|
109
128
|
* - {} -> ''
|
|
110
|
-
* - { hour: 1, minute: 30 } -> "1
|
|
111
|
-
* - { hour: 1 } -> "1
|
|
129
|
+
* - { hour: 1, minute: 30 } -> "1 hours and 30 minutes"
|
|
130
|
+
* - { hour: 1 } -> "1 hours"
|
|
112
131
|
* - { minute: 30 } -> "30 minutes"
|
|
113
132
|
*
|
|
114
|
-
* @param input
|
|
115
|
-
* @returns
|
|
133
|
+
* @param input - The hours and minutes to format
|
|
134
|
+
* @returns A human-readable string representation
|
|
116
135
|
*/
|
|
117
136
|
export declare function hoursAndMinutesToString(input: HoursAndMinutes): string;
|
package/src/lib/date/minute.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export interface MinutesAndSeconds {
|
|
|
11
11
|
*
|
|
12
12
|
* Rounds down to the nearest second.
|
|
13
13
|
*
|
|
14
|
-
* @param milliseconds
|
|
15
|
-
* @returns
|
|
14
|
+
* @param milliseconds - The number of milliseconds to convert
|
|
15
|
+
* @returns An object with the minute and second components
|
|
16
16
|
*/
|
|
17
17
|
export declare function millisecondsToMinutesAndSeconds(milliseconds: Milliseconds): MinutesAndSeconds;
|
|
18
18
|
/**
|
|
@@ -25,7 +25,7 @@ export interface MinutesAndSeconds {
|
|
|
25
25
|
/**
|
|
26
26
|
* Converts the input number of seconds to the equivalent in minutes and seconds.
|
|
27
27
|
*
|
|
28
|
-
* @param inputSeconds
|
|
29
|
-
* @returns
|
|
28
|
+
* @param inputSeconds - The number of seconds to convert
|
|
29
|
+
* @returns An object with the minute and second components
|
|
30
30
|
*/
|
|
31
31
|
export declare function secondsToMinutesAndSeconds(inputSeconds: Seconds): MinutesAndSeconds;
|
package/src/lib/date/time.d.ts
CHANGED
|
@@ -19,6 +19,15 @@ export type TimePeriodCounter = (() => number) & {
|
|
|
19
19
|
*/
|
|
20
20
|
readonly _reset: (start?: Date) => Date;
|
|
21
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* Creates a counter that tracks invocations within fixed time periods.
|
|
24
|
+
* Returns the number of invocations since the current period started.
|
|
25
|
+
* When a new period begins, the counter resets to 0.
|
|
26
|
+
*
|
|
27
|
+
* @param timePeriodLength - Length of each time period in milliseconds
|
|
28
|
+
* @param lastTimePeriodStart - Optional starting point for the first period
|
|
29
|
+
* @returns A callable counter function with metadata properties
|
|
30
|
+
*/
|
|
22
31
|
export declare function timePeriodCounter(timePeriodLength: number, lastTimePeriodStart?: Maybe<Date>): TimePeriodCounter;
|
|
23
32
|
export type TimerState = 'running' | 'paused' | 'complete' | 'cancelled';
|
|
24
33
|
/**
|
|
@@ -101,10 +110,10 @@ export declare class TimerCancelledError extends BaseError {
|
|
|
101
110
|
*/
|
|
102
111
|
export declare function makeTimer(duration: Milliseconds, startImmediately?: boolean): Timer;
|
|
103
112
|
/**
|
|
104
|
-
* Toggles the input Timer's running state.
|
|
113
|
+
* Toggles the input Timer's running state between running and stopped.
|
|
105
114
|
*
|
|
106
|
-
* @param timer
|
|
107
|
-
* @param toggleRun
|
|
115
|
+
* @param timer - The timer to toggle
|
|
116
|
+
* @param toggleRun - If provided, forces the timer to run (true) or stop (false). Otherwise toggles the current state.
|
|
108
117
|
*/
|
|
109
118
|
export declare function toggleTimerRunning(timer: Timer, toggleRun?: boolean): void;
|
|
110
119
|
/**
|
package/src/lib/date/week.d.ts
CHANGED
|
@@ -12,12 +12,12 @@ export type Saturday = 6;
|
|
|
12
12
|
*/
|
|
13
13
|
export type DayOfWeek = Sunday | Monday | Tuesday | Wednesday | Thusrsday | Friday | Saturday | Sunday;
|
|
14
14
|
/**
|
|
15
|
-
* Returns the day of the week for the input
|
|
15
|
+
* Returns the day of the week for the input date.
|
|
16
16
|
*
|
|
17
|
-
* Equivalent to date.getDay()
|
|
17
|
+
* Equivalent to date.getDay().
|
|
18
18
|
*
|
|
19
|
-
* @param date
|
|
20
|
-
* @returns
|
|
19
|
+
* @param date - The date to get the day of week for
|
|
20
|
+
* @returns The DayOfWeek value (0=Sunday through 6=Saturday)
|
|
21
21
|
*/
|
|
22
22
|
export declare function dayOfWeek(date: Date): DayOfWeek;
|
|
23
23
|
/**
|
|
@@ -25,10 +25,10 @@ export declare function dayOfWeek(date: Date): DayOfWeek;
|
|
|
25
25
|
*/
|
|
26
26
|
export type IsInAllowedDaysOfWeekSetDecisionFunction = IsInSetDecisionFunction<Date | DayOfWeek, DayOfWeek>;
|
|
27
27
|
/**
|
|
28
|
-
* Creates a DecisionFunction that checks whether
|
|
28
|
+
* Creates a DecisionFunction that checks whether the input day or Date falls within the allowed days of the week.
|
|
29
29
|
*
|
|
30
|
-
* @param allowedDaysOfWeek
|
|
31
|
-
* @returns
|
|
30
|
+
* @param allowedDaysOfWeek - Set of allowed DayOfWeek values
|
|
31
|
+
* @returns A decision function that checks membership in the allowed set
|
|
32
32
|
*/
|
|
33
33
|
export declare function isInAllowedDaysOfWeekSet(allowedDaysOfWeek: Set<DayOfWeek>): IsInAllowedDaysOfWeekSetDecisionFunction;
|
|
34
34
|
/**
|
|
@@ -36,7 +36,9 @@ export declare function isInAllowedDaysOfWeekSet(allowedDaysOfWeek: Set<DayOfWee
|
|
|
36
36
|
*
|
|
37
37
|
* Returns 7 days by default.
|
|
38
38
|
*
|
|
39
|
-
* @param startingOn
|
|
39
|
+
* @param startingOn - The day to start from (defaults to Sunday)
|
|
40
|
+
* @param maxDays - Maximum number of days to return (defaults to 7)
|
|
41
|
+
* @returns An array of DayOfWeek values
|
|
40
42
|
*/
|
|
41
43
|
export declare function daysOfWeekArray(startingOn?: DayOfWeek, maxDays?: number): DayOfWeek[];
|
|
42
44
|
/**
|
|
@@ -63,8 +65,23 @@ export interface EnabledDays {
|
|
|
63
65
|
friday: boolean;
|
|
64
66
|
saturday: boolean;
|
|
65
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates an EnabledDays object from an iterable of Day enum values.
|
|
70
|
+
*
|
|
71
|
+
* @param input - Iterable of Day values to mark as enabled
|
|
72
|
+
* @returns An EnabledDays object with the specified days set to true
|
|
73
|
+
*/
|
|
66
74
|
export declare function enabledDaysFromDaysOfWeek(input: Maybe<Iterable<Day>>): EnabledDays;
|
|
75
|
+
/**
|
|
76
|
+
* Converts an EnabledDays object to an array of Day enum values.
|
|
77
|
+
*
|
|
78
|
+
* @param input - The EnabledDays object to convert
|
|
79
|
+
* @returns An array of Day values for all enabled days
|
|
80
|
+
*/
|
|
67
81
|
export declare function daysOfWeekFromEnabledDays(input: Maybe<EnabledDays>): Day[];
|
|
82
|
+
/**
|
|
83
|
+
* Configuration for transforming day-of-week name strings.
|
|
84
|
+
*/
|
|
68
85
|
export interface DayOfWeekNamesTransformConfig {
|
|
69
86
|
/**
|
|
70
87
|
* Whether or not to abbreviate the day names.
|
|
@@ -80,16 +97,66 @@ export interface DayOfWeekNamesTransformConfig {
|
|
|
80
97
|
uppercase?: boolean;
|
|
81
98
|
}
|
|
82
99
|
/**
|
|
83
|
-
* Returns an array of
|
|
100
|
+
* Returns an array of strings with each day of the week named.
|
|
84
101
|
*
|
|
85
|
-
* @
|
|
102
|
+
* @param sundayFirst - If true (default), Sunday is the first day; otherwise Monday is first
|
|
103
|
+
* @param transform - Optional configuration for abbreviation and casing
|
|
104
|
+
* @returns Array of day name strings
|
|
86
105
|
*/
|
|
87
106
|
export declare function getDaysOfWeekNames(sundayFirst?: boolean, transform?: DayOfWeekNamesTransformConfig): string[];
|
|
107
|
+
/**
|
|
108
|
+
* Creates a Map from DayOfWeek values to their string names.
|
|
109
|
+
*
|
|
110
|
+
* @param transform - Optional configuration for abbreviation and casing
|
|
111
|
+
* @returns A Map from DayOfWeek to name string
|
|
112
|
+
*/
|
|
88
113
|
export declare function daysOfWeekNameMap(transform?: DayOfWeekNamesTransformConfig): Map<DayOfWeek, string>;
|
|
114
|
+
/**
|
|
115
|
+
* Function that returns the name string for a given DayOfWeek.
|
|
116
|
+
*/
|
|
89
117
|
export type DayOfWeekNameFunction = (dayOfWeek: DayOfWeek) => string;
|
|
118
|
+
/**
|
|
119
|
+
* Creates a function that returns the name for a given DayOfWeek.
|
|
120
|
+
*
|
|
121
|
+
* @param transform - Optional configuration for abbreviation and casing
|
|
122
|
+
* @returns A function that maps DayOfWeek values to name strings
|
|
123
|
+
*/
|
|
90
124
|
export declare function daysOfWeekNameFunction(transform?: DayOfWeekNamesTransformConfig): DayOfWeekNameFunction;
|
|
125
|
+
/**
|
|
126
|
+
* Returns the DayOfWeek for the day after the given day.
|
|
127
|
+
*
|
|
128
|
+
* @param day - The starting day
|
|
129
|
+
* @returns The next day of the week
|
|
130
|
+
*/
|
|
91
131
|
export declare function getDayTomorrow(day: DayOfWeek): DayOfWeek;
|
|
132
|
+
/**
|
|
133
|
+
* Returns the DayOfWeek for the day before the given day.
|
|
134
|
+
*
|
|
135
|
+
* @param day - The starting day
|
|
136
|
+
* @returns The previous day of the week
|
|
137
|
+
*/
|
|
92
138
|
export declare function getDayYesterday(day: DayOfWeek): DayOfWeek;
|
|
139
|
+
/**
|
|
140
|
+
* Returns the DayOfWeek offset by the given number of days (positive = forward, negative = backward).
|
|
141
|
+
*
|
|
142
|
+
* @param day - The starting day
|
|
143
|
+
* @param days - The number of days to offset (positive or negative)
|
|
144
|
+
* @returns The resulting DayOfWeek
|
|
145
|
+
*/
|
|
93
146
|
export declare function getDayOffset(day: DayOfWeek, days: number): DayOfWeek;
|
|
147
|
+
/**
|
|
148
|
+
* Returns the DayOfWeek that is the given number of days before the input day.
|
|
149
|
+
*
|
|
150
|
+
* @param day - The starting day
|
|
151
|
+
* @param days - The number of days to go back (defaults to 1)
|
|
152
|
+
* @returns The resulting DayOfWeek
|
|
153
|
+
*/
|
|
94
154
|
export declare function getPreviousDay(day: DayOfWeek, days?: number): DayOfWeek;
|
|
155
|
+
/**
|
|
156
|
+
* Returns the DayOfWeek that is the given number of days after the input day.
|
|
157
|
+
*
|
|
158
|
+
* @param day - The starting day
|
|
159
|
+
* @param days - The number of days to advance (defaults to 1)
|
|
160
|
+
* @returns The resulting DayOfWeek
|
|
161
|
+
*/
|
|
95
162
|
export declare function getNextDay(day: DayOfWeek, days?: number): DayOfWeek;
|
package/src/lib/error/error.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export type ThrowErrorFunction<T = unknown> = (error: T) => never | void;
|
|
|
7
7
|
* A unique identifier for a specific error.
|
|
8
8
|
*/
|
|
9
9
|
export type StringErrorCode = string;
|
|
10
|
+
/**
|
|
11
|
+
* Default error code used when no specific code is provided.
|
|
12
|
+
*/
|
|
10
13
|
export declare const DEFAULT_READABLE_ERROR_CODE = "ERROR";
|
|
11
14
|
/**
|
|
12
15
|
* An error that is identified by a unique code.
|
|
@@ -24,25 +27,73 @@ export interface CodedError {
|
|
|
24
27
|
export interface ReadableError extends Partial<CodedError> {
|
|
25
28
|
readonly message?: Maybe<string>;
|
|
26
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Checks if the error has the default error code or no code at all.
|
|
32
|
+
*
|
|
33
|
+
* @param error - A ReadableError or error code string to check
|
|
34
|
+
* @returns True if the error uses the default code or has no code
|
|
35
|
+
*/
|
|
27
36
|
export declare function isDefaultReadableError(error: Maybe<ReadableError | StringErrorCode>): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* A ReadableError that is guaranteed to have a code.
|
|
39
|
+
*/
|
|
28
40
|
export type ReadableErrorWithCode<T extends ReadableError = ReadableError> = T & CodedError;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a ReadableError with a code and optional message.
|
|
43
|
+
*
|
|
44
|
+
* @param code - The error code
|
|
45
|
+
* @param message - Optional human-readable error message
|
|
46
|
+
* @returns A ReadableErrorWithCode object
|
|
47
|
+
*/
|
|
29
48
|
export declare function readableError(code: StringErrorCode, message?: string): ReadableErrorWithCode;
|
|
49
|
+
/**
|
|
50
|
+
* A ReadableError that includes additional data of type T.
|
|
51
|
+
*/
|
|
30
52
|
export interface ReadableDataError<T = unknown> extends ReadableError {
|
|
31
53
|
readonly data?: T;
|
|
32
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Wrapper around an error that contains the error data.
|
|
57
|
+
*/
|
|
33
58
|
export interface ErrorWrapper {
|
|
34
59
|
readonly data: ReadableError | CodedError;
|
|
35
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Union of all supported error input types for conversion functions.
|
|
63
|
+
*/
|
|
36
64
|
export type ErrorInput = ErrorWrapper | CodedError | ReadableError | ReadableDataError;
|
|
37
65
|
/**
|
|
38
|
-
* Converts
|
|
66
|
+
* Converts various error input formats to a normalized ReadableErrorWithCode.
|
|
67
|
+
* Handles CodedError, ErrorWrapper, BaseError, and plain ReadableError inputs.
|
|
39
68
|
*
|
|
40
|
-
* @param inputError
|
|
41
|
-
* @returns
|
|
69
|
+
* @param inputError - The error to convert
|
|
70
|
+
* @returns A normalized ReadableErrorWithCode
|
|
42
71
|
*/
|
|
43
72
|
export declare function toReadableError(inputError: ErrorInput): CodedError | ReadableErrorWithCode;
|
|
44
73
|
export declare function toReadableError(inputError: Maybe<ErrorInput>): Maybe<CodedError | ReadableErrorWithCode>;
|
|
74
|
+
/**
|
|
75
|
+
* Checks if an error's message contains the target string.
|
|
76
|
+
*
|
|
77
|
+
* @param input - The error or string to check
|
|
78
|
+
* @param target - The string to search for in the error message
|
|
79
|
+
* @returns True if the error message contains the target string
|
|
80
|
+
*/
|
|
45
81
|
export declare function errorMessageContainsString(input: Maybe<ErrorInput | string>, target: string): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Function that checks if an error's message contains a specific string.
|
|
84
|
+
*/
|
|
46
85
|
export type ErrorMessageContainsStringFunction = (input: Maybe<ErrorInput | string>) => boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a function that checks if an error's message contains the target string.
|
|
88
|
+
*
|
|
89
|
+
* @param target - The string to search for
|
|
90
|
+
* @returns A function that checks error messages for the target string
|
|
91
|
+
*/
|
|
47
92
|
export declare function errorMessageContainsStringFunction(target: string): ErrorMessageContainsStringFunction;
|
|
93
|
+
/**
|
|
94
|
+
* Extracts the message string from an error or returns the input if it's already a string.
|
|
95
|
+
*
|
|
96
|
+
* @param input - The error or string to extract a message from
|
|
97
|
+
* @returns The error message string, or null/undefined if not available
|
|
98
|
+
*/
|
|
48
99
|
export declare function messageFromError(input: Maybe<ErrorInput | string>): Maybe<string>;
|