@oscarpalmer/atoms 0.186.2 → 0.187.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/filter.d.mts +4 -4
- package/dist/array/find.d.mts +4 -4
- package/dist/array/first.d.mts +4 -4
- package/dist/array/get.d.mts +27 -1
- package/dist/array/get.mjs +5 -3
- package/dist/array/group-by.d.mts +6 -6
- package/dist/array/last.d.mts +4 -4
- package/dist/array/match.d.mts +7 -6
- package/dist/array/move.d.mts +7 -7
- package/dist/array/move.mjs +1 -1
- package/dist/array/select.d.mts +1 -0
- package/dist/array/slice.d.mts +3 -3
- package/dist/array/sort.d.mts +10 -7
- package/dist/array/sort.mjs +4 -3
- package/dist/array/swap.d.mts +1 -1
- package/dist/array/swap.mjs +1 -1
- package/dist/array/to-map.d.mts +32 -32
- package/dist/array/to-record.d.mts +6 -6
- package/dist/array/to-set.d.mts +6 -6
- package/dist/beacon.d.mts +6 -0
- package/dist/beacon.mjs +3 -0
- package/dist/color/index.d.mts +6 -2
- package/dist/color/index.mjs +6 -2
- package/dist/color/instance.d.mts +78 -14
- package/dist/color/instance.mjs +78 -14
- package/dist/color/misc/get.d.mts +39 -11
- package/dist/color/misc/get.mjs +39 -11
- package/dist/color/misc/is.d.mts +26 -11
- package/dist/color/misc/is.mjs +26 -11
- package/dist/color/misc/state.mjs +1 -1
- package/dist/color/models.d.mts +7 -4
- package/dist/color/space/hex.d.mts +15 -6
- package/dist/color/space/hex.mjs +15 -6
- package/dist/color/space/hsl.d.mts +10 -4
- package/dist/color/space/hsl.mjs +10 -4
- package/dist/color/space/rgb.d.mts +21 -12
- package/dist/color/space/rgb.mjs +21 -12
- package/dist/function/assert.d.mts +20 -14
- package/dist/function/assert.mjs +19 -13
- package/dist/function/limit.d.mts +8 -6
- package/dist/function/limit.mjs +8 -6
- package/dist/function/memoize.d.mts +15 -4
- package/dist/function/memoize.mjs +18 -4
- package/dist/function/once.d.mts +5 -3
- package/dist/function/once.mjs +5 -3
- package/dist/function/retry.d.mts +5 -2
- package/dist/function/retry.mjs +3 -1
- package/dist/function/work.d.mts +146 -98
- package/dist/{kalas.d.mts → herald.d.mts} +17 -8
- package/dist/{kalas.mjs → herald.mjs} +22 -13
- package/dist/index.d.mts +1464 -708
- package/dist/index.mjs +677 -324
- package/dist/internal/array/index-of.d.mts +4 -4
- package/dist/internal/array/insert.mjs +1 -1
- package/dist/internal/array/shuffle.d.mts +1 -0
- package/dist/internal/array/shuffle.mjs +2 -1
- package/dist/internal/is.d.mts +26 -8
- package/dist/internal/is.mjs +26 -8
- package/dist/internal/math/aggregate.d.mts +9 -9
- package/dist/internal/number.d.mts +13 -2
- package/dist/internal/number.mjs +13 -2
- package/dist/internal/random.d.mts +4 -2
- package/dist/internal/random.mjs +7 -5
- package/dist/internal/result.d.mts +17 -11
- package/dist/internal/result.mjs +10 -14
- package/dist/internal/string.d.mts +16 -1
- package/dist/internal/string.mjs +24 -1
- package/dist/internal/value/compare.d.mts +5 -2
- package/dist/internal/value/compare.mjs +5 -2
- package/dist/internal/value/equal.d.mts +12 -3
- package/dist/internal/value/equal.mjs +7 -4
- package/dist/internal/value/get.d.mts +17 -17
- package/dist/internal/value/has.d.mts +55 -11
- package/dist/internal/value/set.d.mts +24 -0
- package/dist/is.d.mts +12 -0
- package/dist/is.mjs +16 -1
- package/dist/logger.d.mts +7 -6
- package/dist/logger.mjs +6 -5
- package/dist/math.d.mts +36 -18
- package/dist/math.mjs +6 -3
- package/dist/models.d.mts +3 -3
- package/dist/promise/delay.d.mts +2 -0
- package/dist/promise/helpers.d.mts +6 -4
- package/dist/promise/helpers.mjs +6 -4
- package/dist/promise/index.d.mts +49 -38
- package/dist/promise/misc.d.mts +10 -7
- package/dist/promise/misc.mjs +4 -3
- package/dist/promise/models.d.mts +18 -19
- package/dist/promise/models.mjs +4 -3
- package/dist/promise/timed.d.mts +8 -6
- package/dist/query.d.mts +2 -0
- package/dist/query.mjs +2 -0
- package/dist/queue.d.mts +15 -4
- package/dist/queue.mjs +10 -3
- package/dist/random.d.mts +9 -2
- package/dist/random.mjs +7 -2
- package/dist/result/index.d.mts +14 -8
- package/dist/result/match.d.mts +18 -10
- package/dist/result/misc.d.mts +14 -7
- package/dist/result/misc.mjs +4 -2
- package/dist/result/models.d.mts +2 -0
- package/dist/result/work/flow.d.mts +86 -62
- package/dist/result/work/pipe.d.mts +55 -33
- package/dist/sized/map.d.mts +19 -16
- package/dist/sized/map.mjs +4 -4
- package/dist/sized/set.d.mts +20 -16
- package/dist/sized/set.mjs +8 -7
- package/dist/string/case.d.mts +8 -0
- package/dist/string/case.mjs +8 -0
- package/dist/string/fuzzy.d.mts +19 -5
- package/dist/string/fuzzy.mjs +7 -0
- package/dist/string/index.d.mts +17 -2
- package/dist/string/index.mjs +7 -9
- package/dist/string/match.d.mts +3 -0
- package/dist/string/match.mjs +3 -0
- package/dist/string/normalize.d.mts +6 -2
- package/dist/string/normalize.mjs +5 -2
- package/dist/string/template.d.mts +38 -9
- package/dist/string/template.mjs +19 -19
- package/dist/value/clone.d.mts +25 -4
- package/dist/value/clone.mjs +36 -22
- package/dist/value/collection.d.mts +9 -6
- package/dist/value/collection.mjs +3 -2
- package/dist/value/diff.d.mts +3 -1
- package/dist/value/diff.mjs +1 -0
- package/dist/value/freeze.d.mts +118 -9
- package/dist/value/freeze.mjs +56 -14
- package/dist/value/index.d.mts +1 -2
- package/dist/value/index.mjs +1 -2
- package/dist/value/merge.d.mts +11 -5
- package/dist/value/merge.mjs +2 -2
- package/dist/value/omit.d.mts +1 -0
- package/dist/value/omit.mjs +1 -0
- package/dist/value/pick.d.mts +1 -0
- package/dist/value/pick.mjs +1 -0
- package/dist/value/shake.d.mts +1 -0
- package/dist/value/shake.mjs +1 -0
- package/dist/value/smush.d.mts +1 -0
- package/dist/value/smush.mjs +1 -0
- package/dist/value/transform.d.mts +7 -3
- package/dist/value/unsmush.d.mts +1 -0
- package/dist/value/unsmush.mjs +1 -0
- package/package.json +11 -7
- package/src/array/filter.ts +4 -4
- package/src/array/find.ts +4 -4
- package/src/array/first.ts +4 -4
- package/src/array/get.ts +40 -5
- package/src/array/group-by.ts +6 -6
- package/src/array/last.ts +4 -4
- package/src/array/match.ts +7 -6
- package/src/array/move.ts +7 -7
- package/src/array/select.ts +1 -0
- package/src/array/slice.ts +3 -3
- package/src/array/sort.ts +15 -10
- package/src/array/swap.ts +1 -1
- package/src/array/to-map.ts +32 -32
- package/src/array/to-record.ts +6 -6
- package/src/array/to-set.ts +6 -6
- package/src/beacon.ts +6 -0
- package/src/color/index.ts +6 -2
- package/src/color/instance.ts +78 -14
- package/src/color/misc/get.ts +39 -11
- package/src/color/misc/is.ts +26 -11
- package/src/color/misc/state.ts +1 -1
- package/src/color/models.ts +7 -4
- package/src/color/space/hex.ts +15 -6
- package/src/color/space/hsl.ts +10 -4
- package/src/color/space/rgb.ts +21 -12
- package/src/function/assert.ts +20 -14
- package/src/function/limit.ts +8 -6
- package/src/function/memoize.ts +24 -5
- package/src/function/once.ts +5 -3
- package/src/function/retry.ts +7 -3
- package/src/function/work.ts +146 -98
- package/src/{kalas.ts → herald.ts} +23 -14
- package/src/index.ts +3 -2
- package/src/internal/array/index-of.ts +4 -4
- package/src/internal/array/insert.ts +1 -1
- package/src/internal/array/shuffle.ts +2 -1
- package/src/internal/is.ts +26 -8
- package/src/internal/math/aggregate.ts +9 -9
- package/src/internal/number.ts +13 -2
- package/src/internal/random.ts +10 -4
- package/src/internal/result.ts +30 -29
- package/src/internal/string.ts +28 -0
- package/src/internal/value/compare.ts +5 -2
- package/src/internal/value/equal.ts +13 -4
- package/src/internal/value/get.ts +17 -17
- package/src/internal/value/has.ts +54 -11
- package/src/internal/value/set.ts +24 -0
- package/src/is.ts +15 -1
- package/src/logger.ts +8 -7
- package/src/math.ts +36 -18
- package/src/models.ts +3 -3
- package/src/promise/delay.ts +2 -0
- package/src/promise/helpers.ts +6 -4
- package/src/promise/index.ts +49 -38
- package/src/promise/misc.ts +10 -7
- package/src/promise/models.ts +18 -19
- package/src/promise/timed.ts +8 -6
- package/src/query.ts +2 -0
- package/src/queue.ts +15 -4
- package/src/random.ts +8 -1
- package/src/result/index.ts +14 -8
- package/src/result/match.ts +18 -10
- package/src/result/misc.ts +17 -9
- package/src/result/models.ts +2 -0
- package/src/result/work/flow.ts +86 -62
- package/src/result/work/pipe.ts +55 -33
- package/src/sized/map.ts +20 -17
- package/src/sized/set.ts +21 -17
- package/src/string/case.ts +8 -0
- package/src/string/fuzzy.ts +19 -5
- package/src/string/index.ts +18 -15
- package/src/string/match.ts +3 -0
- package/src/string/normalize.ts +6 -2
- package/src/string/template.ts +69 -18
- package/src/value/clone.ts +51 -26
- package/src/value/collection.ts +9 -6
- package/src/value/diff.ts +3 -1
- package/src/value/freeze.ts +239 -25
- package/src/value/index.ts +0 -1
- package/src/value/merge.ts +11 -5
- package/src/value/omit.ts +1 -0
- package/src/value/pick.ts +1 -0
- package/src/value/shake.ts +1 -0
- package/src/value/smush.ts +1 -0
- package/src/value/transform.ts +7 -3
- package/src/value/unsmush.ts +1 -0
|
@@ -72,7 +72,7 @@ declare namespace indexOf {
|
|
|
72
72
|
/**
|
|
73
73
|
* Get the index of the last matching item by callback
|
|
74
74
|
*
|
|
75
|
-
*
|
|
75
|
+
* _Available as `lastIndexOf` and `indexOf.last`_
|
|
76
76
|
*
|
|
77
77
|
* @param array Array to search in
|
|
78
78
|
* @param callback Callback to get an item's value
|
|
@@ -92,7 +92,7 @@ declare function lastIndexOf<Item, Callback extends (item: Item, index: number,
|
|
|
92
92
|
/**
|
|
93
93
|
* Get the index of the last matching item by key
|
|
94
94
|
*
|
|
95
|
-
*
|
|
95
|
+
* _Available as `lastIndexOf` and `indexOf.last`_
|
|
96
96
|
*
|
|
97
97
|
* @param array Array to search in
|
|
98
98
|
* @param key Key to match items by
|
|
@@ -112,7 +112,7 @@ declare function lastIndexOf<Item extends PlainObject, ItemKey extends keyof Ite
|
|
|
112
112
|
/**
|
|
113
113
|
* Get the index of the last item matching the filter
|
|
114
114
|
*
|
|
115
|
-
*
|
|
115
|
+
* _Available as `lastIndexOf` and `indexOf.last`_
|
|
116
116
|
*
|
|
117
117
|
* @param array Array to search in
|
|
118
118
|
* @param filter Filter callback to match items
|
|
@@ -130,7 +130,7 @@ declare function lastIndexOf<Item>(array: Item[], filter: (item: Item, index: nu
|
|
|
130
130
|
/**
|
|
131
131
|
* Get the index of the last item matching the given item
|
|
132
132
|
*
|
|
133
|
-
*
|
|
133
|
+
* _Available as `lastIndexOf` and `indexOf.last`_
|
|
134
134
|
*
|
|
135
135
|
* @param array Array to search in
|
|
136
136
|
* @param item Item to match against
|
|
@@ -5,7 +5,7 @@ function insertChunkedValues(type, array, items, start, deleteCount) {
|
|
|
5
5
|
const actualStart = Math.min(Math.max(0, start), array.length);
|
|
6
6
|
const chunked = chunk(items);
|
|
7
7
|
const lastIndex = chunked.length - 1;
|
|
8
|
-
let index =
|
|
8
|
+
let index = chunked.length;
|
|
9
9
|
let returned;
|
|
10
10
|
while (index > 0) {
|
|
11
11
|
index -= 1;
|
|
@@ -2,6 +2,7 @@ import { getRandomInteger } from "../random.mjs";
|
|
|
2
2
|
//#region src/internal/array/shuffle.ts
|
|
3
3
|
/**
|
|
4
4
|
* Shuffle items in array
|
|
5
|
+
*
|
|
5
6
|
* @param array Original array
|
|
6
7
|
* @returns Shuffled array
|
|
7
8
|
*/
|
|
@@ -9,7 +10,7 @@ function shuffle(array) {
|
|
|
9
10
|
if (!Array.isArray(array)) return [];
|
|
10
11
|
const shuffled = array.slice();
|
|
11
12
|
if (shuffled.length < 2) return shuffled;
|
|
12
|
-
let index =
|
|
13
|
+
let index = shuffled.length;
|
|
13
14
|
while (--index >= 0) {
|
|
14
15
|
const random = getRandomInteger(0, index);
|
|
15
16
|
[shuffled[index], shuffled[random]] = [shuffled[random], shuffled[index]];
|
package/dist/internal/is.d.mts
CHANGED
|
@@ -2,111 +2,129 @@ import { ArrayOrPlainObject, Constructor, Key, PlainObject, Primitive, TypedArra
|
|
|
2
2
|
|
|
3
3
|
//#region src/internal/is.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* Is the value an array or a
|
|
5
|
+
* Is the value an array or a plain object?
|
|
6
|
+
*
|
|
6
7
|
* @param value Value to check
|
|
7
|
-
* @returns `true` if the value is an array or a
|
|
8
|
+
* @returns `true` if the value is an array or a plain object, otherwise `false`
|
|
8
9
|
*/
|
|
9
10
|
declare function isArrayOrPlainObject(value: unknown): value is ArrayOrPlainObject;
|
|
10
11
|
/**
|
|
11
12
|
* Is the value a constructor function?
|
|
13
|
+
*
|
|
12
14
|
* @param value Value to check
|
|
13
15
|
* @returns `true` if the value is a constructor function, otherwise `false`
|
|
14
16
|
*/
|
|
15
17
|
declare function isConstructor(value: unknown): value is Constructor;
|
|
16
18
|
/**
|
|
17
19
|
* Is the value an instance of the constructor?
|
|
20
|
+
*
|
|
18
21
|
* @param constructor Class constructor
|
|
19
22
|
* @param value Value to check
|
|
20
23
|
* @returns `true` if the value is an instance of the constructor, otherwise `false`
|
|
21
24
|
*/
|
|
22
25
|
declare function isInstanceOf<Instance>(constructor: Constructor<Instance>, value: unknown): value is Instance;
|
|
23
26
|
/**
|
|
24
|
-
* Is the value a
|
|
27
|
+
* Is the value a _Key_?
|
|
28
|
+
*
|
|
25
29
|
* @param value Value to check
|
|
26
|
-
* @returns `true` if the value is a
|
|
30
|
+
* @returns `true` if the value is a _Key_ _(`number` or `string`)_, otherwise `false`
|
|
27
31
|
*/
|
|
28
32
|
declare function isKey(value: unknown): value is Key;
|
|
29
33
|
/**
|
|
30
34
|
* Is the value not an array or a plain object?
|
|
35
|
+
*
|
|
31
36
|
* @param value Value to check
|
|
32
37
|
* @returns `true` if the value is not an array or a plain object, otherwise `false`
|
|
33
38
|
*/
|
|
34
39
|
declare function isNonArrayOrPlainObject<Value>(value: Value): value is Exclude<Value, ArrayOrPlainObject>;
|
|
35
40
|
/**
|
|
36
41
|
* Is the value not a constructor function?
|
|
42
|
+
*
|
|
37
43
|
* @param value Value to check
|
|
38
44
|
* @returns `true` if the value is not a constructor function, otherwise `false`
|
|
39
45
|
*/
|
|
40
46
|
declare function isNonConstructor<Value>(value: Value): value is Exclude<Value, Constructor>;
|
|
41
47
|
/**
|
|
42
48
|
* Is the value not an instance of the constructor?
|
|
49
|
+
*
|
|
43
50
|
* @param constructor Class constructor
|
|
44
51
|
* @param value Value to check
|
|
45
52
|
* @returns `true` if the value is not an instance of the constructor, otherwise `false`
|
|
46
53
|
*/
|
|
47
54
|
declare function isNonInstanceOf<Instance, Value>(constructor: Constructor<Instance>, value: Value): value is Exclude<Value, Instance>;
|
|
48
55
|
/**
|
|
49
|
-
* Is the value not a
|
|
56
|
+
* Is the value not a _Key_?
|
|
57
|
+
*
|
|
50
58
|
* @param value Value to check
|
|
51
|
-
* @returns `true` if the value is not a
|
|
59
|
+
* @returns `true` if the value is not a _Key_ _(`number` or `string`)_, otherwise `false`
|
|
52
60
|
*/
|
|
53
61
|
declare function isNonKey<Value>(value: Value): value is Exclude<Value, Key>;
|
|
54
62
|
/**
|
|
55
63
|
* Is the value not a number?
|
|
64
|
+
*
|
|
56
65
|
* @param value Value to check
|
|
57
66
|
* @returns `true` if the value is not a `number`, otherwise `false`
|
|
58
67
|
*/
|
|
59
68
|
declare function isNonNumber<Value>(value: Value): value is Exclude<Value, number>;
|
|
60
69
|
/**
|
|
61
70
|
* Is the value not a plain object?
|
|
71
|
+
*
|
|
62
72
|
* @param value Value to check
|
|
63
73
|
* @returns `true` if the value is not a plain object, otherwise `false`
|
|
64
74
|
*/
|
|
65
75
|
declare function isNonPlainObject<Value>(value: Value): value is Exclude<Value, PlainObject>;
|
|
66
76
|
/**
|
|
67
77
|
* Is the value not a primitive value?
|
|
78
|
+
*
|
|
68
79
|
* @param value Value to check
|
|
69
80
|
* @returns `true` if the value is not a primitive value, otherwise `false`
|
|
70
81
|
*/
|
|
71
82
|
declare function isNonPrimitive<Value>(value: Value): value is Exclude<Value, Primitive>;
|
|
72
83
|
/**
|
|
73
84
|
* Is the value not a template strings array?
|
|
85
|
+
*
|
|
74
86
|
* @param value Value to check
|
|
75
87
|
* @returns `true` if the value is not a `TemplateStringsArray`, otherwise `false`
|
|
76
88
|
*/
|
|
77
89
|
declare function isNonTemplateStringsArray<Value>(value: Value): value is Exclude<Value, TemplateStringsArray>;
|
|
78
90
|
/**
|
|
79
91
|
* Is the value not a typed array?
|
|
92
|
+
*
|
|
80
93
|
* @param value Value to check
|
|
81
94
|
* @returns `true` if the value is not a typed array, otherwise `false`
|
|
82
95
|
*/
|
|
83
96
|
declare function isNonTypedArray<Value>(value: Value): value is Exclude<Value, TypedArray>;
|
|
84
97
|
/**
|
|
85
98
|
* Is the value a number?
|
|
99
|
+
*
|
|
86
100
|
* @param value Value to check
|
|
87
101
|
* @returns `true` if the value is a `number`, otherwise `false`
|
|
88
102
|
*/
|
|
89
103
|
declare function isNumber(value: unknown): value is number;
|
|
90
104
|
/**
|
|
91
105
|
* Is the value a plain object?
|
|
106
|
+
*
|
|
92
107
|
* @param value Value to check
|
|
93
108
|
* @returns `true` if the value is a plain object, otherwise `false`
|
|
94
109
|
*/
|
|
95
110
|
declare function isPlainObject(value: unknown): value is PlainObject;
|
|
96
111
|
/**
|
|
97
|
-
*
|
|
112
|
+
* Is the value a primitive value?
|
|
113
|
+
*
|
|
98
114
|
* @param value Value to check
|
|
99
|
-
* @returns `true` if the value
|
|
115
|
+
* @returns `true` if the value is a primitive value, otherwise `false`
|
|
100
116
|
*/
|
|
101
117
|
declare function isPrimitive(value: unknown): value is Primitive;
|
|
102
118
|
/**
|
|
103
119
|
* Is the value a template strings array?
|
|
120
|
+
*
|
|
104
121
|
* @param value Value to check
|
|
105
122
|
* @returns `true` if the value is a `TemplateStringsArray`, otherwise `false`
|
|
106
123
|
*/
|
|
107
124
|
declare function isTemplateStringsArray(value: unknown): value is TemplateStringsArray;
|
|
108
125
|
/**
|
|
109
126
|
* Is the value a typed array?
|
|
127
|
+
*
|
|
110
128
|
* @param value Value to check
|
|
111
129
|
* @returns `true` if the value is a typed array, otherwise `false`
|
|
112
130
|
*/
|
package/dist/internal/is.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
//#region src/internal/is.ts
|
|
2
2
|
/**
|
|
3
|
-
* Is the value an array or a
|
|
3
|
+
* Is the value an array or a plain object?
|
|
4
|
+
*
|
|
4
5
|
* @param value Value to check
|
|
5
|
-
* @returns `true` if the value is an array or a
|
|
6
|
+
* @returns `true` if the value is an array or a plain object, otherwise `false`
|
|
6
7
|
*/
|
|
7
8
|
function isArrayOrPlainObject(value) {
|
|
8
9
|
return Array.isArray(value) || isPlainObject(value);
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* Is the value a constructor function?
|
|
13
|
+
*
|
|
12
14
|
* @param value Value to check
|
|
13
15
|
* @returns `true` if the value is a constructor function, otherwise `false`
|
|
14
16
|
*/
|
|
@@ -17,6 +19,7 @@ function isConstructor(value) {
|
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Is the value an instance of the constructor?
|
|
22
|
+
*
|
|
20
23
|
* @param constructor Class constructor
|
|
21
24
|
* @param value Value to check
|
|
22
25
|
* @returns `true` if the value is an instance of the constructor, otherwise `false`
|
|
@@ -25,15 +28,17 @@ function isInstanceOf(constructor, value) {
|
|
|
25
28
|
return isConstructor(constructor) && value instanceof constructor;
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
28
|
-
* Is the value a
|
|
31
|
+
* Is the value a _Key_?
|
|
32
|
+
*
|
|
29
33
|
* @param value Value to check
|
|
30
|
-
* @returns `true` if the value is a
|
|
34
|
+
* @returns `true` if the value is a _Key_ _(`number` or `string`)_, otherwise `false`
|
|
31
35
|
*/
|
|
32
36
|
function isKey(value) {
|
|
33
37
|
return typeof value === "number" || typeof value === "string";
|
|
34
38
|
}
|
|
35
39
|
/**
|
|
36
40
|
* Is the value not an array or a plain object?
|
|
41
|
+
*
|
|
37
42
|
* @param value Value to check
|
|
38
43
|
* @returns `true` if the value is not an array or a plain object, otherwise `false`
|
|
39
44
|
*/
|
|
@@ -42,6 +47,7 @@ function isNonArrayOrPlainObject(value) {
|
|
|
42
47
|
}
|
|
43
48
|
/**
|
|
44
49
|
* Is the value not a constructor function?
|
|
50
|
+
*
|
|
45
51
|
* @param value Value to check
|
|
46
52
|
* @returns `true` if the value is not a constructor function, otherwise `false`
|
|
47
53
|
*/
|
|
@@ -50,6 +56,7 @@ function isNonConstructor(value) {
|
|
|
50
56
|
}
|
|
51
57
|
/**
|
|
52
58
|
* Is the value not an instance of the constructor?
|
|
59
|
+
*
|
|
53
60
|
* @param constructor Class constructor
|
|
54
61
|
* @param value Value to check
|
|
55
62
|
* @returns `true` if the value is not an instance of the constructor, otherwise `false`
|
|
@@ -58,15 +65,17 @@ function isNonInstanceOf(constructor, value) {
|
|
|
58
65
|
return !isInstanceOf(constructor, value);
|
|
59
66
|
}
|
|
60
67
|
/**
|
|
61
|
-
* Is the value not a
|
|
68
|
+
* Is the value not a _Key_?
|
|
69
|
+
*
|
|
62
70
|
* @param value Value to check
|
|
63
|
-
* @returns `true` if the value is not a
|
|
71
|
+
* @returns `true` if the value is not a _Key_ _(`number` or `string`)_, otherwise `false`
|
|
64
72
|
*/
|
|
65
73
|
function isNonKey(value) {
|
|
66
74
|
return !isKey(value);
|
|
67
75
|
}
|
|
68
76
|
/**
|
|
69
77
|
* Is the value not a number?
|
|
78
|
+
*
|
|
70
79
|
* @param value Value to check
|
|
71
80
|
* @returns `true` if the value is not a `number`, otherwise `false`
|
|
72
81
|
*/
|
|
@@ -75,6 +84,7 @@ function isNonNumber(value) {
|
|
|
75
84
|
}
|
|
76
85
|
/**
|
|
77
86
|
* Is the value not a plain object?
|
|
87
|
+
*
|
|
78
88
|
* @param value Value to check
|
|
79
89
|
* @returns `true` if the value is not a plain object, otherwise `false`
|
|
80
90
|
*/
|
|
@@ -83,6 +93,7 @@ function isNonPlainObject(value) {
|
|
|
83
93
|
}
|
|
84
94
|
/**
|
|
85
95
|
* Is the value not a primitive value?
|
|
96
|
+
*
|
|
86
97
|
* @param value Value to check
|
|
87
98
|
* @returns `true` if the value is not a primitive value, otherwise `false`
|
|
88
99
|
*/
|
|
@@ -91,6 +102,7 @@ function isNonPrimitive(value) {
|
|
|
91
102
|
}
|
|
92
103
|
/**
|
|
93
104
|
* Is the value not a template strings array?
|
|
105
|
+
*
|
|
94
106
|
* @param value Value to check
|
|
95
107
|
* @returns `true` if the value is not a `TemplateStringsArray`, otherwise `false`
|
|
96
108
|
*/
|
|
@@ -99,6 +111,7 @@ function isNonTemplateStringsArray(value) {
|
|
|
99
111
|
}
|
|
100
112
|
/**
|
|
101
113
|
* Is the value not a typed array?
|
|
114
|
+
*
|
|
102
115
|
* @param value Value to check
|
|
103
116
|
* @returns `true` if the value is not a typed array, otherwise `false`
|
|
104
117
|
*/
|
|
@@ -107,6 +120,7 @@ function isNonTypedArray(value) {
|
|
|
107
120
|
}
|
|
108
121
|
/**
|
|
109
122
|
* Is the value a number?
|
|
123
|
+
*
|
|
110
124
|
* @param value Value to check
|
|
111
125
|
* @returns `true` if the value is a `number`, otherwise `false`
|
|
112
126
|
*/
|
|
@@ -115,6 +129,7 @@ function isNumber(value) {
|
|
|
115
129
|
}
|
|
116
130
|
/**
|
|
117
131
|
* Is the value a plain object?
|
|
132
|
+
*
|
|
118
133
|
* @param value Value to check
|
|
119
134
|
* @returns `true` if the value is a plain object, otherwise `false`
|
|
120
135
|
*/
|
|
@@ -125,9 +140,10 @@ function isPlainObject(value) {
|
|
|
125
140
|
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
126
141
|
}
|
|
127
142
|
/**
|
|
128
|
-
*
|
|
143
|
+
* Is the value a primitive value?
|
|
144
|
+
*
|
|
129
145
|
* @param value Value to check
|
|
130
|
-
* @returns `true` if the value
|
|
146
|
+
* @returns `true` if the value is a primitive value, otherwise `false`
|
|
131
147
|
*/
|
|
132
148
|
function isPrimitive(value) {
|
|
133
149
|
if (value == null) return true;
|
|
@@ -136,6 +152,7 @@ function isPrimitive(value) {
|
|
|
136
152
|
}
|
|
137
153
|
/**
|
|
138
154
|
* Is the value a template strings array?
|
|
155
|
+
*
|
|
139
156
|
* @param value Value to check
|
|
140
157
|
* @returns `true` if the value is a `TemplateStringsArray`, otherwise `false`
|
|
141
158
|
*/
|
|
@@ -144,6 +161,7 @@ function isTemplateStringsArray(value) {
|
|
|
144
161
|
}
|
|
145
162
|
/**
|
|
146
163
|
* Is the value a typed array?
|
|
164
|
+
*
|
|
147
165
|
* @param value Value to check
|
|
148
166
|
* @returns `true` if the value is a typed array, otherwise `false`
|
|
149
167
|
*/
|
|
@@ -17,14 +17,14 @@ declare function getAggregateCallback(key: unknown): Function | undefined;
|
|
|
17
17
|
* max(
|
|
18
18
|
* [{id: 1, value: 10}, {id: 2, value: 20}],
|
|
19
19
|
* item => item.value,
|
|
20
|
-
* ); // 20
|
|
20
|
+
* ); // => 20
|
|
21
21
|
*
|
|
22
|
-
* max([], item => item.value); // Number.NaN
|
|
22
|
+
* max([], item => item.value); // => Number.NaN
|
|
23
23
|
* ```
|
|
24
24
|
*
|
|
25
25
|
* @param items List of items
|
|
26
26
|
* @param callback Callback to get an item's value
|
|
27
|
-
* @returns Maximum value, or `NaN` if no maximum can be found
|
|
27
|
+
* @returns Maximum value, or `Number.NaN` if no maximum can be found
|
|
28
28
|
*/
|
|
29
29
|
declare function max<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
|
|
30
30
|
/**
|
|
@@ -35,14 +35,14 @@ declare function max<Item>(items: Item[], callback: (item: Item, index: number,
|
|
|
35
35
|
* max(
|
|
36
36
|
* [{id: 1, value: 10}, {id: 2, value: 20}],
|
|
37
37
|
* 'value',
|
|
38
|
-
* ); // 20
|
|
38
|
+
* ); // => 20
|
|
39
39
|
*
|
|
40
|
-
* max([], 'value'); // Number.NaN
|
|
40
|
+
* max([], 'value'); // => Number.NaN
|
|
41
41
|
* ```
|
|
42
42
|
*
|
|
43
43
|
* @param items List of items
|
|
44
44
|
* @param key Key to use for value
|
|
45
|
-
* @returns Maximum value, or `NaN` if no maximum can be found
|
|
45
|
+
* @returns Maximum value, or `Number.NaN` if no maximum can be found
|
|
46
46
|
*/
|
|
47
47
|
declare function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(items: Item[], key: ItemKey): number;
|
|
48
48
|
/**
|
|
@@ -50,12 +50,12 @@ declare function max<Item extends PlainObject, ItemKey extends keyof NumericalVa
|
|
|
50
50
|
*
|
|
51
51
|
* @example
|
|
52
52
|
* ```typescript
|
|
53
|
-
* max([10, 20]); // 20
|
|
54
|
-
* max([]); // Number.NaN
|
|
53
|
+
* max([10, 20]); // => 20
|
|
54
|
+
* max([]); // => Number.NaN
|
|
55
55
|
* ```
|
|
56
56
|
*
|
|
57
57
|
* @param values List of numbers
|
|
58
|
-
* @returns Maximum value, or `NaN` if no maximum can be found
|
|
58
|
+
* @returns Maximum value, or `Number.NaN` if no maximum can be found
|
|
59
59
|
*/
|
|
60
60
|
declare function max(values: number[]): number;
|
|
61
61
|
declare function getAggregated(type: NonAverageAggregationType, array: unknown[], key?: unknown): number;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//#region src/internal/number.d.ts
|
|
2
2
|
/**
|
|
3
3
|
* Is the number between a minimum and maximum value?
|
|
4
|
+
*
|
|
4
5
|
* @param value Value to check
|
|
5
6
|
* @param minimum Minimum value
|
|
6
7
|
* @param maximum Maximum value
|
|
@@ -9,17 +10,27 @@
|
|
|
9
10
|
declare function between(value: number, minimum: number, maximum: number): boolean;
|
|
10
11
|
/**
|
|
11
12
|
* Clamp a number between a minimum and maximum value
|
|
13
|
+
*
|
|
12
14
|
* @param value Value to clamp
|
|
13
15
|
* @param minimum Minimum value
|
|
14
16
|
* @param maximum Maximum value
|
|
15
17
|
* @param loop If `true`, the value will loop around when smaller than the minimum or larger than the maximum _(defaults to `false`)_
|
|
16
18
|
* @returns Clamped value
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* clamp(10, 0, 5); // => 5
|
|
23
|
+
* clamp(10, 0, 5, true); // => 0
|
|
24
|
+
* ```
|
|
17
25
|
*/
|
|
18
26
|
declare function clamp(value: number, minimum: number, maximum: number, loop?: boolean): number;
|
|
19
27
|
/**
|
|
20
|
-
* Get the number value from an unknown value
|
|
28
|
+
* Get the number value from an unknown value
|
|
29
|
+
*
|
|
30
|
+
* _(Based on Lodash)_
|
|
31
|
+
*
|
|
21
32
|
* @param value Original value
|
|
22
|
-
* @returns Original value as a number, or `NaN` if the value is unable to be parsed
|
|
33
|
+
* @returns Original value as a number, or `Number.NaN` if the value is unable to be parsed
|
|
23
34
|
*/
|
|
24
35
|
declare function getNumber(value: unknown): number;
|
|
25
36
|
declare function getNumberOrDefault(value: unknown, defaultValue: number, minimum?: number): number;
|
package/dist/internal/number.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { isNumber } from "./is.mjs";
|
|
|
2
2
|
//#region src/internal/number.ts
|
|
3
3
|
/**
|
|
4
4
|
* Is the number between a minimum and maximum value?
|
|
5
|
+
*
|
|
5
6
|
* @param value Value to check
|
|
6
7
|
* @param minimum Minimum value
|
|
7
8
|
* @param maximum Maximum value
|
|
@@ -18,11 +19,18 @@ function between(value, minimum, maximum) {
|
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
21
|
* Clamp a number between a minimum and maximum value
|
|
22
|
+
*
|
|
21
23
|
* @param value Value to clamp
|
|
22
24
|
* @param minimum Minimum value
|
|
23
25
|
* @param maximum Maximum value
|
|
24
26
|
* @param loop If `true`, the value will loop around when smaller than the minimum or larger than the maximum _(defaults to `false`)_
|
|
25
27
|
* @returns Clamped value
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* clamp(10, 0, 5); // => 5
|
|
32
|
+
* clamp(10, 0, 5, true); // => 0
|
|
33
|
+
* ```
|
|
26
34
|
*/
|
|
27
35
|
function clamp(value, minimum, maximum, loop) {
|
|
28
36
|
if (![
|
|
@@ -34,9 +42,12 @@ function clamp(value, minimum, maximum, loop) {
|
|
|
34
42
|
return value > maximum ? loop === true ? minimum : maximum : value;
|
|
35
43
|
}
|
|
36
44
|
/**
|
|
37
|
-
* Get the number value from an unknown value
|
|
45
|
+
* Get the number value from an unknown value
|
|
46
|
+
*
|
|
47
|
+
* _(Based on Lodash)_
|
|
48
|
+
*
|
|
38
49
|
* @param value Original value
|
|
39
|
-
* @returns Original value as a number, or `NaN` if the value is unable to be parsed
|
|
50
|
+
* @returns Original value as a number, or `Number.NaN` if the value is unable to be parsed
|
|
40
51
|
*/
|
|
41
52
|
function getNumber(value) {
|
|
42
53
|
if (typeof value === "number") return value;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
//#region src/internal/random.d.ts
|
|
2
2
|
/**
|
|
3
3
|
* Get a random floating-point number
|
|
4
|
+
*
|
|
4
5
|
* @param minimum Minimum value
|
|
5
6
|
* @param maximum Maximum value
|
|
6
7
|
* @returns Random floating-point number
|
|
7
8
|
*/
|
|
8
|
-
declare function
|
|
9
|
+
declare function getRandomFloatingNumber(minimum?: number, maximum?: number): number;
|
|
9
10
|
/**
|
|
10
11
|
* Get a random integer
|
|
12
|
+
*
|
|
11
13
|
* @param minimum Minimum value
|
|
12
14
|
* @param maximum Maximum value
|
|
13
15
|
* @returns Random integer
|
|
14
16
|
*/
|
|
15
17
|
declare function getRandomInteger(minimum?: number, maximum?: number): number;
|
|
16
18
|
//#endregion
|
|
17
|
-
export {
|
|
19
|
+
export { getRandomFloatingNumber, getRandomInteger };
|
package/dist/internal/random.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isNumber } from "./is.mjs";
|
|
2
2
|
//#region src/internal/random.ts
|
|
3
|
-
function
|
|
3
|
+
function getRandomFloatingNumberValue(inclusive, minimum, maximum) {
|
|
4
4
|
let maxFloat = isNumber(maximum) && maximum <= Number.MAX_SAFE_INTEGER ? maximum : Number.MAX_SAFE_INTEGER;
|
|
5
5
|
let minFloat = isNumber(minimum) && minimum >= Number.MIN_SAFE_INTEGER ? minimum : Number.MIN_SAFE_INTEGER;
|
|
6
6
|
if (minFloat === maxFloat) return minFloat;
|
|
@@ -9,21 +9,23 @@ function _getRandomFloat(inclusive, minimum, maximum) {
|
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Get a random floating-point number
|
|
12
|
+
*
|
|
12
13
|
* @param minimum Minimum value
|
|
13
14
|
* @param maximum Maximum value
|
|
14
15
|
* @returns Random floating-point number
|
|
15
16
|
*/
|
|
16
|
-
function
|
|
17
|
-
return
|
|
17
|
+
function getRandomFloatingNumber(minimum, maximum) {
|
|
18
|
+
return getRandomFloatingNumberValue(false, minimum, maximum);
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
21
|
* Get a random integer
|
|
22
|
+
*
|
|
21
23
|
* @param minimum Minimum value
|
|
22
24
|
* @param maximum Maximum value
|
|
23
25
|
* @returns Random integer
|
|
24
26
|
*/
|
|
25
27
|
function getRandomInteger(minimum, maximum) {
|
|
26
|
-
return Math.floor(
|
|
28
|
+
return Math.floor(getRandomFloatingNumberValue(true, minimum, maximum));
|
|
27
29
|
}
|
|
28
30
|
//#endregion
|
|
29
|
-
export {
|
|
31
|
+
export { getRandomFloatingNumber, getRandomInteger };
|
|
@@ -2,39 +2,45 @@ import { Err, ExtendedErr, Ok, Result } from "../result/models.mjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/internal/result.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* Is the
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
5
|
+
* Is the _Result_ an extended error?
|
|
6
|
+
*
|
|
7
|
+
* @param result _Result_ to check
|
|
8
|
+
* @returns `true` if the _Result_ is an extended error, `false` otherwise
|
|
8
9
|
*/
|
|
9
10
|
declare function isError<Value, E = Error>(result: ExtendedErr<E> | Result<Value, E>, extended: true): result is ExtendedErr<E>;
|
|
10
11
|
/**
|
|
11
|
-
* Is the
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
12
|
+
* Is the _Result_ an error?
|
|
13
|
+
*
|
|
14
|
+
* @param result _Result_ to check
|
|
15
|
+
* @returns `true` if the _Result_ is an error, `false` otherwise
|
|
14
16
|
*/
|
|
15
17
|
declare function isError<Value, E = Error>(result: Result<Value, E>): result is Err<E>;
|
|
16
18
|
/**
|
|
17
19
|
* Is the value an error?
|
|
20
|
+
*
|
|
18
21
|
* @param value Value to check
|
|
19
22
|
* @returns `true` if the value is an error, `false` otherwise
|
|
20
23
|
*/
|
|
21
24
|
declare function isError(value: unknown): value is Err<unknown> | ExtendedErr<unknown>;
|
|
22
25
|
/**
|
|
23
|
-
* Is the
|
|
24
|
-
*
|
|
25
|
-
* @
|
|
26
|
+
* Is the _Result_ ok?
|
|
27
|
+
*
|
|
28
|
+
* @param value _Result_ to check
|
|
29
|
+
* @returns `true` if the _Result_ is ok, `false` otherwise
|
|
26
30
|
*/
|
|
27
31
|
declare function isOk<Value, E = Error>(value: Result<Value, E>): value is Ok<Value>;
|
|
28
32
|
/**
|
|
29
33
|
* Is the value ok?
|
|
34
|
+
*
|
|
30
35
|
* @param value Value to check
|
|
31
36
|
* @returns `true` if the value is ok, `false` otherwise
|
|
32
37
|
*/
|
|
33
38
|
declare function isOk(value: unknown): value is Ok<unknown>;
|
|
34
39
|
/**
|
|
35
|
-
* Is the value a
|
|
40
|
+
* Is the value a _Result_?
|
|
41
|
+
*
|
|
36
42
|
* @param value Value to check
|
|
37
|
-
* @returns `true` if the value is a
|
|
43
|
+
* @returns `true` if the value is a _Result_, `false` otherwise
|
|
38
44
|
*/
|
|
39
45
|
declare function isResult(value: unknown): value is ExtendedErr<unknown> | Result<unknown, unknown>;
|
|
40
46
|
//#endregion
|
package/dist/internal/result.mjs
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
import { isNonPlainObject } from "./is.mjs";
|
|
2
2
|
//#region src/internal/result.ts
|
|
3
|
-
function _isResult(value, okValue) {
|
|
4
|
-
if (isNonPlainObject(value)) return false;
|
|
5
|
-
return value.ok === okValue && (okValue ? PROPERTY_VALUE : PROPERTY_ERROR) in value;
|
|
6
|
-
}
|
|
7
3
|
function isError(value, extended) {
|
|
8
|
-
return
|
|
4
|
+
return isResultValue(value, false) && (extended === true ? value.original instanceof Error : true);
|
|
9
5
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Is the result ok?
|
|
12
|
-
* @param result Result to check
|
|
13
|
-
* @returns `true` if the result is ok, `false` otherwise
|
|
14
|
-
*/
|
|
15
6
|
function isOk(value) {
|
|
16
|
-
return
|
|
7
|
+
return isResultValue(value, true);
|
|
17
8
|
}
|
|
18
9
|
/**
|
|
19
|
-
* Is the value a
|
|
10
|
+
* Is the value a _Result_?
|
|
11
|
+
*
|
|
20
12
|
* @param value Value to check
|
|
21
|
-
* @returns `true` if the value is a
|
|
13
|
+
* @returns `true` if the value is a _Result_, `false` otherwise
|
|
22
14
|
*/
|
|
23
15
|
function isResult(value) {
|
|
24
|
-
return
|
|
16
|
+
return isResultValue(value, true) || isResultValue(value, false);
|
|
17
|
+
}
|
|
18
|
+
function isResultValue(value, okValue) {
|
|
19
|
+
if (isNonPlainObject(value)) return false;
|
|
20
|
+
return value.ok === okValue && (okValue ? PROPERTY_VALUE : PROPERTY_ERROR) in value;
|
|
25
21
|
}
|
|
26
22
|
const PROPERTY_ERROR = "error";
|
|
27
23
|
const PROPERTY_VALUE = "value";
|