@oscarpalmer/atoms 0.193.0 → 0.193.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/package.json +3 -4
  2. package/src/array/difference.ts +0 -73
  3. package/src/array/exists.ts +0 -93
  4. package/src/array/filter.ts +0 -182
  5. package/src/array/find.ts +0 -183
  6. package/src/array/first.ts +0 -196
  7. package/src/array/flatten.ts +0 -20
  8. package/src/array/from.ts +0 -129
  9. package/src/array/get.ts +0 -131
  10. package/src/array/group-by.ts +0 -369
  11. package/src/array/index.ts +0 -26
  12. package/src/array/insert.ts +0 -52
  13. package/src/array/intersection.ts +0 -72
  14. package/src/array/last.ts +0 -194
  15. package/src/array/match.ts +0 -436
  16. package/src/array/move.ts +0 -315
  17. package/src/array/partition.ts +0 -91
  18. package/src/array/push.ts +0 -23
  19. package/src/array/reverse.ts +0 -33
  20. package/src/array/select.ts +0 -260
  21. package/src/array/single.ts +0 -93
  22. package/src/array/slice.ts +0 -335
  23. package/src/array/sort.ts +0 -607
  24. package/src/array/splice.ts +0 -106
  25. package/src/array/swap.ts +0 -322
  26. package/src/array/to-map.ts +0 -371
  27. package/src/array/to-record.ts +0 -351
  28. package/src/array/to-set.ts +0 -80
  29. package/src/array/toggle.ts +0 -79
  30. package/src/array/union.ts +0 -72
  31. package/src/array/unique.ts +0 -67
  32. package/src/array/update.ts +0 -75
  33. package/src/beacon.ts +0 -378
  34. package/src/color/constants.ts +0 -137
  35. package/src/color/index.ts +0 -83
  36. package/src/color/instance.ts +0 -162
  37. package/src/color/misc/alpha.ts +0 -56
  38. package/src/color/misc/format.ts +0 -29
  39. package/src/color/misc/get.ts +0 -210
  40. package/src/color/misc/is.ts +0 -221
  41. package/src/color/misc/state.ts +0 -243
  42. package/src/color/models.ts +0 -389
  43. package/src/color/space/hex.ts +0 -184
  44. package/src/color/space/hsl.ts +0 -174
  45. package/src/color/space/hwb.ts +0 -153
  46. package/src/color/space/rgb.ts +0 -240
  47. package/src/function/assert.ts +0 -174
  48. package/src/function/index.ts +0 -2
  49. package/src/function/limit.ts +0 -83
  50. package/src/function/memoize.ts +0 -202
  51. package/src/function/once.ts +0 -200
  52. package/src/function/retry.ts +0 -175
  53. package/src/function/work.ts +0 -1007
  54. package/src/herald.ts +0 -216
  55. package/src/index.ts +0 -68
  56. package/src/internal/array/callbacks.ts +0 -46
  57. package/src/internal/array/chunk.ts +0 -51
  58. package/src/internal/array/compact.ts +0 -56
  59. package/src/internal/array/find.ts +0 -200
  60. package/src/internal/array/group.ts +0 -42
  61. package/src/internal/array/index-of.ts +0 -182
  62. package/src/internal/array/insert.ts +0 -80
  63. package/src/internal/array/overlap.ts +0 -35
  64. package/src/internal/array/sets.ts +0 -74
  65. package/src/internal/array/shuffle.ts +0 -33
  66. package/src/internal/array/update.ts +0 -52
  67. package/src/internal/function/misc.ts +0 -8
  68. package/src/internal/function/timer.ts +0 -168
  69. package/src/internal/is.ts +0 -244
  70. package/src/internal/math/aggregate.ts +0 -164
  71. package/src/internal/math/misc.ts +0 -28
  72. package/src/internal/number.ts +0 -129
  73. package/src/internal/random.ts +0 -49
  74. package/src/internal/result.ts +0 -92
  75. package/src/internal/sized.ts +0 -25
  76. package/src/internal/string.ts +0 -128
  77. package/src/internal/subscription.ts +0 -264
  78. package/src/internal/value/compare.ts +0 -170
  79. package/src/internal/value/equal.ts +0 -465
  80. package/src/internal/value/get.ts +0 -57
  81. package/src/internal/value/handlers.ts +0 -95
  82. package/src/internal/value/has.ts +0 -118
  83. package/src/internal/value/misc.ts +0 -125
  84. package/src/internal/value/partial.ts +0 -46
  85. package/src/internal/value/set.ts +0 -132
  86. package/src/is.ts +0 -182
  87. package/src/logger.ts +0 -230
  88. package/src/math.ts +0 -281
  89. package/src/models.ts +0 -286
  90. package/src/number.ts +0 -1
  91. package/src/promise/delay.ts +0 -62
  92. package/src/promise/helpers.ts +0 -96
  93. package/src/promise/index.ts +0 -300
  94. package/src/promise/misc.ts +0 -96
  95. package/src/promise/models.ts +0 -195
  96. package/src/promise/timed.ts +0 -91
  97. package/src/query.ts +0 -147
  98. package/src/queue.ts +0 -814
  99. package/src/random.ts +0 -125
  100. package/src/result/index.ts +0 -105
  101. package/src/result/match.ts +0 -124
  102. package/src/result/misc.ts +0 -129
  103. package/src/result/models.ts +0 -83
  104. package/src/result/work/flow.ts +0 -488
  105. package/src/result/work/pipe.ts +0 -496
  106. package/src/sized/map.ts +0 -110
  107. package/src/sized/set.ts +0 -107
  108. package/src/string/case.ts +0 -236
  109. package/src/string/fuzzy.ts +0 -444
  110. package/src/string/index.ts +0 -199
  111. package/src/string/match.ts +0 -80
  112. package/src/string/normalize.ts +0 -205
  113. package/src/string/template.ts +0 -161
  114. package/src/value/clone.ts +0 -319
  115. package/src/value/collection.ts +0 -63
  116. package/src/value/diff.ts +0 -232
  117. package/src/value/freeze.ts +0 -322
  118. package/src/value/handle.ts +0 -3
  119. package/src/value/index.ts +0 -5
  120. package/src/value/merge.ts +0 -278
  121. package/src/value/omit.ts +0 -20
  122. package/src/value/pick.ts +0 -20
  123. package/src/value/shake.ts +0 -45
  124. package/src/value/smush.ts +0 -89
  125. package/src/value/transform.ts +0 -153
  126. package/src/value/unsmush.ts +0 -84
