@oscarpalmer/atoms 0.136.0 → 0.137.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.
Files changed (45) hide show
  1. package/dist/array/group-by.js +1 -2
  2. package/dist/array/index.js +4 -4
  3. package/dist/array/to-map.js +1 -2
  4. package/dist/array/to-record.js +1 -2
  5. package/dist/atoms.full.js +46 -63
  6. package/dist/index.js +10 -10
  7. package/dist/internal/is.js +3 -4
  8. package/dist/internal/value/compare.js +14 -12
  9. package/dist/internal/value/equal.js +12 -13
  10. package/dist/is.js +2 -2
  11. package/dist/result.js +1 -2
  12. package/dist/string/index.js +2 -2
  13. package/dist/string/template.js +12 -12
  14. package/dist/value/clone.js +12 -10
  15. package/dist/value/index.js +4 -4
  16. package/dist/value/merge.js +3 -3
  17. package/package.json +1 -1
  18. package/src/array/group-by.ts +7 -9
  19. package/src/array/index.ts +4 -4
  20. package/src/array/to-map.ts +7 -9
  21. package/src/array/to-record.ts +7 -9
  22. package/src/internal/is.ts +3 -5
  23. package/src/internal/value/compare.ts +17 -15
  24. package/src/internal/value/equal.ts +17 -38
  25. package/src/is.ts +17 -2
  26. package/src/result.ts +3 -5
  27. package/src/string/index.ts +1 -1
  28. package/src/string/template.ts +13 -13
  29. package/src/value/clone.ts +13 -11
  30. package/src/value/index.ts +9 -3
  31. package/src/value/merge.ts +1 -1
  32. package/types/array/group-by.d.ts +6 -10
  33. package/types/array/index.d.ts +4 -4
  34. package/types/array/to-map.d.ts +6 -10
  35. package/types/array/to-record.d.ts +6 -10
  36. package/types/internal/is.d.ts +2 -2
  37. package/types/internal/value/compare.d.ts +11 -9
  38. package/types/internal/value/equal.d.ts +19 -25
  39. package/types/is.d.ts +2 -2
  40. package/types/result.d.ts +2 -6
  41. package/types/string/index.d.ts +1 -1
  42. package/types/string/template.d.ts +6 -3
  43. package/types/value/clone.d.ts +11 -9
  44. package/types/value/index.d.ts +3 -3
  45. package/types/value/merge.d.ts +6 -3
@@ -2,8 +2,7 @@ import { groupValues } from "../internal/array/group.js";
2
2
  function groupBy(array, first, second) {
3
3
  return groupValues(array, first, second, false);
4
4
  }
5
- groupBy.arrays = groupArraysBy;
6
5
  function groupArraysBy(array, first, second) {
7
6
  return groupValues(array, first, second, true);
8
7
  }
9
- export { groupBy };
8
+ export { groupArraysBy, groupBy };
@@ -3,7 +3,7 @@ import { filter } from "./filter.js";
3
3
  import { find } from "./find.js";
4
4
  import { flatten } from "./flatten.js";
5
5
  import { getArray } from "./get.js";
6
- import { groupBy } from "./group-by.js";
6
+ import { groupArraysBy, groupBy } from "./group-by.js";
7
7
  import { indexOf } from "./index-of.js";
8
8
  import { chunk } from "../internal/array/chunk.js";
9
9
  import { compact } from "../internal/array/compact.js";
@@ -12,8 +12,8 @@ import { insert } from "./insert.js";
12
12
  import { push } from "./push.js";
13
13
  import { sort } from "./sort.js";
14
14
  import { splice } from "./splice.js";
15
- import { toMap } from "./to-map.js";
16
- import { toRecord } from "./to-record.js";
15
+ import { toMap, toMapArrays } from "./to-map.js";
16
+ import { toRecord, toRecordArrays } from "./to-record.js";
17
17
  import { toSet } from "./to-set.js";
18
18
  import { unique } from "./unique.js";
