@oscarpalmer/atoms 0.176.0 → 0.177.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/index.mjs CHANGED
@@ -16,26 +16,34 @@ function getArrayCallbacks(bool, key, value) {
16
16
  }
17
17
  //#endregion
18
18
  //#region src/internal/array/find.ts
19
- function findValue(type, array, parameters) {
19
+ function findValue(type, array, parameters, reversed) {
20
20
  const findIndex = type === FIND_VALUE_INDEX;
21
21
  if (!Array.isArray(array) || array.length === 0) return findIndex ? -1 : void 0;
22
- const { bool, key, value } = getParameters(parameters);
22
+ const { bool, key, value } = getFindParameters(parameters);
23
23
  const callbacks = getArrayCallbacks(bool, key);
24
24
  if (callbacks?.bool == null && callbacks?.keyed == null) return findIndex ? array.indexOf(value) : array.find((item) => Object.is(item, value));
25
25
  if (callbacks.bool != null) {
26
26
  const index = array.findIndex(callbacks.bool);
27
27
  return findIndex ? index : array[index];
28
28
  }
29
- return findValueInArray(array, callbacks.keyed, value, findIndex);
29
+ return findValueInArray(array, callbacks.keyed, value, findIndex, reversed);
30
30
  }
31
- function findValueInArray(array, callback, value, findIndex) {
31
+ function findValueInArray(array, callback, value, findIndex, reversed) {
32
32
  const { length } = array;
33
33
  for (let index = 0; index < length; index += 1) {
34
- const item = array[index];
34
+ const item = reversed ? array.at(-(index + 1)) : array[index];
35
35
  if (Object.is(callback?.(item, index, array), value)) return findIndex ? index : item;
36
36
  }
37
37
  return findIndex ? -1 : void 0;
38
38
  }
39
+ function findAbsoluteValueOrDefault(array, parameters, defaultValue, useDefaultValue, reversed) {
40
+ if (parameters.length === 0) {
41
+ if (Array.isArray(array) && array.length > 0) return reversed ? array.at(-1) : array[0];
42
+ return useDefaultValue ? defaultValue : void 0;
43
+ }
44
+ const index = findValue(FIND_VALUE_INDEX, array, parameters, reversed);
45
+ return index > -1 ? array[index] : useDefaultValue ? defaultValue : void 0;
46
+ }
39
47
  function findValues(type, array, parameters, mapper) {
40
48
  const result = {
41
49
  matched: [],
@@ -43,13 +51,13 @@ function findValues(type, array, parameters, mapper) {
43
51
  };
44
52
  if (!Array.isArray(array) || array.length === 0) return result;
45
53
  const { length } = array;
46
- const { bool, key, value } = getParameters(parameters);
54
+ const { bool, key, value } = getFindParameters(parameters);
47
55
  const callbacks = getArrayCallbacks(bool, key);
48
56
  if (type === "unique" && callbacks?.keyed == null && length >= UNIQUE_THRESHOLD) {
49
57
  result.matched = [...new Set(array)];
50
58
  return result;
51
59
  }
52
- const mapCallback = typeof mapper === "function" ? mapper : void 0;
60
+ const mapCallback = getArrayCallback(mapper);
53
61
  if (callbacks?.bool != null || type === "all" && key == null) {
54
62
  const callback = callbacks?.bool ?? ((item) => Object.is(item, value));
55
63
  for (let index = 0; index < length; index += 1) {
@@ -70,7 +78,7 @@ function findValues(type, array, parameters, mapper) {
70
78
  }
71
79
  return result;
72
80
  }
73
- function getParameters(original) {
81
+ function getFindParameters(original) {
74
82
  const { length } = original;
75
83
  return {
76
84
  bool: length === 1 && typeof original[0] === "function" ? original[0] : void 0,
@@ -79,7 +87,7 @@ function getParameters(original) {
79
87
  };
80
88
  }
81
89
  const FIND_VALUE_INDEX = "index";
82
- const FIND_VALUE_VALUE = "value";
90
+ const FIND_VALUE_ITEM = "item";
83
91
  const FIND_VALUES_UNIQUE = "unique";
84
92
  const UNIQUE_THRESHOLD = 100;
85
93
  //#endregion
@@ -92,6 +100,15 @@ function removeFiltered(array, ...parameters) {
92
100
  return findValues("all", array, parameters).notMatched;
93
101
  }
94
102
  //#endregion
103
+ //#region src/array/first.ts
104
+ function first(array, ...parameters) {
105
+ return findAbsoluteValueOrDefault(array, parameters, void 0, false, false);
106
+ }
107
+ first.default = firstOrDefault;
108
+ function firstOrDefault(array, defaultValue, ...parameters) {
109
+ return findAbsoluteValueOrDefault(array, parameters, defaultValue, true, false);
110
+ }
111
+ //#endregion
95
112
  //#region src/internal/array/group.ts
96
113
  function groupValues(array, key, value, arrays) {
97
114
  if (!Array.isArray(array) || array.length === 0) return {};
@@ -195,6 +212,30 @@ function isInstanceOf(constructor, value) {
195
212
  function isKey(value) {
196
213
  return typeof value === "number" || typeof value === "string";
197
214
  }
215
+ function isNonArrayOrPlainObject(value) {
216
+ return !isArrayOrPlainObject(value);
217
+ }
218
+ function isNonConstructor(value) {
219
+ return !isConstructor(value);
220
+ }
221
+ function isNonInstanceOf(constructor, value) {
222
+ return !isInstanceOf(constructor, value);
223
+ }
224
+ function isNonKey(value) {
225
+ return !isKey(value);
226
+ }
227
+ function isNonNumber(value) {
228
+ return !isNumber(value);
229
+ }
230
+ function isNonPlainObject(value) {
231
+ return !isPlainObject(value);
232
+ }
233
+ function isNonPrimitive(value) {
234
+ return !isPrimitive(value);
235
+ }
236
+ function isNonTypedArray(value) {
237
+ return !isTypedArray(value);
238
+ }
198
239
  /**
199
240
  * Is the value a number?
200
241
  * @param value Value to check
@@ -220,7 +261,9 @@ function isPlainObject(value) {
220
261
  * @returns `true` if the value matches, otherwise `false`
221
262
  */
222
263
  function isPrimitive(value) {
223
- return value == null || EXPRESSION_PRIMITIVE.test(typeof value);
264
+ if (value == null) return true;
265
+ const type = typeof value;
266
+ return type === "bigint" || type === "boolean" || type === "number" || type === "string" || type === "symbol";
224
267
  }
225
268
  /**
226
269
  * Is the value a typed array?
@@ -228,7 +271,7 @@ function isPrimitive(value) {
228
271
  * @returns `true` if the value is a typed array, otherwise `false`
229
272
  */
230
273
  function isTypedArray(value) {
231
- TYPED_ARRAYS ??= new Set([
274
+ isTypedArray.types ??= new Set([
232
275
  Int8Array,
233
276
  Uint8Array,
234
277
  Uint8ClampedArray,
@@ -241,10 +284,8 @@ function isTypedArray(value) {
241
284
  BigInt64Array,
242
285
  BigUint64Array
243
286
  ]);
244
- return TYPED_ARRAYS.has(value?.constructor);
287
+ return isTypedArray.types.has(value?.constructor);
245
288
  }
246
- const EXPRESSION_PRIMITIVE = /^(bigint|boolean|number|string|symbol)$/;
247
- let TYPED_ARRAYS;
248
289
  //#endregion
249
290
  //#region src/internal/random.ts
250
291
  function _getRandomFloat(inclusive, minimum, maximum) {
@@ -329,12 +370,12 @@ function difference(first, second, key) {
329
370
  //#region src/array/exists.ts
330
371
  function exists(array, ...parameters) {
331
372
  if (parameters.length === 1 && typeof parameters[0] !== "function") return Array.isArray(array) ? array.includes(parameters[0]) : false;
332
- return findValue(FIND_VALUE_INDEX, array, parameters) > -1;
373
+ return findValue(FIND_VALUE_INDEX, array, parameters, false) > -1;
333
374
  }
334
375
  //#endregion
335
376
  //#region src/array/find.ts
336
377
  function find(array, ...parameters) {
337
- return findValue(FIND_VALUE_VALUE, array, parameters);
378
+ return findValue(FIND_VALUE_ITEM, array, parameters, false);
338
379
  }
339
380
  //#endregion
340
381
  //#region src/array/flatten.ts
@@ -496,6 +537,14 @@ function select(array, ...parameters) {
496
537
  return findValues("all", array, parameters, parameters.pop()).matched;
497
538
  }
498
539
  //#endregion
540
+ //#region src/array/single.ts
541
+ function single(array, ...parameters) {
542
+ const { matched } = findValues("all", array, parameters);
543
+ if (matched.length > 1) throw new Error(MESSAGE);
544
+ return matched[0];
545
+ }
546
+ const MESSAGE = "Multiple items were found";
547
+ //#endregion
499
548
  //#region src/array/slice.ts
500
549
  function drop(array, first, second) {
501
550
  return extract(EXTRACT_DROP, array, first, second);
@@ -606,6 +655,15 @@ function update(array, values, key) {
606
655
  return updateInArray(array, values, key, true);
607
656
  }
608
657
  //#endregion
658
+ //#region src/array/last.ts
659
+ function last(array, ...parameters) {
660
+ return findAbsoluteValueOrDefault(array, parameters, void 0, false, true);
661
+ }
662
+ last.default = lastOrDefault;
663
+ function lastOrDefault(array, defaultValue, ...parameters) {
664
+ return findAbsoluteValueOrDefault(array, parameters, defaultValue, true, true);
665
+ }
666
+ //#endregion
609
667
  //#region src/internal/array/overlap.ts
610
668
  function arraysOverlap(first, second) {
611
669
  const firstArray = first.index < second.index ? first.array : second.array;
@@ -3600,6 +3658,14 @@ function isEmpty(value) {
3600
3658
  return true;
3601
3659
  }
3602
3660
  /**
3661
+ * Is the value not empty, or holding non-empty values?
3662
+ * @param value Value to check
3663
+ * @returns `true` if the value is not considered empty, otherwise `false`
3664
+ */
3665
+ function isNonEmpty(value) {
3666
+ return !isEmpty(value);
3667
+ }
3668
+ /**
3603
3669
  * Is the value not `undefined` or `null`?
3604
3670
  * @param value Value to check
3605
3671
  * @returns `true` if the value is not `undefined` or `null`, otherwise `false`
@@ -3608,6 +3674,38 @@ function isNonNullable(value) {
3608
3674
  return value != null;
3609
3675
  }
3610
3676
  /**
3677
+ * Is the value not `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
3678
+ * @param value Value to check
3679
+ * @returns `true` if the value is not `undefined`, `null`, or matches an empty string, otherwise `false`
3680
+ */
3681
+ function isNonNullableOrEmpty(value) {
3682
+ return value != null && getString(value) !== "";
3683
+ }
3684
+ /**
3685
+ * Is the value not `undefined`, `null`, or stringified as a whitespace-only string?
3686
+ * @param value Value to check
3687
+ * @returns `true` if the value is not `undefined`, `null`, or matches a whitespace-only string, otherwise `false`
3688
+ */
3689
+ function isNonNullableOrWhitespace(value) {
3690
+ return value != null && !EXPRESSION_WHITESPACE.test(getString(value));
3691
+ }
3692
+ /**
3693
+ * Is the value not a number or a number-like string?
3694
+ * @param value Value to check
3695
+ * @returns `true` if the value is not a number or a number-like string, otherwise `false`
3696
+ */
3697
+ function isNonNumerical(value) {
3698
+ return !isNumerical(value);
3699
+ }
3700
+ /**
3701
+ * Is the value not an object _(or function)_?
3702
+ * @param value Value to check
3703
+ * @returns `true` if the value is not an object, otherwise `false`
3704
+ */
3705
+ function isNonObject(value) {
3706
+ return !isObject(value);
3707
+ }
3708
+ /**
3611
3709
  * Is the value `undefined` or `null`?
3612
3710
  * @param value Value to check
3613
3711
  * @returns `true` if the value is `undefined` or `null`, otherwise `false`
@@ -3616,17 +3714,17 @@ function isNullable(value) {
3616
3714
  return value == null;
3617
3715
  }
3618
3716
  /**
3619
- * Is the value `undefined`, `null`, or an empty _(no whitespace)_ string?
3717
+ * Is the value `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
3620
3718
  * @param value Value to check
3621
- * @returns `true` if the value is nullable or an empty string, otherwise `false`
3719
+ * @returns `true` if the value is nullable or matches an empty string, otherwise `false`
3622
3720
  */
3623
3721
  function isNullableOrEmpty(value) {
3624
3722
  return value == null || getString(value) === "";
3625
3723
  }
3626
3724
  /**
3627
- * Is the value `undefined`, `null`, or a whitespace-only string?
3725
+ * Is the value `undefined`, `null`, or stringified as a whitespace-only string?
3628
3726
  * @param value Value to check
3629
- * @returns `true` if the value is nullable or a whitespace-only string, otherwise `false`
3727
+ * @returns `true` if the value is nullable or matches a whitespace-only string, otherwise `false`
3630
3728
  */
3631
3729
  function isNullableOrWhitespace(value) {
3632
3730
  return value == null || EXPRESSION_WHITESPACE.test(getString(value));
@@ -3634,7 +3732,7 @@ function isNullableOrWhitespace(value) {
3634
3732
  /**
3635
3733
  * Is the value a number or a number-like string?
3636
3734
  * @param value Value to check
3637
- * @returns `true` if the value is a number or a parseable string, otherwise `false`
3735
+ * @returns `true` if the value is a number or a number-like string, otherwise `false`
3638
3736
  */
3639
3737
  function isNumerical(value) {
3640
3738
  return isNumber(value) || typeof value === "string" && value.trim().length > 0 && !Number.isNaN(+value);
@@ -4608,4 +4706,4 @@ var SizedSet = class extends Set {
4608
4706
  }
4609
4707
  };
4610
4708
  //#endregion
4611
- export { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, attempt, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, difference, drop, endsWith, endsWithArray, equal, error, exists, filter, find, flatten, floor, flow, fromQuery, toPromise as fromResult, toPromise, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getTimedPromise, getUuid, getValue, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shuffle, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
4709
+ export { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, attempt, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, difference, drop, endsWith, endsWithArray, equal, error, exists, filter, find, first, flatten, floor, flow, fromQuery, toPromise as fromResult, toPromise, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getTimedPromise, getUuid, getValue, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, last, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
@@ -1,15 +1,22 @@
1
1
  //#region src/internal/array/find.d.ts
2
- type FindValueType = 'index' | 'value';
2
+ type FindValueType = 'index' | 'item';
3
3
  type FindValuesResult = {
4
4
  matched: unknown[];
5
5
  notMatched: unknown[];
6
6
  };
7
7
  type FindValuesType = 'all' | 'unique';
8
- declare function findValue(type: FindValueType, array: unknown[], parameters: unknown[]): unknown;
8
+ type Parameters = {
9
+ bool?: unknown;
10
+ key?: unknown;
11
+ value?: unknown;
12
+ };
13
+ declare function findValue(type: FindValueType, array: unknown[], parameters: unknown[], reversed: boolean): unknown;
14
+ declare function findAbsoluteValueOrDefault(array: unknown[], parameters: unknown[], defaultValue: unknown, useDefaultValue: boolean, reversed: boolean): unknown;
9
15
  declare function findValues(type: FindValuesType, array: unknown[], parameters: unknown[], mapper?: unknown): FindValuesResult;
16
+ declare function getFindParameters(original: unknown[]): Parameters;
10
17
  declare const FIND_VALUE_INDEX: FindValueType;
11
- declare const FIND_VALUE_VALUE: FindValueType;
18
+ declare const FIND_VALUE_ITEM: FindValueType;
12
19
  declare const FIND_VALUES_ALL: FindValuesType;
13
20
  declare const FIND_VALUES_UNIQUE: FindValuesType;
14
21
  //#endregion
15
- export { FIND_VALUES_ALL, FIND_VALUES_UNIQUE, FIND_VALUE_INDEX, FIND_VALUE_VALUE, findValue, findValues };
22
+ export { FIND_VALUES_ALL, FIND_VALUES_UNIQUE, FIND_VALUE_INDEX, FIND_VALUE_ITEM, findAbsoluteValueOrDefault, findValue, findValues, getFindParameters };
@@ -1,25 +1,33 @@
1
- import { getArrayCallbacks } from "./callbacks.mjs";
1
+ import { getArrayCallback, getArrayCallbacks } from "./callbacks.mjs";
2
2
  //#region src/internal/array/find.ts
3
- function findValue(type, array, parameters) {
3
+ function findValue(type, array, parameters, reversed) {
4
4
  const findIndex = type === FIND_VALUE_INDEX;
5
5
  if (!Array.isArray(array) || array.length === 0) return findIndex ? -1 : void 0;
6
- const { bool, key, value } = getParameters(parameters);
6
+ const { bool, key, value } = getFindParameters(parameters);
7
7
  const callbacks = getArrayCallbacks(bool, key);
8
8
  if (callbacks?.bool == null && callbacks?.keyed == null) return findIndex ? array.indexOf(value) : array.find((item) => Object.is(item, value));
9
9
  if (callbacks.bool != null) {
10
10
  const index = array.findIndex(callbacks.bool);
11
11
  return findIndex ? index : array[index];
12
12
  }
13
- return findValueInArray(array, callbacks.keyed, value, findIndex);
13
+ return findValueInArray(array, callbacks.keyed, value, findIndex, reversed);
14
14
  }
15
- function findValueInArray(array, callback, value, findIndex) {
15
+ function findValueInArray(array, callback, value, findIndex, reversed) {
16
16
  const { length } = array;
17
17
  for (let index = 0; index < length; index += 1) {
18
- const item = array[index];
18
+ const item = reversed ? array.at(-(index + 1)) : array[index];
19
19
  if (Object.is(callback?.(item, index, array), value)) return findIndex ? index : item;
20
20
  }
21
21
  return findIndex ? -1 : void 0;
22
22
  }
23
+ function findAbsoluteValueOrDefault(array, parameters, defaultValue, useDefaultValue, reversed) {
24
+ if (parameters.length === 0) {
25
+ if (Array.isArray(array) && array.length > 0) return reversed ? array.at(-1) : array[0];
26
+ return useDefaultValue ? defaultValue : void 0;
27
+ }
28
+ const index = findValue(FIND_VALUE_INDEX, array, parameters, reversed);
29
+ return index > -1 ? array[index] : useDefaultValue ? defaultValue : void 0;
30
+ }
23
31
  function findValues(type, array, parameters, mapper) {
24
32
  const result = {
25
33
  matched: [],
@@ -27,13 +35,13 @@ function findValues(type, array, parameters, mapper) {
27
35
  };
28
36
  if (!Array.isArray(array) || array.length === 0) return result;
29
37
  const { length } = array;
30
- const { bool, key, value } = getParameters(parameters);
38
+ const { bool, key, value } = getFindParameters(parameters);
31
39
  const callbacks = getArrayCallbacks(bool, key);
32
40
  if (type === "unique" && callbacks?.keyed == null && length >= UNIQUE_THRESHOLD) {
33
41
  result.matched = [...new Set(array)];
34
42
  return result;
35
43
  }
36
- const mapCallback = typeof mapper === "function" ? mapper : void 0;
44
+ const mapCallback = getArrayCallback(mapper);
37
45
  if (callbacks?.bool != null || type === "all" && key == null) {
38
46
  const callback = callbacks?.bool ?? ((item) => Object.is(item, value));
39
47
  for (let index = 0; index < length; index += 1) {
@@ -54,7 +62,7 @@ function findValues(type, array, parameters, mapper) {
54
62
  }
55
63
  return result;
56
64
  }
57
- function getParameters(original) {
65
+ function getFindParameters(original) {
58
66
  const { length } = original;
59
67
  return {
60
68
  bool: length === 1 && typeof original[0] === "function" ? original[0] : void 0,
@@ -63,9 +71,9 @@ function getParameters(original) {
63
71
  };
64
72
  }
65
73
  const FIND_VALUE_INDEX = "index";
66
- const FIND_VALUE_VALUE = "value";
74
+ const FIND_VALUE_ITEM = "item";
67
75
  const FIND_VALUES_ALL = "all";
68
76
  const FIND_VALUES_UNIQUE = "unique";
69
77
  const UNIQUE_THRESHOLD = 100;
70
78
  //#endregion
71
- export { FIND_VALUES_ALL, FIND_VALUES_UNIQUE, FIND_VALUE_INDEX, FIND_VALUE_VALUE, findValue, findValues };
79
+ export { FIND_VALUES_ALL, FIND_VALUES_UNIQUE, FIND_VALUE_INDEX, FIND_VALUE_ITEM, findAbsoluteValueOrDefault, findValue, findValues, getFindParameters };
@@ -26,6 +26,14 @@ declare function isInstanceOf<Instance>(constructor: Constructor<Instance>, valu
26
26
  * @returns `true` if the value is a `Key` _(`number` or `string`)_, otherwise `false`
27
27
  */
28
28
  declare function isKey(value: unknown): value is Key;
29
+ declare function isNonArrayOrPlainObject<Value>(value: Value): value is Exclude<Value, ArrayOrPlainObject>;
30
+ declare function isNonConstructor<Value>(value: Value): value is Exclude<Value, Constructor>;
31
+ declare function isNonInstanceOf<Instance, Value>(constructor: Constructor<Instance>, value: Value): value is Exclude<Value, Instance>;
32
+ declare function isNonKey<Value>(value: Value): value is Exclude<Value, Key>;
33
+ declare function isNonNumber<Value>(value: Value): value is Exclude<Value, number>;
34
+ declare function isNonPlainObject<Value>(value: Value): value is Exclude<Value, PlainObject>;
35
+ declare function isNonPrimitive<Value>(value: Value): value is Exclude<Value, Primitive>;
36
+ declare function isNonTypedArray<Value>(value: Value): value is Exclude<Value, TypedArray>;
29
37
  /**
30
38
  * Is the value a number?
31
39
  * @param value Value to check
@@ -51,4 +59,4 @@ declare function isPrimitive(value: unknown): value is Primitive;
51
59
  */
52
60
  declare function isTypedArray(value: unknown): value is TypedArray;
53
61
  //#endregion
54
- export { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNumber, isPlainObject, isPrimitive, isTypedArray };
62
+ export { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonInstanceOf, isNonKey, isNonNumber, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNumber, isPlainObject, isPrimitive, isTypedArray };
@@ -32,6 +32,30 @@ function isInstanceOf(constructor, value) {
32
32
  function isKey(value) {
33
33
  return typeof value === "number" || typeof value === "string";
34
34
  }
35
+ function isNonArrayOrPlainObject(value) {
36
+ return !isArrayOrPlainObject(value);
37
+ }
38
+ function isNonConstructor(value) {
39
+ return !isConstructor(value);
40
+ }
41
+ function isNonInstanceOf(constructor, value) {
42
+ return !isInstanceOf(constructor, value);
43
+ }
44
+ function isNonKey(value) {
45
+ return !isKey(value);
46
+ }
47
+ function isNonNumber(value) {
48
+ return !isNumber(value);
49
+ }
50
+ function isNonPlainObject(value) {
51
+ return !isPlainObject(value);
52
+ }
53
+ function isNonPrimitive(value) {
54
+ return !isPrimitive(value);
55
+ }
56
+ function isNonTypedArray(value) {
57
+ return !isTypedArray(value);
58
+ }
35
59
  /**
36
60
  * Is the value a number?
37
61
  * @param value Value to check
@@ -57,7 +81,9 @@ function isPlainObject(value) {
57
81
  * @returns `true` if the value matches, otherwise `false`
58
82
  */
59
83
  function isPrimitive(value) {
60
- return value == null || EXPRESSION_PRIMITIVE.test(typeof value);
84
+ if (value == null) return true;
85
+ const type = typeof value;
86
+ return type === "bigint" || type === "boolean" || type === "number" || type === "string" || type === "symbol";
61
87
  }
62
88
  /**
63
89
  * Is the value a typed array?
@@ -65,7 +91,7 @@ function isPrimitive(value) {
65
91
  * @returns `true` if the value is a typed array, otherwise `false`
66
92
  */
67
93
  function isTypedArray(value) {
68
- TYPED_ARRAYS ??= new Set([
94
+ isTypedArray.types ??= new Set([
69
95
  Int8Array,
70
96
  Uint8Array,
71
97
  Uint8ClampedArray,
@@ -78,9 +104,7 @@ function isTypedArray(value) {
78
104
  BigInt64Array,
79
105
  BigUint64Array
80
106
  ]);
81
- return TYPED_ARRAYS.has(value?.constructor);
107
+ return isTypedArray.types.has(value?.constructor);
82
108
  }
83
- const EXPRESSION_PRIMITIVE = /^(bigint|boolean|number|string|symbol)$/;
84
- let TYPED_ARRAYS;
85
109
  //#endregion
86
- export { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNumber, isPlainObject, isPrimitive, isTypedArray };
110
+ export { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonInstanceOf, isNonKey, isNonNumber, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNumber, isPlainObject, isPrimitive, isTypedArray };
package/dist/is.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNumber, isPlainObject, isPrimitive, isTypedArray } from "./internal/is.mjs";
1
+ import { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonInstanceOf, isNonKey, isNonNumber, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNumber, isPlainObject, isPrimitive, isTypedArray } from "./internal/is.mjs";
2
2
 
3
3
  //#region src/is.d.ts
4
4
  /**
@@ -7,12 +7,42 @@ import { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNumber, isP
7
7
  * @returns `true` if the value is considered empty, otherwise `false`
8
8
  */
9
9
  declare function isEmpty(value: unknown): boolean;
10
+ /**
11
+ * Is the value not empty, or holding non-empty values?
12
+ * @param value Value to check
13
+ * @returns `true` if the value is not considered empty, otherwise `false`
14
+ */
15
+ declare function isNonEmpty(value: unknown): boolean;
10
16
  /**
11
17
  * Is the value not `undefined` or `null`?
12
18
  * @param value Value to check
13
19
  * @returns `true` if the value is not `undefined` or `null`, otherwise `false`
14
20
  */
15
- declare function isNonNullable(value: unknown): value is Exclude<unknown, undefined | null>;
21
+ declare function isNonNullable<Value>(value: Value): value is Exclude<Value, undefined | null>;
22
+ /**
23
+ * Is the value not `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
24
+ * @param value Value to check
25
+ * @returns `true` if the value is not `undefined`, `null`, or matches an empty string, otherwise `false`
26
+ */
27
+ declare function isNonNullableOrEmpty<Value>(value: Value): value is Exclude<Value, undefined | null | ''>;
28
+ /**
29
+ * Is the value not `undefined`, `null`, or stringified as a whitespace-only string?
30
+ * @param value Value to check
31
+ * @returns `true` if the value is not `undefined`, `null`, or matches a whitespace-only string, otherwise `false`
32
+ */
33
+ declare function isNonNullableOrWhitespace<Value>(value: Value): value is Exclude<Value, undefined | null | ''>;
34
+ /**
35
+ * Is the value not a number or a number-like string?
36
+ * @param value Value to check
37
+ * @returns `true` if the value is not a number or a number-like string, otherwise `false`
38
+ */
39
+ declare function isNonNumerical<Value>(value: Value): value is Exclude<Value, number | `${number}`>;
40
+ /**
41
+ * Is the value not an object _(or function)_?
42
+ * @param value Value to check
43
+ * @returns `true` if the value is not an object, otherwise `false`
44
+ */
45
+ declare function isNonObject<Value>(value: Value): value is Exclude<Value, object>;
16
46
  /**
17
47
  * Is the value `undefined` or `null`?
18
48
  * @param value Value to check
@@ -20,21 +50,21 @@ declare function isNonNullable(value: unknown): value is Exclude<unknown, undefi
20
50
  */
21
51
  declare function isNullable(value: unknown): value is undefined | null;
22
52
  /**
23
- * Is the value `undefined`, `null`, or an empty _(no whitespace)_ string?
53
+ * Is the value `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
24
54
  * @param value Value to check
25
- * @returns `true` if the value is nullable or an empty string, otherwise `false`
55
+ * @returns `true` if the value is nullable or matches an empty string, otherwise `false`
26
56
  */
27
57
  declare function isNullableOrEmpty(value: unknown): value is undefined | null | '';
28
58
  /**
29
- * Is the value `undefined`, `null`, or a whitespace-only string?
59
+ * Is the value `undefined`, `null`, or stringified as a whitespace-only string?
30
60
  * @param value Value to check
31
- * @returns `true` if the value is nullable or a whitespace-only string, otherwise `false`
61
+ * @returns `true` if the value is nullable or matches a whitespace-only string, otherwise `false`
32
62
  */
33
63
  declare function isNullableOrWhitespace(value: unknown): value is undefined | null | '';
34
64
  /**
35
65
  * Is the value a number or a number-like string?
36
66
  * @param value Value to check
37
- * @returns `true` if the value is a number or a parseable string, otherwise `false`
67
+ * @returns `true` if the value is a number or a number-like string, otherwise `false`
38
68
  */
39
69
  declare function isNumerical(value: unknown): value is number | `${number}`;
40
70
  /**
@@ -44,4 +74,4 @@ declare function isNumerical(value: unknown): value is number | `${number}`;
44
74
  */
45
75
  declare function isObject(value: unknown): value is object;
46
76
  //#endregion
47
- export { isArrayOrPlainObject, isConstructor, isEmpty, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isPlainObject, isPrimitive, isTypedArray };
77
+ export { isArrayOrPlainObject, isConstructor, isEmpty, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isPlainObject, isPrimitive, isTypedArray };
package/dist/is.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNumber, isPlainObject, isPrimitive, isTypedArray } from "./internal/is.mjs";
1
+ import { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonInstanceOf, isNonKey, isNonNumber, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNumber, isPlainObject, isPrimitive, isTypedArray } from "./internal/is.mjs";
2
2
  import { getArray } from "./array/get.mjs";
3
3
  import { getString } from "./internal/string.mjs";
4
4
  //#region src/is.ts
@@ -16,6 +16,14 @@ function isEmpty(value) {
16
16
  return true;
17
17
  }
18
18
  /**
19
+ * Is the value not empty, or holding non-empty values?
20
+ * @param value Value to check
21
+ * @returns `true` if the value is not considered empty, otherwise `false`
22
+ */
23
+ function isNonEmpty(value) {
24
+ return !isEmpty(value);
25
+ }
26
+ /**
19
27
  * Is the value not `undefined` or `null`?
20
28
  * @param value Value to check
21
29
  * @returns `true` if the value is not `undefined` or `null`, otherwise `false`
@@ -24,6 +32,38 @@ function isNonNullable(value) {
24
32
  return value != null;
25
33
  }
26
34
  /**
35
+ * Is the value not `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
36
+ * @param value Value to check
37
+ * @returns `true` if the value is not `undefined`, `null`, or matches an empty string, otherwise `false`
38
+ */
39
+ function isNonNullableOrEmpty(value) {
40
+ return value != null && getString(value) !== "";
41
+ }
42
+ /**
43
+ * Is the value not `undefined`, `null`, or stringified as a whitespace-only string?
44
+ * @param value Value to check
45
+ * @returns `true` if the value is not `undefined`, `null`, or matches a whitespace-only string, otherwise `false`
46
+ */
47
+ function isNonNullableOrWhitespace(value) {
48
+ return value != null && !EXPRESSION_WHITESPACE.test(getString(value));
49
+ }
50
+ /**
51
+ * Is the value not a number or a number-like string?
52
+ * @param value Value to check
53
+ * @returns `true` if the value is not a number or a number-like string, otherwise `false`
54
+ */
55
+ function isNonNumerical(value) {
56
+ return !isNumerical(value);
57
+ }
58
+ /**
59
+ * Is the value not an object _(or function)_?
60
+ * @param value Value to check
61
+ * @returns `true` if the value is not an object, otherwise `false`
62
+ */
63
+ function isNonObject(value) {
64
+ return !isObject(value);
65
+ }
66
+ /**
27
67
  * Is the value `undefined` or `null`?
28
68
  * @param value Value to check
29
69
  * @returns `true` if the value is `undefined` or `null`, otherwise `false`
@@ -32,17 +72,17 @@ function isNullable(value) {
32
72
  return value == null;
33
73
  }
34
74
  /**
35
- * Is the value `undefined`, `null`, or an empty _(no whitespace)_ string?
75
+ * Is the value `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
36
76
  * @param value Value to check
37
- * @returns `true` if the value is nullable or an empty string, otherwise `false`
77
+ * @returns `true` if the value is nullable or matches an empty string, otherwise `false`
38
78
  */
39
79
  function isNullableOrEmpty(value) {
40
80
  return value == null || getString(value) === "";
41
81
  }
42
82
  /**
43
- * Is the value `undefined`, `null`, or a whitespace-only string?
83
+ * Is the value `undefined`, `null`, or stringified as a whitespace-only string?
44
84
  * @param value Value to check
45
- * @returns `true` if the value is nullable or a whitespace-only string, otherwise `false`
85
+ * @returns `true` if the value is nullable or matches a whitespace-only string, otherwise `false`
46
86
  */
47
87
  function isNullableOrWhitespace(value) {
48
88
  return value == null || EXPRESSION_WHITESPACE.test(getString(value));
@@ -50,7 +90,7 @@ function isNullableOrWhitespace(value) {
50
90
  /**
51
91
  * Is the value a number or a number-like string?
52
92
  * @param value Value to check
53
- * @returns `true` if the value is a number or a parseable string, otherwise `false`
93
+ * @returns `true` if the value is a number or a number-like string, otherwise `false`
54
94
  */
55
95
  function isNumerical(value) {
56
96
  return isNumber(value) || typeof value === "string" && value.trim().length > 0 && !Number.isNaN(+value);
@@ -65,4 +105,4 @@ function isObject(value) {
65
105
  }
66
106
  const EXPRESSION_WHITESPACE = /^\s*$/;
67
107
  //#endregion
68
- export { isArrayOrPlainObject, isConstructor, isEmpty, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isPlainObject, isPrimitive, isTypedArray };
108
+ export { isArrayOrPlainObject, isConstructor, isEmpty, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isPlainObject, isPrimitive, isTypedArray };