@@ -1,244 +0,0 @@
1
- import type {
2
- ArrayOrPlainObject,
3
- Constructor,
4
- Key,
5
- PlainObject,
6
- Primitive,
7
- TypedArray,
8
- } from '../models';
9
-
10
- // #region Functions
11
-
12
- /**
13
- * Is the value an array or a plain object?
14
- *
15
- * @param value Value to check
16
- * @returns `true` if the value is an array or a plain object, otherwise `false`
17
- */
18
- export function isArrayOrPlainObject(value: unknown): value is ArrayOrPlainObject {
19
- return Array.isArray(value) || isPlainObject(value);
20
- }
21
-
22
- /**
23
- * Is the value a constructor function?
24
- *
25
- * @param value Value to check
26
- * @returns `true` if the value is a constructor function, otherwise `false`
27
- */
28
- export function isConstructor(value: unknown): value is Constructor {
29
- return typeof value === 'function' && value.prototype?.constructor === value;
30
- }
31
-
32
- /**
33
- * Is the value an instance of the constructor?
34
- *
35
- * @param constructor Class constructor
36
- * @param value Value to check
37
- * @returns `true` if the value is an instance of the constructor, otherwise `false`
38
- */
39
- export function isInstanceOf<Instance>(
40
- constructor: Constructor<Instance>,
41
- value: unknown,
42
- ): value is Instance {
43
- return isConstructor(constructor) && value instanceof constructor;
44
- }
45
-
46
- /**
47
- * Is the value a _Key_?
48
- *
49
- * @param value Value to check
50
- * @returns `true` if the value is a _Key_ _(`number` or `string`)_, otherwise `false`
51
- */
52
- export function isKey(value: unknown): value is Key {
53
- return typeof value === 'number' || typeof value === 'string';
54
- }
55
-
56
- /**
57
- * Is the value not an array or a plain object?
58
- *
59
- * @param value Value to check
60
- * @returns `true` if the value is not an array or a plain object, otherwise `false`
61
- */
62
- export function isNonArrayOrPlainObject<Value>(
63
- value: Value,
64
- ): value is Exclude<Value, ArrayOrPlainObject> {
65
- return !isArrayOrPlainObject(value);
66
- }
67
-
68
- /**
69
- * Is the value not a constructor function?
70
- *
71
- * @param value Value to check
72
- * @returns `true` if the value is not a constructor function, otherwise `false`
73
- */
74
- export function isNonConstructor<Value>(value: Value): value is Exclude<Value, Constructor> {
75
- return !isConstructor(value);
76
- }
77
-
78
- /**
79
- * Is the value not an instance of the constructor?
80
- *
81
- * @param constructor Class constructor
82
- * @param value Value to check
83
- * @returns `true` if the value is not an instance of the constructor, otherwise `false`
84
- */
85
- export function isNonInstanceOf<Instance, Value>(
86
- constructor: Constructor<Instance>,
87
- value: Value,
88
- ): value is Exclude<Value, Instance> {
89
- return !isInstanceOf(constructor, value);
90
- }
91
-
92
- /**
93
- * Is the value not a _Key_?
94
- *
95
- * @param value Value to check
96
- * @returns `true` if the value is not a _Key_ _(`number` or `string`)_, otherwise `false`
97
- */
98
- export function isNonKey<Value>(value: Value): value is Exclude<Value, Key> {
99
- return !isKey(value);
100
- }
101
-
102
- /**
103
- * Is the value not a number?
104
- *
105
- * @param value Value to check
106
- * @returns `true` if the value is not a `number`, otherwise `false`
107
- */
108
- export function isNonNumber<Value>(value: Value): value is Exclude<Value, number> {
109
- return !isNumber(value);
110
- }
111
-
112
- /**
113
- * Is the value not a plain object?
114
- *
115
- * @param value Value to check
116
- * @returns `true` if the value is not a plain object, otherwise `false`
117
- */
118
- export function isNonPlainObject<Value>(value: Value): value is Exclude<Value, PlainObject> {
119
- return !isPlainObject(value);
120
- }
121
-
122
- /**
123
- * Is the value not a primitive value?
124
- *
125
- * @param value Value to check
126
- * @returns `true` if the value is not a primitive value, otherwise `false`
127
- */
128
- export function isNonPrimitive<Value>(value: Value): value is Exclude<Value, Primitive> {
129
- return !isPrimitive(value);
130
- }
131
-
132
- /**
133
- * Is the value not a template strings array?
134
- *
135
- * @param value Value to check
136
- * @returns `true` if the value is not a `TemplateStringsArray`, otherwise `false`
137
- */
138
- export function isNonTemplateStringsArray<Value>(
139
- value: Value,
140
- ): value is Exclude<Value, TemplateStringsArray> {
141
- return !isTemplateStringsArray(value);
142
- }
143
-
144
- /**
145
- * Is the value not a typed array?
146
- *
147
- * @param value Value to check
148
- * @returns `true` if the value is not a typed array, otherwise `false`
149
- */
150
- export function isNonTypedArray<Value>(value: Value): value is Exclude<Value, TypedArray> {
151
- return !isTypedArray(value);
152
- }
153
-
154
- /**
155
- * Is the value a number?
156
- *
157
- * @param value Value to check
158
- * @returns `true` if the value is a `number`, otherwise `false`
159
- */
160
- export function isNumber(value: unknown): value is number {
161
- return typeof value === 'number' && !Number.isNaN(value);
162
- }
163
-
164
- /**
165
- * Is the value a plain object?
166
- *
167
- * @param value Value to check
168
- * @returns `true` if the value is a plain object, otherwise `false`
169
- */
170
- export function isPlainObject(value: unknown): value is PlainObject {
171
- if (value === null || typeof value !== 'object') {
172
- return false;
173
- }
174
-
175
- if (Symbol.toStringTag in value || Symbol.iterator in value) {
176
- return false;
177
- }
178
-
179
- const prototype = Object.getPrototypeOf(value);
180
-
181
- return (
182
- prototype === null ||
183
- prototype === Object.prototype ||
184
- Object.getPrototypeOf(prototype) === null
185
- );
186
- }
187
-
188
- /**
189
- * Is the value a primitive value?
190
- *
191
- * @param value Value to check
192
- * @returns `true` if the value is a primitive value, otherwise `false`
193
- */
194
- export function isPrimitive(value: unknown): value is Primitive {
195
- if (value == null) {
196
- return true;
197
- }
198
-
199
- const type = typeof value;
200
-
201
- return (
202
- type === 'bigint' ||
203
- type === 'boolean' ||
204
- type === 'number' ||
205
- type === 'string' ||
206
- type === 'symbol'
207
- );
208
- }
209
-
210
- /**
211
- * Is the value a template strings array?
212
- *
213
- * @param value Value to check
214
- * @returns `true` if the value is a `TemplateStringsArray`, otherwise `false`
215
- */
216
- export function isTemplateStringsArray(value: unknown): value is TemplateStringsArray {
217
- return Array.isArray(value) && Array.isArray((value as unknown as TemplateStringsArray).raw);
218
- }
219
-
220
- /**
221
- * Is the value a typed array?
222
- *
223
- * @param value Value to check
224
- * @returns `true` if the value is a typed array, otherwise `false`
225
- */
226
- export function isTypedArray(value: unknown): value is TypedArray {
227
- (isTypedArray as any).types ??= new Set<unknown>([
228
- Int8Array,
229
- Uint8Array,
230
- Uint8ClampedArray,
231
- Int16Array,
232
- Uint16Array,
233
- Int32Array,
234
- Uint32Array,
235
- Float32Array,
236
- Float64Array,
237
- BigInt64Array,
238
- BigUint64Array,
239
- ]);
240
-
241
- return (isTypedArray as any).types.has((value as TypedArray)?.constructor);
242
- }
243
-
244
- // #endregion
@@ -1,164 +0,0 @@
1
- import type {NumericalValues, PlainObject} from '../../models';
2
- import {isNonNumber} from '../is';
3
-
4
- // #region Types
5
-
6
- type Aggregation = {
7
- count: number;
8
- value: number;
9
- };
10
-
11
- type AggregationCallback = (current: number, value: number, notNumber: boolean) => number;
12
-
13
- export type AggregationType = 'average' | 'max' | 'min' | 'sum';
14
-
15
- type NonAverageAggregationType = 'max' | 'min' | 'sum';
16
-
17
- // #endregion
18
-
19
- // #region Functions
20
-
21
- export function aggregate(type: AggregationType, array: unknown[], key: unknown): Aggregation {
22
- const length = Array.isArray(array) ? array.length : 0;
23
-
24
- if (length === 0) {
25
- return {
26
- count: 0,
27
- value: Number.NaN,
28
- };
29
- }
30
-
31
- const aggregator = aggregators[type];
32
- const callback = getAggregateCallback(key);
33
-
34
- let counted = 0;
35
- let aggregated = Number.NaN;
36
- let notNumber = true;
37
-
38
- for (let index = 0; index < length; index += 1) {
39
- const item = array[index];
40
-
41
- const value = callback == null ? item : callback(item as never, index, array);
42
-
43
- if (isNonNumber(value)) {
44
- continue;
45
- }
46
-
47
- aggregated = aggregator(aggregated, value, notNumber);
48
-
49
- counted += 1;
50
- notNumber = false;
51
- }
52
-
53
- return {
54
- count: counted,
55
- value: aggregated,
56
- };
57
- }
58
-
59
- export function getAggregateCallback(key: unknown): Function | undefined {
60
- if (key == null) {
61
- return;
62
- }
63
-
64
- return typeof key === 'function' ? key : (item: PlainObject): unknown => item[key as never];
65
- }
66
-
67
- /**
68
- * Get the maximum value from a list of items
69
- *
70
- * @example
71
- * ```typescript
72
- * max(
73
- * [{id: 1, value: 10}, {id: 2, value: 20}],
74
- * item => item.value,
75
- * ); // => 20
76
- *
77
- * max([], item => item.value); // => Number.NaN
78
- * ```
79
- *
80
- * @param items List of items
81
- * @param callback Callback to get an item's value
82
- * @returns Maximum value, or `Number.NaN` if no maximum can be found
83
- */
84
- export function max<Item>(
85
- items: Item[],
86
- callback: (item: Item, index: number, array: Item[]) => number,
87
- ): number;
88
-
89
- /**
90
- * Get the maximum value from a list of items
91
- *
92
- * @example
93
- * ```typescript
94
- * max(
95
- * [{id: 1, value: 10}, {id: 2, value: 20}],
96
- * 'value',
97
- * ); // => 20
98
- *
99
- * max([], 'value'); // => Number.NaN
100
- * ```
101
- *
102
- * @param items List of items
103
- * @param key Key to use for value
104
- * @returns Maximum value, or `Number.NaN` if no maximum can be found
105
- */
106
- export function max<Item extends PlainObject, ItemKey extends keyof NumericalValues<Item>>(
107
- items: Item[],
108
- key: ItemKey,
109
- ): number;
110
-
111
- /**
112
- * Get the maximum value from a list of numbers
113
- *
114
- * @example
115
- * ```typescript
116
- * max([10, 20]); // => 20
117
- * max([]); // => Number.NaN
118
- * ```
119
- *
120
- * @param values List of numbers
121
- * @returns Maximum value, or `Number.NaN` if no maximum can be found
122
- */
123
- export function max(values: number[]): number;
124
-
125
- export function max(array: unknown[], key?: unknown): number {
126
- return getAggregated(AGGREGATION_MAX as NonAverageAggregationType, array, key);
127
- }
128
-
129
- function calculateSum(current: number, value: number, notNumber: boolean): number {
130
- return notNumber ? value : current + value;
131
- }
132
-
133
- export function getAggregated(
134
- type: NonAverageAggregationType,
135
- array: unknown[],
136
- key?: unknown,
137
- ): number {
138
- const aggregated = aggregate(type, array, key);
139
-
140
- return aggregated.count > 0 ? aggregated.value : Number.NaN;
141
- }
142
-
143
- // #endregion
144
-
145
- // #region Variables
146
-
147
- export const AGGREGATION_AVERAGE: AggregationType = 'average';
148
-
149
- export const AGGREGATION_MAX = 'max';
150
-
151
- export const AGGREGATION_MIN = 'min';
152
-
153
- export const AGGREGATION_SUM = 'sum';
154
-
155
- const aggregators: Record<AggregationType, AggregationCallback> = {
156
- average: calculateSum,
157
- max: (current: number, value: number, notNumber: boolean) =>
158
- notNumber || value > current ? value : current,
159
- min: (current: number, value: number, notNumber: boolean) =>
160
- notNumber || value < current ? value : current,
161
- sum: calculateSum,
162
- };
163
-
164
- // #endregion
@@ -1,28 +0,0 @@
1
- /**
2
- * Round a number
3
- *
4
- * @param value Number to round
5
- * @param decimals Number of decimal places to round to _(defaults to `0`)_
6
- * @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
7
- */
8
- export function round(value: number, decimals?: number): number {
9
- return roundNumber(Math.round, value, decimals);
10
- }
11
-
12
- export function roundNumber(
13
- callback: (value: number) => number,
14
- value: number,
15
- decimals?: number,
16
- ): number {
17
- if (typeof value !== 'number') {
18
- return Number.NaN;
19
- }
20
-
21
- if (typeof decimals !== 'number' || decimals < 1) {
22
- return callback(value);
23
- }
24
-
25
- const mod = 10 ** decimals;
26
-
27
- return callback((value + Number.EPSILON) * mod) / mod;
28
- }
@@ -1,129 +0,0 @@
1
- import {isNumber} from './is';
2
-
3
- // #region Functions
4
-
5
- /**
6
- * Is the number between a minimum and maximum value?
7
- *
8
- * @param value Value to check
9
- * @param minimum Minimum value
10
- * @param maximum Maximum value
11
- * @returns `true` if the value is between the minimum and maximum, otherwise `false`
12
- */
13
- export function between(value: number, minimum: number, maximum: number): boolean {
14
- if (![value, minimum, maximum].every(isNumber)) {
15
- return false;
16
- }
17
-
18
- if (Object.is(minimum, maximum)) {
19
- return Object.is(value, minimum);
20
- }
21
-
22
- const max = maximum > minimum ? maximum : minimum;
23
- const min = maximum > minimum ? minimum : maximum;
24
-
25
- return value >= min && value <= max;
26
- }
27
-
28
- /**
29
- * Clamp a number between a minimum and maximum value
30
- *
31
- * @param value Value to clamp
32
- * @param minimum Minimum value
33
- * @param maximum Maximum value
34
- * @param loop If `true`, the value will loop around when smaller than the minimum or larger than the maximum _(defaults to `false`)_
35
- * @returns Clamped value
36
- *
37
- * @example
38
- * ```typescript
39
- * clamp(10, 0, 5); // => 5
40
- * clamp(10, 0, 5, true); // => 0
41
- * ```
42
- */
43
- export function clamp(value: number, minimum: number, maximum: number, loop?: boolean): number {
44
- if (![value, minimum, maximum].every(isNumber)) {
45
- return Number.NaN;
46
- }
47
-
48
- if (value < minimum) {
49
- return loop === true ? maximum : minimum;
50
- }
51
-
52
- const next = loop === true ? minimum : maximum;
53
-
54
- return value > maximum ? next : value;
55
- }
56
-
57
- /**
58
- * Get the number value from an unknown value
59
- *
60
- * _(Based on Lodash)_
61
- *
62
- * @param value Original value
63
- * @returns Original value as a number, or `Number.NaN` if the value is unable to be parsed
64
- */
65
- export function getNumber(value: unknown): number {
66
- if (typeof value === 'number') {
67
- return value;
68
- }
69
-
70
- if (typeof value === 'bigint' || typeof value === 'boolean') {
71
- return Number(value);
72
- }
73
-
74
- if (value == null || typeof value === 'symbol') {
75
- return Number.NaN;
76
- }
77
-
78
- if (typeof value === 'function') {
79
- return getNumber(value());
80
- }
81
-
82
- let parsed = value.valueOf();
83
-
84
- if (typeof parsed === 'object') {
85
- parsed = parsed.toString();
86
- }
87
-
88
- if (typeof parsed !== 'string') {
89
- return getNumber(parsed);
90
- }
91
-
92
- const trimmed = parsed.trim();
93
-
94
- if (trimmed.length === 0) {
95
- return Number.NaN;
96
- }
97
-
98
- if (EXPRESSION_ZEROISH.test(parsed)) {
99
- return 0;
100
- }
101
-
102
- const isBinary = EXPRESSION_BINARY.test(trimmed);
103
-
104
- if (isBinary || EXPRESSION_OCTAL.test(trimmed)) {
105
- return Number.parseInt(trimmed.slice(2), isBinary ? 2 : OCTAL_VALUE);
106
- }
107
-
108
- return Number(trimmed);
109
- }
110
-
111
- export function getNumberOrDefault(value: unknown, defaultValue: number, minimum?: number): number {
112
- return typeof value === 'number' && !Number.isNaN(value) && value >= (minimum ?? 0)
113
- ? Math.floor(value)
114
- : defaultValue;
115
- }
116
-
117
- // #endregion
118
-
119
- // #region Variables
120
-
121
- const EXPRESSION_BINARY = /^0b[01]+$/i;
122
-
123
- const EXPRESSION_OCTAL = /^0o[0-7]+$/i;
124
-
125
- const EXPRESSION_ZEROISH = /^\s*0+\s*$/;
126
-
127
- const OCTAL_VALUE = 8;
128
-
129
- // #endregion
@@ -1,49 +0,0 @@
1
- import {isNumber} from './is';
2
-
3
- // #region Functions
4
-
5
- function getRandomFloatingNumberValue(
6
- inclusive: boolean,
7
- minimum?: number,
8
- maximum?: number,
9
- ): number {
10
- let maxFloat =
11
- isNumber(maximum) && maximum <= Number.MAX_SAFE_INTEGER ? maximum : Number.MAX_SAFE_INTEGER;
12
-
13
- let minFloat =
14
- isNumber(minimum) && minimum >= Number.MIN_SAFE_INTEGER ? minimum : Number.MIN_SAFE_INTEGER;
15
-
16
- if (minFloat === maxFloat) {
17
- return minFloat;
18
- }
19
-
20
- if (minFloat > maxFloat) {
21
- [minFloat, maxFloat] = [maxFloat, minFloat];
22
- }
23
-
24
- return Math.random() * (maxFloat + (inclusive ? 1 : 0) - minFloat) + minFloat;
25
- }
26
-
27
- /**
28
- * Get a random floating-point number
29
- *
30
- * @param minimum Minimum value
31
- * @param maximum Maximum value
32
- * @returns Random floating-point number
33
- */
34
- export function getRandomFloatingNumber(minimum?: number, maximum?: number): number {
35
- return getRandomFloatingNumberValue(false, minimum, maximum);
36
- }
37
-
38
- /**
39
- * Get a random integer
40
- *
41
- * @param minimum Minimum value
42
- * @param maximum Maximum value
43
- * @returns Random integer
44
- */
45
- export function getRandomInteger(minimum?: number, maximum?: number): number {
46
- return Math.floor(getRandomFloatingNumberValue(true, minimum, maximum));
47
- }
48
-
49
- // #endregion
@@ -1,92 +0,0 @@
1
- import type {PlainObject} from '../models';
2
- import type {Err, ExtendedErr, Ok, Result} from '../result/models';
3
- import {isNonPlainObject} from './is';
4
-
5
- // #region Functions
6
-
7
- /**
8
- * Is the _Result_ an extended error?
9
- *
10
- * @param result _Result_ to check
11
- * @returns `true` if the _Result_ is an extended error, otherwise `false`
12
- */
13
- export function isError<Value, E = Error>(
14
- result: ExtendedErr<E> | Result<Value, E>,
15
- extended: true,
16
- ): result is ExtendedErr<E>;
17
-
18
- /**
19
- * Is the _Result_ an error?
20
- *
21
- * @param result _Result_ to check
22
- * @returns `true` if the _Result_ is an error, otherwise `false`
23
- */
24
- export function isError<Value, E = Error>(result: Result<Value, E>): result is Err<E>;
25
-
26
- /**
27
- * Is the value an error?
28
- *
29
- * @param value Value to check
30
- * @returns `true` if the value is an error, otherwise `false`
31
- */
32
- export function isError(value: unknown): value is Err<unknown> | ExtendedErr<unknown>;
33
-
34
- export function isError(
35
- value: unknown,
36
- extended?: boolean,
37
- ): value is Err<unknown> | ExtendedErr<unknown> {
38
- return (
39
- isResultValue(value, false) &&
40
- (extended === true ? (value as ExtendedErr<unknown>).original instanceof Error : true)
41
- );
42
- }
43
-
44
- /**
45
- * Is the _Result_ ok?
46
- *
47
- * @param value _Result_ to check
48
- * @returns `true` if the _Result_ is ok, otherwise `false`
49
- */
50
- export function isOk<Value, E = Error>(value: Result<Value, E>): value is Ok<Value>;
51
-
52
- /**
53
- * Is the value ok?
54
- *
55
- * @param value Value to check
56
- * @returns `true` if the value is ok, otherwise `false`
57
- */
58
- export function isOk(value: unknown): value is Ok<unknown>;
59
-
60
- export function isOk(value: unknown): value is Ok<unknown> {
61
- return isResultValue(value, true);
62
- }
63
-
64
- /**
65
- * Is the value a _Result_?
66
- *
67
- * @param value Value to check
68
- * @returns `true` if the value is a _Result_, otherwise `false`
69
- */
70
- export function isResult(value: unknown): value is ExtendedErr<unknown> | Result<unknown, unknown> {
71
- return isResultValue(value, true) || isResultValue(value, false);
72
- }
73
-
74
- function isResultValue(value: unknown, okValue: boolean): value is Result<unknown, unknown> {
75
- if (isNonPlainObject(value)) {
76
- return false;
77
- }
78
-
79
- return (
80
- (value as PlainObject).ok === okValue && (okValue ? PROPERTY_VALUE : PROPERTY_ERROR) in value
81
- );
82
- }
83
-
84
- // #endregion
85
-
86
- // #region Variable
87
-
88
- const PROPERTY_ERROR = 'error';
89
-
90
- const PROPERTY_VALUE = 'value';
91
-
92
- // #endregion