19
- export { chunk, compact, exists, filter, find, flatten, getArray, groupBy, indexOf, insert, push, shuffle, sort, splice, toMap, toRecord, toSet, unique };
19
+ export { chunk, compact, exists, filter, find, flatten, getArray, groupArraysBy, groupBy, indexOf, insert, push, shuffle, sort, splice, toMap, toMapArrays, toRecord, toRecordArrays, toSet, unique };
@@ -19,8 +19,7 @@ function getMapValues(array, first, second, arrays) {
19
19
  function toMap(array, first, second) {
20
20
  return getMapValues(array, first, second, false);
21
21
  }
22
- toMap.arrays = toMapArrays;
23
22
  function toMapArrays(array, first, second) {
24
23
  return getMapValues(array, first, second, true);
25
24
  }
26
- export { toMap };
25
+ export { toMap, toMapArrays };
@@ -2,8 +2,7 @@ import { groupValues } from "../internal/array/group.js";
2
2
  function toRecord(array, first, second) {
3
3
  return groupValues(array, first, second, false);
4
4
  }
5
- toRecord.arrays = toRecordArrays;
6
5
  function toRecordArrays(array, first, second) {
7
6
  return groupValues(array, first, second, true);
8
7
  }
9
- export { toRecord };
8
+ export { toRecord, toRecordArrays };
@@ -63,12 +63,12 @@ function isArrayOrPlainObject(value) {
63
63
  return Array.isArray(value) || isPlainObject(value);
64
64
  }
65
65
  /**
66
- * Is the value a constructor?
66
+ * Is the value a constructor function?
67
67
  * @param value Value to check
68
- * @returns `true` if the value is a constructor, otherwise `false`
68
+ * @returns `true` if the value is a constructor function, otherwise `false`
69
69
  */
70
70
  function isConstructor(value) {
71
- return typeof value === "function" && EXPRESSION_CONSTRUCTOR.test(value.name);
71
+ return typeof value === "function" && value.prototype?.constructor === value;
72
72
  }
73
73
  /**
74
74
  * Is the value a key?
@@ -118,7 +118,6 @@ function isTypedArray(value) {
118
118
  ]);
119
119
  return TYPED_ARRAYS.has(value?.constructor);
120
120
  }
121
- const EXPRESSION_CONSTRUCTOR = /^[A-Z][A-Za-z0-9]*$/;
122
121
  let TYPED_ARRAYS;
123
122
  function _getRandomFloat(inclusive, minimum, maximum) {
124
123
  let maxFloat = isNumber(maximum) && maximum <= Number.MAX_SAFE_INTEGER ? maximum : Number.MAX_SAFE_INTEGER;
@@ -279,7 +278,6 @@ function groupValues(array, key, value, arrays) {
279
278
  function groupBy(array, first, second) {
280
279
  return groupValues(array, first, second, false);
281
280
  }
282
- groupBy.arrays = groupArraysBy;
283
281
  function groupArraysBy(array, first, second) {
284
282
  return groupValues(array, first, second, true);
285
283
  }
@@ -481,25 +479,21 @@ function compare(first, second) {
481
479
  }
482
480
  return 0;
483
481
  }
484
- compare.handlers = getCompareHandlers(compare, {
485
- callback: (first, second, compareStrings) => {
486
- if (compareStrings) return getString(first).localeCompare(getString(second));
487
- },
488
- method: "compare"
489
- });
490
482
  /**
491
483
  * Register a custom comparison handler for a class
492
484
  * @param constructor Class constructor
493
485
  * @param handler Method name or comparison function _(defaults to `compare`)_
494
486
  */
495
- compare.register = function(constructor, handler) {
496
- compare.handlers.register(constructor, handler);
497
- };
487
+ function registerComparator(constructor, handler) {
488
+ compareHandlers.register(constructor, handler);
489
+ }
498
490
  /**
499
491
  * Unregister a custom comparison handler for a class
500
492
  * @param constructor Class constructor
501
493
  */
502
- compare.unregister = compare.handlers.unregister;
494
+ function unregisterComparator(constructor) {
495
+ compareHandlers.unregister(constructor);
496
+ }
503
497
  function compareNumbers(first, second) {
504
498
  const firstNumber = Number(first);
505
499
  const secondNumber = Number(second);
@@ -513,7 +507,7 @@ function compareValue(first, second, compareStrings) {
513
507
  const firstType = typeof first;
514
508
  if (firstType === typeof second && firstType in comparators) return comparators[firstType](first, second);
515
509
  if (first instanceof Date && second instanceof Date) return compareNumbers(first.getTime(), second.getTime());
516
- return compare.handlers.handle(first, second, compareStrings);
510
+ return compareHandlers.handle(first, second, compareStrings);
517
511
  }
518
512
  function getComparisonParts(value) {
519
513
  if (Array.isArray(value)) return value;
@@ -525,6 +519,12 @@ const comparators = {
525
519
  number: compareNumbers,
526
520
  symbol: compareSymbols
527
521
  };
522
+ const compareHandlers = getCompareHandlers(compare, {
523
+ callback: (first, second, compareStrings) => {
524
+ if (compareStrings) return getString(first).localeCompare(getString(second));
525
+ },
526
+ method: "compare"
527
+ });
528
528
  function getCallback(value, key, forObject) {
529
529
  if (key != null) return;
530
530
  if (forObject && typeof value.value === "function") return value.value;
@@ -605,14 +605,12 @@ function getMapValues(array, first, second, arrays) {
605
605
  function toMap(array, first, second) {
606
606
  return getMapValues(array, first, second, false);
607
607
  }
608
- toMap.arrays = toMapArrays;
609
608
  function toMapArrays(array, first, second) {
610
609
  return getMapValues(array, first, second, true);
611
610
  }
612
611
  function toRecord(array, first, second) {
613
612
  return groupValues(array, first, second, false);
614
613
  }
615
- toRecord.arrays = toRecordArrays;
616
614
  function toRecordArrays(array, first, second) {
617
615
  return groupValues(array, first, second, true);
618
616
  }
@@ -2548,7 +2546,6 @@ function result(callback, err) {
2548
2546
  return getError(err ?? thrown, err == null ? void 0 : thrown);
2549
2547
  }
2550
2548
  }
2551
- result.async = asyncResult;
2552
2549
  async function asyncResult(callback, err) {
2553
2550
  try {
2554
2551
  return ok(await callback());
@@ -2795,6 +2792,17 @@ function handleTemplate(value, pattern, ignoreCase, variables) {
2795
2792
  });
2796
2793
  }
2797
2794
  /**
2795
+ * Create a templater with predefined options
2796
+ * @param options Templating options
2797
+ * @returns Templater function
2798
+ */
2799
+ function initializeTemplater(options) {
2800
+ const { ignoreCase, pattern } = getTemplateOptions(options);
2801
+ return (value, variables) => {
2802
+ return handleTemplate(value, pattern, ignoreCase, variables);
2803
+ };
2804
+ }
2805
+ /**
2798
2806
  * Render a string from a template with variables
2799
2807
  * @param value Template string
2800
2808
  * @param variables Variables to use
@@ -2805,17 +2813,6 @@ function template(value, variables, options) {
2805
2813
  const { ignoreCase, pattern } = getTemplateOptions(options);
2806
2814
  return handleTemplate(value, pattern, ignoreCase, variables);
2807
2815
  }
2808
- /**
2809
- * Create a templater with predefined options
2810
- * @param options Templating options
2811
- * @returns Templater function
2812
- */
2813
- template.initialize = function(options) {
2814
- const { ignoreCase, pattern } = getTemplateOptions(options);
2815
- return (value, variables) => {
2816
- return handleTemplate(value, pattern, ignoreCase, variables);
2817
- };
2818
- };
2819
2816
  const EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
2820
2817
  function equal(first, second, options) {
2821
2818
  return equalValue(first, second, getEqualOptions(options));
@@ -2916,35 +2913,33 @@ function equalValue(first, second, options) {
2916
2913
  case Array.isArray(first) && Array.isArray(second): return equalArray(first, second, options);
2917
2914
  case isPlainObject(first) && isPlainObject(second): return equalPlainObject(first, second, options);
2918
2915
  case isTypedArray(first) && isTypedArray(second): return equalTypedArray(first, second);
2919
- default: return equal.handlers.handle(first, second, options);
2916
+ default: return equalHandlers.handle(first, second, options);
2920
2917
  }
2921
2918
  }
2922
- equal.handlers = getCompareHandlers(equal, { callback: Object.is });
2923
2919
  /**
2924
2920
  * Create an equalizer with predefined options
2925
2921
  * @param options Comparison options
2926
2922
  * @returns Equalizer function
2927
2923
  */
2928
- equal.initialize = function(options) {
2924
+ function initializeEqualizer(options) {
2929
2925
  const actual = getEqualOptions(options);
2930
- const equalizer = (first, second) => equalValue(first, second, actual);
2931
- equalizer.register = equal.register;
2932
- equalizer.unregister = equal.unregister;
2933
- return equalizer;
2934
- };
2926
+ return (first, second) => equalValue(first, second, actual);
2927
+ }
2935
2928
  /**
2936
2929
  * Register a equality comparison function for a specific class
2937
2930
  * @param constructor Class constructor
2938
2931
  * @param fn Comparison function
2939
2932
  */
2940
- equal.register = function(constructor, fn) {
2941
- equal.handlers.register(constructor, fn);
2942
- };
2933
+ function registerEqualizer(constructor, fn) {
2934
+ equalHandlers.register(constructor, fn);
2935
+ }
2943
2936
  /**
2944
2937
  * Unregister a equality comparison handler for a specific class
2945
2938
  * @param constructor Class constructor
2946
2939
  */
2947
- equal.unregister = equal.handlers.unregister;
2940
+ function unregisterEqualizer(constructor) {
2941
+ equalHandlers.unregister(constructor);
2942
+ }
2948
2943
  function filterKey(key, options) {
2949
2944
  if (typeof key !== "string") return true;
2950
2945
  if (options.ignoreExpressions.enabled && options.ignoreExpressions.values.some((expression) => expression.test(key))) return false;
@@ -2977,28 +2972,12 @@ function getEqualOptions(input) {
2977
2972
  options.relaxedNullish = input.relaxedNullish === true;
2978
2973
  return options;
2979
2974
  }
2975
+ const equalHandlers = getCompareHandlers(equal, { callback: Object.is });
2980
2976
  const ARRAY_PEEK_PERCENTAGE = 10;
2981
2977
  const ARRAY_THRESHOLD = 100;
2982
2978
  function clone(value) {
2983
2979
  return cloneValue(value, 0, /* @__PURE__ */ new WeakMap());
2984
2980
  }
2985
- clone.handlers = getSelfHandlers(clone, {
2986
- callback: tryStructuredClone,
2987
- method: "clone"
2988
- });
2989
- /**
2990
- * Register a clone handler for a specific class
2991
- * @param constructor Class constructor
2992
- * @param handler Method name or clone function _(defaults to `clone`)_
2993
- */
2994
- clone.register = function(constructor, handler) {
2995
- clone.handlers.register(constructor, handler);
2996
- };
2997
- /**
2998
- * Unregister a clone handler for a specific class
2999
- * @param constructor Class constructor
3000
- */
3001
- clone.unregister = clone.handlers.unregister;
3002
2981
  function cloneArrayBuffer(value, depth, references) {
3003
2982
  if (typeof depth === "number" && depth >= MAX_CLONE_DEPTH) return value;
3004
2983
  const cloned = new ArrayBuffer(value.byteLength);
@@ -3077,7 +3056,7 @@ function cloneValue(value, depth, references) {
3077
3056
  case value instanceof Node: return cloneNode(value, depth, references);
3078
3057
  case isArrayOrPlainObject(value): return clonePlainObject(value, depth, references);
3079
3058
  case isTypedArray(value): return cloneTypedArray(value, depth, references);
3080
- default: return clone.handlers.handle(value, depth, references);
3059
+ default: return cloneHandlers.handle(value, depth, references);
3081
3060
  }
3082
3061
  }
3083
3062
  function tryStructuredClone(value, depth, references) {
@@ -3091,6 +3070,10 @@ function tryStructuredClone(value, depth, references) {
3091
3070
  return value;
3092
3071
  }
3093
3072
  }
3073
+ const cloneHandlers = getSelfHandlers(clone, {
3074
+ callback: tryStructuredClone,
3075
+ method: "clone"
3076
+ });
3094
3077
  const MAX_CLONE_DEPTH = 100;
3095
3078
  /**
3096
3079
  * Find the differences between two values
@@ -3219,10 +3202,10 @@ function merge(values, options) {
3219
3202
  * @param options Merging options
3220
3203
  * @returns Merger function
3221
3204
  */
3222
- merge.initialize = function(options) {
3205
+ function initializeMerger(options) {
3223
3206
  const actual = getMergeOptions(options);
3224
3207
  return (values) => handleMerge(values, actual);
3225
- };
3208
+ }
3226
3209
  function mergeObjects(values, options, prefix) {
3227
3210
  const { length } = values;
3228
3211
  const isArray = values.every(Array.isArray);
@@ -3328,4 +3311,4 @@ function unsmush(value) {
3328
3311
  }
3329
3312
  return unsmushed;
3330
3313
  }
3331
- export { frame_rate_default as FRAME_RATE_MS, PromiseTimeoutError, QueueError, SizedMap, SizedSet, average, beacon, between, camelCase, capitalize, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, fromQuery, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, includes, indexOf, insert, isArrayOrPlainObject, isColor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isKey, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, memoize, merge, min, noop, ok, parse, partial, pascalCase, promises, push, queue, result, rgbToHex, rgbToHsl, rgbToHsla, round, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, titleCase, toMap, toQuery, toRecord, toSet, trim, truncate, unique, unsmush, unwrap, upperCase, words };
3314
+ export { frame_rate_default as FRAME_RATE_MS, PromiseTimeoutError, QueueError, SizedMap, SizedSet, asyncResult, average, beacon, between, camelCase, capitalize, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, fromQuery, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupArraysBy, groupBy, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, includes, indexOf, initializeEqualizer, initializeMerger, initializeTemplater, insert, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isKey, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, memoize, merge, min, noop, ok, parse, partial, pascalCase, promises, push, queue, registerComparator, registerEqualizer, result, rgbToHex, rgbToHsl, rgbToHsla, round, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toSet, trim, truncate, unique, unregisterComparator, unregisterEqualizer, unsmush, unwrap, upperCase, words };
package/dist/index.js CHANGED
@@ -2,9 +2,9 @@ import { exists } from "./array/exists.js";
2
2
  import { filter } from "./array/filter.js";
3
3
  import { find } from "./array/find.js";
4
4
  import { flatten } from "./array/flatten.js";
5
- import { isArrayOrPlainObject, isKey, isNumber, isPlainObject, isTypedArray } from "./internal/is.js";
5
+ import { isArrayOrPlainObject, isConstructor, isKey, isNumber, isPlainObject, isTypedArray } from "./internal/is.js";
6
6
  import { getArray } from "./array/get.js";
7
- import { groupBy } from "./array/group-by.js";
7
+ import { groupArraysBy, groupBy } from "./array/group-by.js";
8
8
  import { indexOf } from "./array/index-of.js";
9
9
  import { chunk } from "./internal/array/chunk.js";
10
10
  import { compact } from "./internal/array/compact.js";
@@ -14,11 +14,11 @@ import { insert } from "./array/insert.js";
14
14
  import { push } from "./array/push.js";
15
15
  import { max } from "./internal/math/aggregate.js";
16
16
  import { getString, join, words } from "./internal/string.js";
17
- import { compare } from "./internal/value/compare.js";
17
+ import { compare, registerComparator, unregisterComparator } from "./internal/value/compare.js";
18
18
  import { sort } from "./array/sort.js";
19
19
  import { splice } from "./array/splice.js";
20
- import { toMap } from "./array/to-map.js";
21
- import { toRecord } from "./array/to-record.js";
20
+ import { toMap, toMapArrays } from "./array/to-map.js";
21
+ import { toRecord, toRecordArrays } from "./array/to-record.js";
22
22
  import { toSet } from "./array/to-set.js";
23
23
  import { unique } from "./array/unique.js";
24
24
  import "./array/index.js";
@@ -42,18 +42,18 @@ import { QueueError, queue } from "./queue.js";
42
42
  import { setValue } from "./internal/value/set.js";
43
43
  import { fromQuery, toQuery } from "./query.js";
44
44
  import { getRandomBoolean, getRandomCharacters, getRandomColor, getRandomHex, getRandomItem, getRandomItems } from "./random.js";
45
- import { error, isError, isOk, isResult, ok, result, unwrap } from "./result.js";
45
+ import { asyncResult, error, isError, isOk, isResult, ok, result, unwrap } from "./result.js";
46
46
  import { camelCase, capitalize, kebabCase, lowerCase, pascalCase, snakeCase, titleCase, upperCase } from "./string/case.js";
47
47
  import { endsWith, getUuid, includes, parse, startsWith, trim, truncate } from "./string/misc.js";
48
48
  import { getValue } from "./internal/value/get.js";
49
- import { template } from "./string/template.js";
49
+ import { initializeTemplater, template } from "./string/template.js";
50
50
  import "./string/index.js";
51
- import { equal } from "./internal/value/equal.js";
51
+ import { equal, initializeEqualizer, registerEqualizer, unregisterEqualizer } from "./internal/value/equal.js";
52
52
  import { clone } from "./value/clone.js";
53
53
  import { diff } from "./value/diff.js";
54
- import { merge } from "./value/merge.js";
54
+ import { initializeMerger, merge } from "./value/merge.js";
55
55
  import { partial } from "./value/partial.js";
56
56
  import { smush } from "./value/smush.js";
57
57
  import { unsmush } from "./value/unsmush.js";
58
58
  import "./value/index.js";
59
- export { frame_rate_default as FRAME_RATE_MS, PromiseTimeoutError, QueueError, SizedMap, SizedSet, average, beacon, between, camelCase, capitalize, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, fromQuery, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, includes, indexOf, insert, isArrayOrPlainObject, isColor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isKey, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, memoize, merge, min, noop, ok, parse, partial, pascalCase, promises, push, queue, result, rgbToHex, rgbToHsl, rgbToHsla, round, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, titleCase, toMap, toQuery, toRecord, toSet, trim, truncate, unique, unsmush, unwrap, upperCase, words };
59
+ export { frame_rate_default as FRAME_RATE_MS, PromiseTimeoutError, QueueError, SizedMap, SizedSet, asyncResult, average, beacon, between, camelCase, capitalize, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, fromQuery, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupArraysBy, groupBy, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, includes, indexOf, initializeEqualizer, initializeMerger, initializeTemplater, insert, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isKey, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, memoize, merge, min, noop, ok, parse, partial, pascalCase, promises, push, queue, registerComparator, registerEqualizer, result, rgbToHex, rgbToHsl, rgbToHsla, round, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toSet, trim, truncate, unique, unregisterComparator, unregisterEqualizer, unsmush, unwrap, upperCase, words };
@@ -7,12 +7,12 @@ function isArrayOrPlainObject(value) {
7
7
  return Array.isArray(value) || isPlainObject(value);
8
8
  }
9
9
  /**
10
- * Is the value a constructor?
10
+ * Is the value a constructor function?
11
11
  * @param value Value to check
12
- * @returns `true` if the value is a constructor, otherwise `false`
12
+ * @returns `true` if the value is a constructor function, otherwise `false`
13
13
  */
14
14
  function isConstructor(value) {
15
- return typeof value === "function" && EXPRESSION_CONSTRUCTOR.test(value.name);
15
+ return typeof value === "function" && value.prototype?.constructor === value;
16
16
  }
17
17
  /**
18
18
  * Is the value a key?
@@ -62,6 +62,5 @@ function isTypedArray(value) {
62
62
  ]);
63
63
  return TYPED_ARRAYS.has(value?.constructor);
64
64
  }
65
- var EXPRESSION_CONSTRUCTOR = /^[A-Z][A-Za-z0-9]*$/;
66
65
  var TYPED_ARRAYS;
67
66
  export { isArrayOrPlainObject, isConstructor, isKey, isNumber, isPlainObject, isTypedArray };
@@ -29,25 +29,21 @@ function compare(first, second) {
29
29
  }
30
30
  return 0;
31
31
  }
32
- compare.handlers = getCompareHandlers(compare, {
33
- callback: (first, second, compareStrings) => {
34
- if (compareStrings) return getString(first).localeCompare(getString(second));
35
- },
36
- method: "compare"
37
- });
38
32
  /**
39
33
  * Register a custom comparison handler for a class
40
34
  * @param constructor Class constructor
41
35
  * @param handler Method name or comparison function _(defaults to `compare`)_
42
36
  */
43
- compare.register = function(constructor, handler) {
44
- compare.handlers.register(constructor, handler);
45
- };
37
+ function registerComparator(constructor, handler) {
38
+ compareHandlers.register(constructor, handler);
39
+ }
46
40
  /**
47
41
  * Unregister a custom comparison handler for a class
48
42
  * @param constructor Class constructor
49
43
  */
50
- compare.unregister = compare.handlers.unregister;
44
+ function unregisterComparator(constructor) {
45
+ compareHandlers.unregister(constructor);
46
+ }
51
47
  function compareNumbers(first, second) {
52
48
  const firstNumber = Number(first);
53
49
  const secondNumber = Number(second);
@@ -61,7 +57,7 @@ function compareValue(first, second, compareStrings) {
61
57
  const firstType = typeof first;
62
58
  if (firstType === typeof second && firstType in comparators) return comparators[firstType](first, second);
63
59
  if (first instanceof Date && second instanceof Date) return compareNumbers(first.getTime(), second.getTime());
64
- return compare.handlers.handle(first, second, compareStrings);
60
+ return compareHandlers.handle(first, second, compareStrings);
65
61
  }
66
62
  function getComparisonParts(value) {
67
63
  if (Array.isArray(value)) return value;
@@ -73,4 +69,10 @@ var comparators = {
73
69
  number: compareNumbers,
74
70
  symbol: compareSymbols
75
71
  };
76
- export { compare };
72
+ var compareHandlers = getCompareHandlers(compare, {
73
+ callback: (first, second, compareStrings) => {
74
+ if (compareStrings) return getString(first).localeCompare(getString(second));
75
+ },
76
+ method: "compare"
77
+ });
78
+ export { compare, registerComparator, unregisterComparator };
@@ -100,35 +100,33 @@ function equalValue(first, second, options) {
100
100
  case Array.isArray(first) && Array.isArray(second): return equalArray(first, second, options);
101
101
  case isPlainObject(first) && isPlainObject(second): return equalPlainObject(first, second, options);
102
102
  case isTypedArray(first) && isTypedArray(second): return equalTypedArray(first, second);
103
- default: return equal.handlers.handle(first, second, options);
103
+ default: return equalHandlers.handle(first, second, options);
104
104
  }
105
105
  }
106
- equal.handlers = getCompareHandlers(equal, { callback: Object.is });
107
106
  /**
108
107
  * Create an equalizer with predefined options
109
108
  * @param options Comparison options
110
109
  * @returns Equalizer function
111
110
  */
112
- equal.initialize = function(options) {
111
+ function initializeEqualizer(options) {
113
112
  const actual = getEqualOptions(options);
114
- const equalizer = (first, second) => equalValue(first, second, actual);
115
- equalizer.register = equal.register;
116
- equalizer.unregister = equal.unregister;
117
- return equalizer;
118
- };
113
+ return (first, second) => equalValue(first, second, actual);
114
+ }
119
115
  /**
120
116
  * Register a equality comparison function for a specific class
121
117
  * @param constructor Class constructor
122
118
  * @param fn Comparison function
123
119
  */
124
- equal.register = function(constructor, fn) {
125
- equal.handlers.register(constructor, fn);
126
- };
120
+ function registerEqualizer(constructor, fn) {
121
+ equalHandlers.register(constructor, fn);
122
+ }
127
123
  /**
128
124
  * Unregister a equality comparison handler for a specific class
129
125
  * @param constructor Class constructor
130
126
  */
131
- equal.unregister = equal.handlers.unregister;
127
+ function unregisterEqualizer(constructor) {
128
+ equalHandlers.unregister(constructor);
129
+ }
132
130
  function filterKey(key, options) {
133
131
  if (typeof key !== "string") return true;
134
132
  if (options.ignoreExpressions.enabled && options.ignoreExpressions.values.some((expression) => expression.test(key))) return false;
@@ -161,6 +159,7 @@ function getEqualOptions(input) {
161
159
  options.relaxedNullish = input.relaxedNullish === true;
162
160
  return options;
163
161
  }
162
+ var equalHandlers = getCompareHandlers(equal, { callback: Object.is });
164
163
  var ARRAY_PEEK_PERCENTAGE = 10;
165
164
  var ARRAY_THRESHOLD = 100;
166
- export { equal };
165
+ export { equal, initializeEqualizer, registerEqualizer, unregisterEqualizer };
package/dist/is.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isArrayOrPlainObject, isKey, isNumber, isPlainObject, isTypedArray } from "./internal/is.js";
1
+ import { isArrayOrPlainObject, isConstructor, isKey, isNumber, isPlainObject, isTypedArray } from "./internal/is.js";
2
2
  import { getArray } from "./array/get.js";
3
3
  import { getString } from "./internal/string.js";
4
4
  /**
@@ -64,4 +64,4 @@ function isPrimitive(value) {
64
64
  }
65
65
  var EXPRESSION_PRIMITIVE = /^(bigint|boolean|number|string|symbol)$/;
66
66
  var EXPRESSION_WHITESPACE = /^\s*$/;
67
- export { isArrayOrPlainObject, isEmpty, isKey, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isPlainObject, isPrimitive, isTypedArray };
67
+ export { isArrayOrPlainObject, isConstructor, isEmpty, isKey, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isPlainObject, isPrimitive, isTypedArray };
package/dist/result.js CHANGED
@@ -51,7 +51,6 @@ function result(callback, err) {
51
51
  return getError(err ?? thrown, err == null ? void 0 : thrown);
52
52
  }
53
53
  }
54
- result.async = asyncResult;
55
54
  async function asyncResult(callback, err) {
56
55
  try {
57
56
  return ok(await callback());
@@ -62,4 +61,4 @@ async function asyncResult(callback, err) {
62
61
  function unwrap(value, defaultValue) {
63
62
  return isOk(value) ? value.value : defaultValue;
64
63
  }
65
- export { error, isError, isOk, isResult, ok, result, unwrap };
64
+ export { asyncResult, error, isError, isOk, isResult, ok, result, unwrap };
@@ -1,5 +1,5 @@
1
1
  import { getString, join, words } from "../internal/string.js";
2
2
  import { camelCase, capitalize, kebabCase, lowerCase, pascalCase, snakeCase, titleCase, upperCase } from "./case.js";
3
3
  import { endsWith, getUuid, includes, parse, startsWith, trim, truncate } from "./misc.js";
4
- import { template } from "./template.js";
5
- export { camelCase, capitalize, endsWith, getString, getUuid, includes, join, kebabCase, lowerCase, parse, pascalCase, snakeCase, startsWith, template, titleCase, trim, truncate, upperCase, words };
4
+ import { initializeTemplater, template } from "./template.js";
5
+ export { camelCase, capitalize, endsWith, getString, getUuid, includes, initializeTemplater, join, kebabCase, lowerCase, parse, pascalCase, snakeCase, startsWith, template, titleCase, trim, truncate, upperCase, words };
@@ -21,6 +21,17 @@ function handleTemplate(value, pattern, ignoreCase, variables) {
21
21
  });
22
22
  }
23
23
  /**
24
+ * Create a templater with predefined options
25
+ * @param options Templating options
26
+ * @returns Templater function
27
+ */
28
+ function initializeTemplater(options) {
29
+ const { ignoreCase, pattern } = getTemplateOptions(options);
30
+ return (value, variables) => {
31
+ return handleTemplate(value, pattern, ignoreCase, variables);
32
+ };
33
+ }
34
+ /**
24
35
  * Render a string from a template with variables
25
36
  * @param value Template string
26
37
  * @param variables Variables to use
@@ -31,16 +42,5 @@ function template(value, variables, options) {
31
42
  const { ignoreCase, pattern } = getTemplateOptions(options);
32
43
  return handleTemplate(value, pattern, ignoreCase, variables);
33
44
  }
34
- /**
35
- * Create a templater with predefined options
36
- * @param options Templating options
37
- * @returns Templater function
38
- */
39
- template.initialize = function(options) {
40
- const { ignoreCase, pattern } = getTemplateOptions(options);
41
- return (value, variables) => {
42
- return handleTemplate(value, pattern, ignoreCase, variables);
43
- };
44
- };
45
45
  var EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
46
- export { template };
46
+ export { initializeTemplater, template };
@@ -3,23 +3,21 @@ import { getSelfHandlers } from "../internal/value/handlers.js";
3
3
  function clone(value) {
4
4
  return cloneValue(value, 0, /* @__PURE__ */ new WeakMap());
5
5
  }
6
- clone.handlers = getSelfHandlers(clone, {
7
- callback: tryStructuredClone,
8
- method: "clone"
9
- });
10
6
  /**
11
7
  * Register a clone handler for a specific class
12
8
  * @param constructor Class constructor
13
9
  * @param handler Method name or clone function _(defaults to `clone`)_
14
10
  */
15
- clone.register = function(constructor, handler) {
16
- clone.handlers.register(constructor, handler);
17
- };
11
+ function registerCloner(constructor, handler) {
12
+ cloneHandlers.register(constructor, handler);
13
+ }
18
14
  /**
19
15
  * Unregister a clone handler for a specific class
20
16
  * @param constructor Class constructor
21
17
  */
22
- clone.unregister = clone.handlers.unregister;
18
+ function unregisterCloner(constructor) {
19
+ cloneHandlers.unregister(constructor);
20
+ }
23
21
  function cloneArrayBuffer(value, depth, references) {
24
22
  if (typeof depth === "number" && depth >= MAX_CLONE_DEPTH) return value;
25
23
  const cloned = new ArrayBuffer(value.byteLength);
@@ -98,7 +96,7 @@ function cloneValue(value, depth, references) {
98
96
  case value instanceof Node: return cloneNode(value, depth, references);
99
97
  case isArrayOrPlainObject(value): return clonePlainObject(value, depth, references);
100
98
  case isTypedArray(value): return cloneTypedArray(value, depth, references);
101
- default: return clone.handlers.handle(value, depth, references);
99
+ default: return cloneHandlers.handle(value, depth, references);
102
100
  }
103
101
  }
104
102
  function tryStructuredClone(value, depth, references) {
@@ -112,5 +110,9 @@ function tryStructuredClone(value, depth, references) {
112
110
  return value;
113
111
  }
114
112
  }
113
+ var cloneHandlers = getSelfHandlers(clone, {
114
+ callback: tryStructuredClone,
115
+ method: "clone"
116
+ });
115
117
  var MAX_CLONE_DEPTH = 100;
116
- export { clone };
118
+ export { clone, registerCloner, unregisterCloner };
@@ -1,11 +1,11 @@
1
- import { compare } from "../internal/value/compare.js";
1
+ import { compare, registerComparator, unregisterComparator } from "../internal/value/compare.js";
2
2
  import { setValue } from "../internal/value/set.js";
3
3
  import { getValue } from "../internal/value/get.js";
4
- import { equal } from "../internal/value/equal.js";
4
+ import { equal, initializeEqualizer, registerEqualizer, unregisterEqualizer } from "../internal/value/equal.js";
5
5
  import { clone } from "./clone.js";
6
6
  import { diff } from "./diff.js";
7
- import { merge } from "./merge.js";
7
+ import { initializeMerger, merge } from "./merge.js";
8
8
  import { partial } from "./partial.js";
9
9
  import { smush } from "./smush.js";
10
10
  import { unsmush } from "./unsmush.js";
11
- export { clone, compare, diff, equal, getValue, merge, partial, setValue, smush, unsmush };
11
+ export { clone, compare, diff, equal, getValue, initializeEqualizer, initializeMerger, merge, partial, registerComparator, registerEqualizer, setValue, smush, unregisterComparator, unregisterEqualizer, unsmush };