@budsbox/lib-es 2.3.0 → 3.0.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/dist/array.d.ts +49 -27
- package/dist/array.js +32 -20
- package/dist/function.d.ts +63 -6
- package/dist/function.js +16 -0
- package/dist/guards/assert.d.ts +213 -0
- package/dist/guards/assert.js +245 -0
- package/dist/guards/check.d.ts +470 -0
- package/dist/guards/check.js +524 -0
- package/dist/guards/describe.d.ts +7 -0
- package/dist/guards/describe.js +34 -0
- package/dist/guards/format.d.ts +109 -0
- package/dist/guards/format.js +295 -0
- package/dist/guards/hlf.d.ts +257 -0
- package/dist/guards/hlf.js +178 -0
- package/dist/guards/index.d.ts +73 -0
- package/dist/guards/index.js +124 -0
- package/dist/guards/message.d.ts +102 -0
- package/dist/guards/message.js +224 -0
- package/dist/guards/prop.d.ts +232 -0
- package/dist/guards/prop.js +45 -0
- package/dist/guards/types.d.ts +256 -0
- package/dist/guards/types.js +2 -0
- package/dist/logical.d.ts +23 -15
- package/dist/logical.js +14 -35
- package/dist/map.d.ts +48 -0
- package/dist/map.js +74 -0
- package/dist/object.d.ts +93 -14
- package/dist/object.js +61 -22
- package/dist/set.d.ts +70 -0
- package/dist/set.js +116 -0
- package/dist/string.d.ts +61 -35
- package/dist/string.js +98 -12
- package/dist/types.d.ts +66 -81
- package/package.json +72 -119
- package/dist/class-name.d.ts +0 -2
- package/dist/class-name.js +0 -2
- package/dist/guards.d.ts +0 -195
- package/dist/guards.js +0 -136
- package/dist/random.d.ts +0 -19
- package/dist/random.js +0 -35
package/dist/guards.d.ts
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import type { Def, Nil, NonNil, Undef } from '@budsbox/lib-types';
|
|
2
|
-
import type { Predicate, TypeGuard } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Checks if the provided value is `undefined`.
|
|
5
|
-
*
|
|
6
|
-
* @param value - The value to check for `undefined`.
|
|
7
|
-
* @returns `true` if the value is `undefined`, otherwise `false`.
|
|
8
|
-
*/
|
|
9
|
-
export declare function isUndef(value: unknown): value is Undef;
|
|
10
|
-
/**
|
|
11
|
-
* Checks if a given value is defined (not `undefined`).
|
|
12
|
-
*
|
|
13
|
-
* @param value - The value to check.
|
|
14
|
-
* @returns Whether the value is defined.
|
|
15
|
-
*/
|
|
16
|
-
export declare function isDef<U>(value: U): value is Def<U>;
|
|
17
|
-
/**
|
|
18
|
-
* Checks if the provided value is `null` or `undefined`.
|
|
19
|
-
*
|
|
20
|
-
* @param value - The value to be checked.
|
|
21
|
-
* @returns Returns `true` if the value is `null` or `undefined`, otherwise `false`.
|
|
22
|
-
*/
|
|
23
|
-
export declare function isNil(value: unknown): value is Nil;
|
|
24
|
-
/**
|
|
25
|
-
* Checks if the provided value is not null or undefined.
|
|
26
|
-
*
|
|
27
|
-
* @param value - The value to be checked.
|
|
28
|
-
* @returns Returns true if the value is not null or undefined; otherwise, false.
|
|
29
|
-
*/
|
|
30
|
-
export declare function isNotNil<T>(value: T): value is NonNil<T>;
|
|
31
|
-
/**
|
|
32
|
-
* Checks if the provided value is not null or undefined.
|
|
33
|
-
*
|
|
34
|
-
* @param value - The value to be checked.
|
|
35
|
-
* @returns Returns true if the value is not null or undefined; otherwise, false.
|
|
36
|
-
*/
|
|
37
|
-
export declare function isNotNil(value: unknown): value is NonNil;
|
|
38
|
-
/**
|
|
39
|
-
* Checks if the provided value is strictly equal to true.
|
|
40
|
-
*
|
|
41
|
-
* @param value - The value to check.
|
|
42
|
-
* @returns Returns true if the value is strictly true, otherwise false.
|
|
43
|
-
*/
|
|
44
|
-
export declare function isTrue(value: unknown): value is true;
|
|
45
|
-
/**
|
|
46
|
-
* Determines if the provided value is strictly `false`.
|
|
47
|
-
*
|
|
48
|
-
* @param value - The value to be checked.
|
|
49
|
-
* @returns Returns `true` if the value is `false`, otherwise returns `false`.
|
|
50
|
-
*/
|
|
51
|
-
export declare function isFalse(value: unknown): value is false;
|
|
52
|
-
/**
|
|
53
|
-
* Determines if the given value is truly, i.e., converts to true when used in a boolean context.
|
|
54
|
-
*
|
|
55
|
-
* @param value - The value to be tested for truthiness.
|
|
56
|
-
* @returns Returns true if the value is truthy, false otherwise.
|
|
57
|
-
*/
|
|
58
|
-
export declare function isTruly(value: unknown): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Determines if a given value is falsy.
|
|
61
|
-
* A value is considered falsy if it evaluates to false when coerced to a boolean.
|
|
62
|
-
*
|
|
63
|
-
* @param value - The value to be tested.
|
|
64
|
-
* @returns True if the value is falsy, otherwise false.
|
|
65
|
-
*/
|
|
66
|
-
export declare function isFalsy(value: unknown): boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Checks if the given value is an object.
|
|
69
|
-
*
|
|
70
|
-
* @param value - The value to check.
|
|
71
|
-
* @returns True if the value is an object, false otherwise.
|
|
72
|
-
*/
|
|
73
|
-
export declare function isObject(value: unknown): value is object;
|
|
74
|
-
/**
|
|
75
|
-
* Checks if the provided value is a record.
|
|
76
|
-
*
|
|
77
|
-
* A record is considered an object where the keys are property keys,
|
|
78
|
-
* and the values can be any type. The function also checks whether
|
|
79
|
-
* empty records are allowed based on the specified flag.
|
|
80
|
-
*
|
|
81
|
-
* @param value - The value to check.
|
|
82
|
-
* @param allowEmpty - Determines whether empty records are allowed.
|
|
83
|
-
* @returns A boolean indicating whether the value is a record.
|
|
84
|
-
*/
|
|
85
|
-
export declare function isRecord(value: unknown, allowEmpty?: boolean): value is Record<PropertyKey, unknown>;
|
|
86
|
-
/**
|
|
87
|
-
* Checks if the given value is an array.
|
|
88
|
-
*
|
|
89
|
-
* @typeParam T - Type of the value to be checked.
|
|
90
|
-
* @param value - The value to check.
|
|
91
|
-
* @returns True if the value is an array, otherwise false.
|
|
92
|
-
*/
|
|
93
|
-
export declare function isArray<T>(value: T | readonly T[]): value is readonly T[];
|
|
94
|
-
/**
|
|
95
|
-
* Checks if the provided value is an array.
|
|
96
|
-
*
|
|
97
|
-
* @typeParam T - type of the value to be checked.
|
|
98
|
-
* @param value - The value to be checked.
|
|
99
|
-
* @returns True if the value is an array, otherwise false.
|
|
100
|
-
*/
|
|
101
|
-
export declare function isArray<T>(value: T | T[]): value is T[];
|
|
102
|
-
/**
|
|
103
|
-
* Checks if the given value is an array.
|
|
104
|
-
*
|
|
105
|
-
* @param value - The value to be checked.
|
|
106
|
-
* @returns Returns true if the value is an array, otherwise false.
|
|
107
|
-
*/
|
|
108
|
-
export declare function isArray(value: unknown): value is unknown[];
|
|
109
|
-
/**
|
|
110
|
-
* Determines if the provided value is of type Function.
|
|
111
|
-
*
|
|
112
|
-
* @param value - The value to be checked.
|
|
113
|
-
* @returns True if the value is a function; otherwise, false.
|
|
114
|
-
*/
|
|
115
|
-
export declare function isFunction<TFn extends CallableFunction = CallableFunction>(value: unknown): value is TFn;
|
|
116
|
-
/**
|
|
117
|
-
* Determines if the provided value is a string.
|
|
118
|
-
*
|
|
119
|
-
* @param value - The value to check.
|
|
120
|
-
* @returns True if the value is a string, otherwise false.
|
|
121
|
-
*/
|
|
122
|
-
export declare function isString(value: unknown): value is string;
|
|
123
|
-
/**
|
|
124
|
-
* Checks if the provided value is a number and not NaN.
|
|
125
|
-
*
|
|
126
|
-
* @param value - The value to be checked.
|
|
127
|
-
* @returns Returns true if the value is a number and not NaN, otherwise false.
|
|
128
|
-
*/
|
|
129
|
-
export declare function isNumber(value: unknown): value is number;
|
|
130
|
-
/**
|
|
131
|
-
* Checks if the given value is of type boolean.
|
|
132
|
-
*
|
|
133
|
-
* @param value - The value to check.
|
|
134
|
-
* @returns A boolean indicating whether the value is a boolean or not.
|
|
135
|
-
*/
|
|
136
|
-
export declare function isBoolean(value: unknown): value is boolean;
|
|
137
|
-
/**
|
|
138
|
-
* Determines if a given property exists on a source object and optionally
|
|
139
|
-
* evaluates it with a provided predicate function.
|
|
140
|
-
*
|
|
141
|
-
* @param source - The object to check for the property existence. Can be `null` or `undefined`.
|
|
142
|
-
* @param prop - The property key to check on the source.
|
|
143
|
-
* @param test - Optional predicate function used to evaluate the property's value.
|
|
144
|
-
* @returns Returns `false` since the source is `null` or `undefined` in this function signature.
|
|
145
|
-
*/
|
|
146
|
-
export declare function hasProp(source: Nil, prop: PropertyKey, test?: Predicate<unknown>): false;
|
|
147
|
-
/**
|
|
148
|
-
* Checks if a given property exists on the provided object.
|
|
149
|
-
*
|
|
150
|
-
* @param source - The object to check for the property.
|
|
151
|
-
* @param prop - The property key to check for existence on the object.
|
|
152
|
-
* @returns A boolean indicating whether the property exists on the object.
|
|
153
|
-
*/
|
|
154
|
-
export declare function hasProp<TKey extends PropertyKey>(source: NonNil, prop: TKey): source is Record<TKey, unknown>;
|
|
155
|
-
/**
|
|
156
|
-
* Checks if the given object has a specific property that meets the criteria
|
|
157
|
-
* defined by a type guard function.
|
|
158
|
-
*
|
|
159
|
-
* @param source - The object to check for the property.
|
|
160
|
-
* @param prop - The key of the property to check for in the object.
|
|
161
|
-
* @param test - A type guard function that tests the property value against a type.
|
|
162
|
-
* @returns Returns `true` if the object has the specified property and the value passes
|
|
163
|
-
* the type guard, otherwise returns `false`.
|
|
164
|
-
*/
|
|
165
|
-
export declare function hasProp<TValue extends NonNil, TKey extends keyof TValue, TNarrowed extends TValue[TKey]>(source: TValue, prop: TKey, test: TypeGuard<Required<TValue>[TKey], TNarrowed>): source is TValue & Record<TKey, TNarrowed>;
|
|
166
|
-
/**
|
|
167
|
-
* Checks if the given `source` object has a property specified by `prop` and verifies
|
|
168
|
-
* that the value of the property satisfies the condition defined by the `test` function.
|
|
169
|
-
*
|
|
170
|
-
* @param source - The object to be checked for the specified property.
|
|
171
|
-
* @param prop - The key of the property to check for existence in the `source`.
|
|
172
|
-
* @param test - A type guard function used to validate the type of the property's value.
|
|
173
|
-
* @returns A boolean indicating whether the `source` has the specified property and the value
|
|
174
|
-
* satisfies the type guard test.
|
|
175
|
-
*/
|
|
176
|
-
export declare function hasProp<TKey extends PropertyKey, TNarrowed>(source: unknown, prop: TKey, test: TypeGuard<unknown, TNarrowed>): source is Record<TKey, TNarrowed>;
|
|
177
|
-
/**
|
|
178
|
-
* Checks if a given property exists on a source object and satisfies a specified test condition.
|
|
179
|
-
*
|
|
180
|
-
* @param source - The source object to check for the property.
|
|
181
|
-
* @param prop - The property key to check in the source object.
|
|
182
|
-
* @param test - A predicate function to test the value of the specified property.
|
|
183
|
-
* @returns True if the property exists on the source object and the test predicate returns true; otherwise, false.
|
|
184
|
-
*/
|
|
185
|
-
export declare function hasProp<TValue extends NonNil, TKey extends keyof TValue>(source: TValue, prop: TKey, test: Predicate<Required<TValue>[TKey]>): boolean;
|
|
186
|
-
/**
|
|
187
|
-
* Checks if a given property exists on the specified source object and optionally validates it using a predicate function.
|
|
188
|
-
*
|
|
189
|
-
* @param source - The object on which the property check is performed.
|
|
190
|
-
* @param prop - The property key to check for existence in the source object.
|
|
191
|
-
* @param test - An optional predicate function to validate the property value.
|
|
192
|
-
* @returns Returns true if the property exists on the source object and the predicate (if provided) evaluates to true; otherwise, false.
|
|
193
|
-
*/
|
|
194
|
-
export declare function hasProp(source: unknown, prop: PropertyKey, test?: Predicate<unknown>): boolean;
|
|
195
|
-
//# sourceMappingURL=guards.d.ts.map
|
package/dist/guards.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if the provided value is `undefined`.
|
|
3
|
-
*
|
|
4
|
-
* @param value - The value to check for `undefined`.
|
|
5
|
-
* @returns `true` if the value is `undefined`, otherwise `false`.
|
|
6
|
-
*/
|
|
7
|
-
export function isUndef(value) {
|
|
8
|
-
return value === undefined;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Checks if a given value is defined (not `undefined`).
|
|
12
|
-
*
|
|
13
|
-
* @param value - The value to be checked.
|
|
14
|
-
* @returns Returns true if the value is defined, otherwise false.
|
|
15
|
-
*/
|
|
16
|
-
export function isDef(value) {
|
|
17
|
-
return value !== undefined;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Checks if the provided value is `null` or `undefined`.
|
|
21
|
-
*
|
|
22
|
-
* @param value - The value to be checked.
|
|
23
|
-
* @returns Returns `true` if the value is `null` or `undefined`, otherwise `false`.
|
|
24
|
-
*/
|
|
25
|
-
export function isNil(value) {
|
|
26
|
-
return value == null;
|
|
27
|
-
}
|
|
28
|
-
export function isNotNil(value) {
|
|
29
|
-
return !isNil(value);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Checks if the provided value is strictly equal to true.
|
|
33
|
-
*
|
|
34
|
-
* @param value - The value to check.
|
|
35
|
-
* @returns Returns true if the value is strictly true, otherwise false.
|
|
36
|
-
*/
|
|
37
|
-
export function isTrue(value) {
|
|
38
|
-
return value === true;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Determines if the provided value is strictly `false`.
|
|
42
|
-
*
|
|
43
|
-
* @param value - The value to be checked.
|
|
44
|
-
* @returns Returns `true` if the value is `false`, otherwise returns `false`.
|
|
45
|
-
*/
|
|
46
|
-
export function isFalse(value) {
|
|
47
|
-
return value === false;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Determines if the given value is truly, i.e., converts to true when used in a boolean context.
|
|
51
|
-
*
|
|
52
|
-
* @param value - The value to be tested for truthiness.
|
|
53
|
-
* @returns Returns true if the value is truthy, false otherwise.
|
|
54
|
-
*/
|
|
55
|
-
export function isTruly(value) {
|
|
56
|
-
return Boolean(value);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Determines if a given value is falsy.
|
|
60
|
-
* A value is considered falsy if it evaluates to false when coerced to a boolean.
|
|
61
|
-
*
|
|
62
|
-
* @param value - The value to be tested.
|
|
63
|
-
* @returns True if the value is falsy, otherwise false.
|
|
64
|
-
*/
|
|
65
|
-
export function isFalsy(value) {
|
|
66
|
-
return !isTruly(value);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Checks if the given value is an object.
|
|
70
|
-
*
|
|
71
|
-
* @param value - The value to check.
|
|
72
|
-
* @returns True if the value is an object, false otherwise.
|
|
73
|
-
*/
|
|
74
|
-
export function isObject(value) {
|
|
75
|
-
return value != null && typeof value === 'object';
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Checks if the provided value is a record.
|
|
79
|
-
*
|
|
80
|
-
* A record is considered an object where the keys are property keys,
|
|
81
|
-
* and the values can be any type. The function also checks whether
|
|
82
|
-
* empty records are allowed based on the specified flag.
|
|
83
|
-
*
|
|
84
|
-
* @param value - The value to check.
|
|
85
|
-
* @param allowEmpty - Determines whether empty records are allowed.
|
|
86
|
-
* @returns A boolean indicating whether the value is a record.
|
|
87
|
-
*/
|
|
88
|
-
export function isRecord(value, allowEmpty = false) {
|
|
89
|
-
return isObject(value) && (allowEmpty || Object.keys(value).length > 0);
|
|
90
|
-
}
|
|
91
|
-
export function isArray(value) {
|
|
92
|
-
return Array.isArray(value);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Determines if the provided value is of type Function.
|
|
96
|
-
*
|
|
97
|
-
* @param value - The value to be checked.
|
|
98
|
-
* @returns True if the value is a function; otherwise, false.
|
|
99
|
-
*/
|
|
100
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
101
|
-
export function isFunction(value) {
|
|
102
|
-
return typeof value === 'function';
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Determines if the provided value is a string.
|
|
106
|
-
*
|
|
107
|
-
* @param value - The value to check.
|
|
108
|
-
* @returns True if the value is a string, otherwise false.
|
|
109
|
-
*/
|
|
110
|
-
export function isString(value) {
|
|
111
|
-
return typeof value === 'string';
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Checks if the provided value is a number and not NaN.
|
|
115
|
-
*
|
|
116
|
-
* @param value - The value to be checked.
|
|
117
|
-
* @returns Returns true if the value is a number and not NaN, otherwise false.
|
|
118
|
-
*/
|
|
119
|
-
export function isNumber(value) {
|
|
120
|
-
return typeof value === 'number' && !Number.isNaN(value);
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Checks if the given value is of type boolean.
|
|
124
|
-
*
|
|
125
|
-
* @param value - The value to check.
|
|
126
|
-
* @returns A boolean indicating whether the value is a boolean or not.
|
|
127
|
-
*/
|
|
128
|
-
export function isBoolean(value) {
|
|
129
|
-
return typeof value === 'boolean';
|
|
130
|
-
}
|
|
131
|
-
export function hasProp(source, prop, test) {
|
|
132
|
-
return (isNotNil(source) &&
|
|
133
|
-
Object.hasOwn(source, prop) &&
|
|
134
|
-
(!isFunction(test) || test(source[prop])));
|
|
135
|
-
}
|
|
136
|
-
//# sourceMappingURL=guards.js.map
|
package/dist/random.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { RNG } from './types.js';
|
|
2
|
-
export type { RNG };
|
|
3
|
-
/**
|
|
4
|
-
* Generates a hash value for the given string using the FNV-1a hashing algorithm.
|
|
5
|
-
*
|
|
6
|
-
* @param seed - The input string to hash.
|
|
7
|
-
* @returns The 32-bit unsigned integer hash of the input string.
|
|
8
|
-
*/
|
|
9
|
-
export declare function fnv1aHash(seed: string): number;
|
|
10
|
-
/**
|
|
11
|
-
* Generates a pseudo-random number generator (PRNG) based on the Mulberry32 algorithm.
|
|
12
|
-
*
|
|
13
|
-
* @param seed - The seed for the random number generator. It can be a string or a numeric value.
|
|
14
|
-
* If a string is provided, it will be hashed into a numeric value before use.
|
|
15
|
-
* @returns An object containing the seed and a `next` function that produces the next pseudo-random
|
|
16
|
-
* number in the sequence as a floating-point value in the range [0, 1).
|
|
17
|
-
*/
|
|
18
|
-
export declare function mulberry32(seed: string | number): RNG;
|
|
19
|
-
//# sourceMappingURL=random.d.ts.map
|
package/dist/random.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { isString } from '#guards';
|
|
2
|
-
/**
|
|
3
|
-
* Generates a hash value for the given string using the FNV-1a hashing algorithm.
|
|
4
|
-
*
|
|
5
|
-
* @param seed - The input string to hash.
|
|
6
|
-
* @returns The 32-bit unsigned integer hash of the input string.
|
|
7
|
-
*/
|
|
8
|
-
export function fnv1aHash(seed) {
|
|
9
|
-
let h = 2166136261 >>> 0;
|
|
10
|
-
for (let i = 0; i < seed.length; i += 1) {
|
|
11
|
-
h ^= seed.charCodeAt(i);
|
|
12
|
-
h = Math.imul(h, 16777619);
|
|
13
|
-
}
|
|
14
|
-
return h >>> 0;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Generates a pseudo-random number generator (PRNG) based on the Mulberry32 algorithm.
|
|
18
|
-
*
|
|
19
|
-
* @param seed - The seed for the random number generator. It can be a string or a numeric value.
|
|
20
|
-
* If a string is provided, it will be hashed into a numeric value before use.
|
|
21
|
-
* @returns An object containing the seed and a `next` function that produces the next pseudo-random
|
|
22
|
-
* number in the sequence as a floating-point value in the range [0, 1).
|
|
23
|
-
*/
|
|
24
|
-
export function mulberry32(seed) {
|
|
25
|
-
seed = isString(seed) ? fnv1aHash(seed) : seed;
|
|
26
|
-
let t = seed >>> 0;
|
|
27
|
-
const next = () => {
|
|
28
|
-
t += 0x6d2b79f5;
|
|
29
|
-
let x = Math.imul(t ^ (t >>> 15), 1 | t);
|
|
30
|
-
x ^= x + Math.imul(x ^ (x >>> 7), 61 | x);
|
|
31
|
-
return ((x ^ (x >>> 14)) >>> 0) / 4294967296;
|
|
32
|
-
};
|
|
33
|
-
return { seed, next };
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=random.js.map
|