@oscarpalmer/atoms 0.217.0 → 0.219.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 (85) hide show
  1. package/dist/array/filter.d.mts +38 -4
  2. package/dist/array/find.d.mts +34 -0
  3. package/dist/array/first.d.mts +40 -4
  4. package/dist/array/insert.mjs +1 -1
  5. package/dist/array/last.d.mts +46 -10
  6. package/dist/array/partition.d.mts +24 -8
  7. package/dist/array/reverse.d.mts +6 -0
  8. package/dist/array/reverse.mjs +6 -0
  9. package/dist/array/select.d.mts +97 -116
  10. package/dist/array/select.mjs +19 -15
  11. package/dist/array/single.d.mts +22 -0
  12. package/dist/array/single.mjs +1 -1
  13. package/dist/array/slice.mjs +27 -14
  14. package/dist/array/sort.d.mts +54 -0
  15. package/dist/array/sort.mjs +2 -1
  16. package/dist/color/misc/get.mjs +3 -1
  17. package/dist/color/space/hex.d.mts +8 -0
  18. package/dist/color/space/hex.mjs +9 -1
  19. package/dist/function/retry.d.mts +1 -1
  20. package/dist/function/retry.mjs +5 -2
  21. package/dist/index.d.mts +879 -324
  22. package/dist/index.mjs +480 -173
  23. package/dist/internal/array/callbacks.mjs +1 -1
  24. package/dist/internal/array/find.d.mts +3 -3
  25. package/dist/internal/array/find.mjs +90 -48
  26. package/dist/internal/array/insert.mjs +1 -1
  27. package/dist/internal/array/match.mjs +21 -17
  28. package/dist/internal/array/sets.mjs +7 -1
  29. package/dist/internal/array/shuffle.d.mts +5 -0
  30. package/dist/internal/array/shuffle.mjs +5 -0
  31. package/dist/internal/math/aggregate.d.mts +69 -21
  32. package/dist/internal/math/aggregate.mjs +4 -1
  33. package/dist/internal/math/misc.d.mts +14 -0
  34. package/dist/internal/math/misc.mjs +14 -0
  35. package/dist/internal/number.d.mts +19 -1
  36. package/dist/internal/number.mjs +22 -2
  37. package/dist/internal/plan/plan.generate.mjs +3 -3
  38. package/dist/internal/random.d.mts +6 -0
  39. package/dist/internal/random.mjs +13 -2
  40. package/dist/internal/result/attempt.mjs +4 -4
  41. package/dist/internal/string/case.d.mts +63 -0
  42. package/dist/internal/string/case.mjs +63 -0
  43. package/dist/internal/string/misc.d.mts +20 -0
  44. package/dist/internal/string/misc.mjs +22 -1
  45. package/dist/internal/subscription.mjs +1 -1
  46. package/dist/internal/value/equal.mjs +2 -1
  47. package/dist/internal/value/partial.mjs +3 -1
  48. package/dist/logger.d.mts +12 -0
  49. package/dist/logger.mjs +12 -0
  50. package/dist/math.d.mts +90 -0
  51. package/dist/math.mjs +7 -0
  52. package/dist/models/array/array.find.model.d.mts +26 -0
  53. package/dist/models/array/array.misc.model.d.mts +2 -4
  54. package/dist/models/index.d.mts +1 -1
  55. package/dist/models/plan.model.d.mts +2 -0
  56. package/dist/models/plan.model.mjs +3 -1
  57. package/dist/models/string/string.fuzzy.model.d.mts +1 -1
  58. package/dist/models/string/string.misc.model.mjs +1 -1
  59. package/dist/models/value/value.merge.model.d.mts +4 -4
  60. package/dist/plan/index.d.mts +1 -4
  61. package/dist/plan/index.mjs +2 -3
  62. package/dist/plan/use.mjs +4 -4
  63. package/dist/promise/index.d.mts +6 -4
  64. package/dist/promise/index.mjs +4 -4
  65. package/dist/promise/misc.d.mts +6 -0
  66. package/dist/promise/misc.mjs +11 -2
  67. package/dist/promise/timed.d.mts +3 -0
  68. package/dist/promise/timed.mjs +5 -2
  69. package/dist/queue.d.mts +0 -1
  70. package/dist/queue.mjs +5 -6
  71. package/dist/random.d.mts +2 -2
  72. package/dist/random.mjs +3 -3
  73. package/dist/result/match.mjs +2 -2
  74. package/dist/result/misc.mjs +3 -10
  75. package/dist/result/work/pipe.d.mts +24 -22
  76. package/dist/result/work/pipe.mjs +7 -3
  77. package/dist/string/fuzzy.mjs +1 -1
  78. package/dist/string/index.d.mts +15 -1
  79. package/dist/string/index.mjs +16 -2
  80. package/dist/string/match.d.mts +24 -0
  81. package/dist/string/match.mjs +24 -0
  82. package/dist/string/template.d.mts +4 -0
  83. package/dist/value/clone.mjs +1 -1
  84. package/dist/value/merge.mjs +17 -4
  85. package/package.json +1 -1
@@ -1,4 +1,10 @@
1
1
  //#region src/internal/random.d.ts
2
+ /**
3
+ * Get a random number between 0 _(inclusive)_ and 1 _(exclusive)_
4
+ *
5
+ * @returns Random number
6
+ */
7
+ export declare function getRandom(): number;
2
8
  /**
3
9
  * Get a random floating-point number
4
10
  *
@@ -1,12 +1,22 @@
1
1
  import { isNumber } from "./is.mjs";
2
2
  import { floor } from "./math/misc.mjs";
3
3
  //#region src/internal/random.ts
4
+ /**
5
+ * Get a random number between 0 _(inclusive)_ and 1 _(exclusive)_
6
+ *
7
+ * @returns Random number
8
+ */
9
+ function getRandom() {
10
+ /* istanbul ignore if */
11
+ if (globalThis.crypto == null) return Math.random();
12
+ return globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(1))[0] / RANDOM_DIVISOR;
13
+ }
4
14
  function getRandomFloatingNumberValue(inclusive, minimum, maximum) {
5
15
  let maxFloat = isNumber(maximum) && maximum <= Number.MAX_SAFE_INTEGER ? maximum : Number.MAX_SAFE_INTEGER;
6
16
  let minFloat = isNumber(minimum) && minimum >= Number.MIN_SAFE_INTEGER ? minimum : Number.MIN_SAFE_INTEGER;
7
17
  if (minFloat === maxFloat) return minFloat;
8
18
  if (minFloat > maxFloat) [minFloat, maxFloat] = [maxFloat, minFloat];
9
- return Math.random() * (maxFloat + (inclusive ? 1 : 0) - minFloat) + minFloat;
19
+ return getRandom() * (maxFloat + (inclusive ? 1 : 0) - minFloat) + minFloat;
10
20
  }
11
21
  /**
12
22
  * Get a random floating-point number
@@ -28,5 +38,6 @@ function getRandomFloatingNumber(minimum, maximum) {
28
38
  function getRandomInteger(minimum, maximum) {
29
39
  return floor(getRandomFloatingNumberValue(true, minimum, maximum));
30
40
  }
41
+ const RANDOM_DIVISOR = 2 ** 32;
31
42
  //#endregion
32
- export { getRandomFloatingNumber, getRandomInteger };
43
+ export { getRandom, getRandomFloatingNumber, getRandomInteger };
@@ -7,16 +7,16 @@ async function asyncAttempt(value, err) {
7
7
  else result = value;
8
8
  if (result instanceof Promise) result = await result;
9
9
  return ok(result);
10
- } catch (thrown) {
11
- return getError(err ?? thrown, err == null ? void 0 : thrown);
10
+ } catch (error) {
11
+ return getError(err ?? error, err == null ? void 0 : error);
12
12
  }
13
13
  }
14
14
  function attempt(callback, err) {
15
15
  try {
16
16
  const value = callback();
17
17
  return ok(value);
18
- } catch (thrown) {
19
- return getError(err ?? thrown, err == null ? void 0 : thrown);
18
+ } catch (error) {
19
+ return getError(err ?? error, err == null ? void 0 : error);
20
20
  }
21
21
  }
22
22
  attempt.async = asyncAttempt;
@@ -4,6 +4,14 @@
4
4
  *
5
5
  * @param value String to convert
6
6
  * @returns Camel-cased string
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * camelCase('this is camel case'); // => 'thisIsCamelCase'
11
+ * camelCase('ThisIsCamelCase'); // => 'thisIsCamelCase'
12
+ * camelCase('this-is-camel-case'); // => 'thisIsCamelCase'
13
+ * camelCase('this_is_camel_case'); // => 'thisIsCamelCase'
14
+ * ```
7
15
  */
8
16
  export declare function camelCase(value: string): string;
9
17
  /**
@@ -11,6 +19,14 @@ export declare function camelCase(value: string): string;
11
19
  *
12
20
  * @param value String to capitalize
13
21
  * @returns Capitalized string
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * capitalize('this is a test'); // => 'This is a test'
26
+ * capitalize('This Is A Test'); // => 'This is a test'
27
+ * capitalize('t'); // => 'T'
28
+ * capitalize(''); // => ''
29
+ * ```
14
30
  */
15
31
  export declare function capitalize(value: string): string;
16
32
  /**
@@ -18,6 +34,14 @@ export declare function capitalize(value: string): string;
18
34
  *
19
35
  * @param value String to convert
20
36
  * @returns Kebab-cased string
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * kebabCase('this is kebab case'); // => 'this-is-kebab-case'
41
+ * kebabCase('ThisIsKebabCase'); // => 'this-is-kebab-case'
42
+ * kebabCase('this-is-kebab-case'); // => 'this-is-kebab-case'
43
+ * kebabCase('this_is_kebab_case'); // => 'this-is-kebab-case'
44
+ * ```
21
45
  */
22
46
  export declare function kebabCase(value: string): string;
23
47
  /**
@@ -25,6 +49,13 @@ export declare function kebabCase(value: string): string;
25
49
  *
26
50
  * @param value String to convert
27
51
  * @returns Lower-cased string
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * lowerCase('THIS IS A TEST'); // => 'this is a test'
56
+ * lowerCase('this is a test'); // => 'this is a test'
57
+ * lowerCase('t'); // => 't'
58
+ * ```
28
59
  */
29
60
  export declare function lowerCase(value: string): string;
30
61
  /**
@@ -32,6 +63,14 @@ export declare function lowerCase(value: string): string;
32
63
  *
33
64
  * @param value String to convert
34
65
  * @returns Pascal-cased string
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * pascalCase('this is pascal case'); // => 'ThisIsPascalCase'
70
+ * pascalCase('ThisIsPascalCase'); // => 'ThisIsPascalCase'
71
+ * pascalCase('this-is-pascal-case'); // => 'ThisIsPascalCase'
72
+ * pascalCase('this_is_pascal_case'); // => 'ThisIsPascalCase'
73
+ * ```
35
74
  */
36
75
  export declare function pascalCase(value: string): string;
37
76
  /**
@@ -39,6 +78,14 @@ export declare function pascalCase(value: string): string;
39
78
  *
40
79
  * @param value String to convert
41
80
  * @returns Snake-cased string
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * snakeCase('this is snake case'); // => 'this_is_snake_case'
85
+ * snakeCase('ThisIsSnakeCase'); // => 'this_is_snake_case'
86
+ * snakeCase('this-is-snake-case'); // => 'this_is_snake_case'
87
+ * snakeCase('this_is_snake_case'); // => 'this_is_snake_case'
88
+ * ```
42
89
  */
43
90
  export declare function snakeCase(value: string): string;
44
91
  /**
@@ -46,6 +93,14 @@ export declare function snakeCase(value: string): string;
46
93
  *
47
94
  * @param value String to convert
48
95
  * @returns Title-cased string
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * titleCase('this is a test'); // => 'This Is A Test'
100
+ * titleCase('This Is A Test'); // => 'This Is A Test'
101
+ * titleCase('t'); // => 'T'
102
+ * titleCase(''); // => ''
103
+ * ```
49
104
  */
50
105
  export declare function titleCase(value: string): string;
51
106
  /**
@@ -53,6 +108,14 @@ export declare function titleCase(value: string): string;
53
108
  *
54
109
  * @param value String to convert
55
110
  * @returns Upper-cased string
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * upperCase('this is a test'); // => 'THIS IS A TEST'
115
+ * upperCase('This Is A Test'); // => 'THIS IS A TEST'
116
+ * upperCase('t'); // => 'T'
117
+ * upperCase(''); // => ''
118
+ * ```
56
119
  */
57
120
  export declare function upperCase(value: string): string;
58
121
  //#endregion
@@ -7,6 +7,14 @@ import { STRING_CASE_CAMEL, STRING_CASE_KEBAB, STRING_CASE_PASCAL, STRING_CASE_S
7
7
  *
8
8
  * @param value String to convert
9
9
  * @returns Camel-cased string
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * camelCase('this is camel case'); // => 'thisIsCamelCase'
14
+ * camelCase('ThisIsCamelCase'); // => 'thisIsCamelCase'
15
+ * camelCase('this-is-camel-case'); // => 'thisIsCamelCase'
16
+ * camelCase('this_is_camel_case'); // => 'thisIsCamelCase'
17
+ * ```
10
18
  */
11
19
  function camelCase(value) {
12
20
  return toCase(STRING_CASE_CAMEL, value, true, false);
@@ -16,6 +24,14 @@ function camelCase(value) {
16
24
  *
17
25
  * @param value String to capitalize
18
26
  * @returns Capitalized string
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * capitalize('this is a test'); // => 'This is a test'
31
+ * capitalize('This Is A Test'); // => 'This is a test'
32
+ * capitalize('t'); // => 'T'
33
+ * capitalize(''); // => ''
34
+ * ```
19
35
  */
20
36
  function capitalize(value) {
21
37
  if (typeof value !== "string" || value.length === 0) return "";
@@ -27,6 +43,14 @@ function capitalize(value) {
27
43
  *
28
44
  * @param value String to convert
29
45
  * @returns Kebab-cased string
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * kebabCase('this is kebab case'); // => 'this-is-kebab-case'
50
+ * kebabCase('ThisIsKebabCase'); // => 'this-is-kebab-case'
51
+ * kebabCase('this-is-kebab-case'); // => 'this-is-kebab-case'
52
+ * kebabCase('this_is_kebab_case'); // => 'this-is-kebab-case'
53
+ * ```
30
54
  */
31
55
  function kebabCase(value) {
32
56
  return toCase(STRING_CASE_KEBAB, value, false, false);
@@ -36,6 +60,13 @@ function kebabCase(value) {
36
60
  *
37
61
  * @param value String to convert
38
62
  * @returns Lower-cased string
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * lowerCase('THIS IS A TEST'); // => 'this is a test'
67
+ * lowerCase('this is a test'); // => 'this is a test'
68
+ * lowerCase('t'); // => 't'
69
+ * ```
39
70
  */
40
71
  function lowerCase(value) {
41
72
  if (typeof value !== "string") return "";
@@ -47,6 +78,14 @@ function lowerCase(value) {
47
78
  *
48
79
  * @param value String to convert
49
80
  * @returns Pascal-cased string
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * pascalCase('this is pascal case'); // => 'ThisIsPascalCase'
85
+ * pascalCase('ThisIsPascalCase'); // => 'ThisIsPascalCase'
86
+ * pascalCase('this-is-pascal-case'); // => 'ThisIsPascalCase'
87
+ * pascalCase('this_is_pascal_case'); // => 'ThisIsPascalCase'
88
+ * ```
50
89
  */
51
90
  function pascalCase(value) {
52
91
  return toCase(STRING_CASE_PASCAL, value, true, true);
@@ -56,6 +95,14 @@ function pascalCase(value) {
56
95
  *
57
96
  * @param value String to convert
58
97
  * @returns Snake-cased string
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * snakeCase('this is snake case'); // => 'this_is_snake_case'
102
+ * snakeCase('ThisIsSnakeCase'); // => 'this_is_snake_case'
103
+ * snakeCase('this-is-snake-case'); // => 'this_is_snake_case'
104
+ * snakeCase('this_is_snake_case'); // => 'this_is_snake_case'
105
+ * ```
59
106
  */
60
107
  function snakeCase(value) {
61
108
  return toCase(STRING_CASE_SNAKE, value, false, false);
@@ -65,6 +112,14 @@ function snakeCase(value) {
65
112
  *
66
113
  * @param value String to convert
67
114
  * @returns Title-cased string
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * titleCase('this is a test'); // => 'This Is A Test'
119
+ * titleCase('This Is A Test'); // => 'This Is A Test'
120
+ * titleCase('t'); // => 'T'
121
+ * titleCase(''); // => ''
122
+ * ```
68
123
  */
69
124
  function titleCase(value) {
70
125
  if (typeof value !== "string" || value.length === 0) return "";
@@ -107,6 +162,14 @@ function toCaseCallback(value) {
107
162
  *
108
163
  * @param value String to convert
109
164
  * @returns Upper-cased string
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * upperCase('this is a test'); // => 'THIS IS A TEST'
169
+ * upperCase('This Is A Test'); // => 'THIS IS A TEST'
170
+ * upperCase('t'); // => 'T'
171
+ * upperCase(''); // => ''
172
+ * ```
110
173
  */
111
174
  function upperCase(value) {
112
175
  if (typeof value !== "string" || value.length === 0) return "";
@@ -17,7 +17,13 @@
17
17
  * ```
18
18
  */
19
19
  export declare function getString(value: unknown): string;
20
+ /**
21
+ * @internal
22
+ */
20
23
  export declare function ignoreKey(key: string): boolean;
24
+ /**
25
+ * @internal
26
+ */
21
27
  export declare function interpolate(strings: TemplateStringsArray, values: unknown[]): string;
22
28
  /**
23
29
  * Join an array of values into a string _(while ignoring empty values)_
@@ -27,9 +33,23 @@ export declare function interpolate(strings: TemplateStringsArray, values: unkno
27
33
  * @param array Array of values
28
34
  * @param delimiter Delimiter to use between values
29
35
  * @returns Joined string
36
+ * @example
37
+ * ```typescript
38
+ * join(['a', 'b', 'c']); // => 'abc'
39
+ * join(['a', 'b', 'c'], ', '); // => 'a, b, c'
40
+ * join(['a', '', 'c']); // => 'ac'
41
+ * join([null, 'b', undefined]); // => 'b'
42
+ * join([]); // => ''
43
+ * ```
30
44
  */
31
45
  export declare function join(array: unknown[], delimiter?: string): string;
46
+ /**
47
+ * @internal
48
+ */
32
49
  export declare function tryDecode(value: string): string;
50
+ /**
51
+ * @internal
52
+ */
33
53
  export declare function tryEncode(value: boolean | number | string): unknown;
34
54
  /**
35
55
  * Split a string into words _(and other readable parts)_
@@ -27,9 +27,15 @@ function getString(value) {
27
27
  const asString = String(value.valueOf?.() ?? value);
28
28
  return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
29
29
  }
30
+ /**
31
+ * @internal
32
+ */
30
33
  function ignoreKey(key) {
31
34
  return STRING_EXPRESSION_IGNORED.test(key);
32
35
  }
36
+ /**
37
+ * @internal
38
+ */
33
39
  function interpolate(strings, values) {
34
40
  const { length } = strings;
35
41
  let interpolated = "";
@@ -47,6 +53,14 @@ function interpolate(strings, values) {
47
53
  * @param array Array of values
48
54
  * @param delimiter Delimiter to use between values
49
55
  * @returns Joined string
56
+ * @example
57
+ * ```typescript
58
+ * join(['a', 'b', 'c']); // => 'abc'
59
+ * join(['a', 'b', 'c'], ', '); // => 'a, b, c'
60
+ * join(['a', '', 'c']); // => 'ac'
61
+ * join([null, 'b', undefined]); // => 'b'
62
+ * join([]); // => ''
63
+ * ```
50
64
  */
51
65
  function join(array, delimiter) {
52
66
  if (!Array.isArray(array)) return "";
@@ -62,9 +76,15 @@ function join(array, delimiter) {
62
76
  function tryCallback(value, callback) {
63
77
  return unwrap(attempt(() => callback(value)), value);
64
78
  }
79
+ /**
80
+ * @internal
81
+ */
65
82
  function tryDecode(value) {
66
83
  return tryCallback(value, decodeURIComponent);
67
84
  }
85
+ /**
86
+ * @internal
87
+ */
68
88
  function tryEncode(value) {
69
89
  return tryCallback(value, encodeURIComponent);
70
90
  }
@@ -75,7 +95,8 @@ function tryEncode(value) {
75
95
  * @returns Array of words found in the string
76
96
  */
77
97
  function words(value) {
78
- return typeof value === "string" ? value.match(STRING_EXPRESSION_WORDS) ?? [] : [];
98
+ if (typeof value === "string") return value.match(STRING_EXPRESSION_WORDS) ?? [];
99
+ return [];
79
100
  }
80
101
  //#endregion
81
102
  export { getString, ignoreKey, interpolate, join, tryDecode, tryEncode, words };
@@ -125,7 +125,7 @@ function createSubscriptionsProperty(input) {
125
125
  const values = isPlainObject(input) ? input : {};
126
126
  return {
127
127
  key: typeof values.key === "string" ? values.key : SUBSCRIPTION_PROPERTY,
128
- value: values.value == null ? SUBSCRIPTION_NAME : values.value
128
+ value: values.value ?? "subscription"
129
129
  };
130
130
  }
131
131
  function createSubscriptionsState(property, keys) {
@@ -1,5 +1,6 @@
1
1
  import { isNonPlainObject, isPlainObject, isPrimitive, isTypedArray } from "../is.mjs";
2
2
  import { round } from "../math/misc.mjs";
3
+ import { min } from "../math/aggregate.mjs";
3
4
  import { createCompareHandler } from "./handlers.mjs";
4
5
  import { EQUAL_ERROR_PROPERTIES, EQUAL_EXPRESSION_PROPERTIES, EQUAL_SYMBOL } from "../../models/value/value.equal.model.mjs";
5
6
  //#region src/internal/value/equal.ts
@@ -63,7 +64,7 @@ function equalArray(first, second, options) {
63
64
  let offset = 0;
64
65
  if (length >= 100) {
65
66
  offset = round(length / 10);
66
- offset = offset > 100 ? 100 : offset;
67
+ offset = min([offset, 100]);
67
68
  for (let index = 0; index < offset; index += 1) if (!(equalValue(first[index], second[index], options) && equalValue(first[length - index - 1], second[length - index - 1], options))) return false;
68
69
  }
69
70
  const end = length - offset;
@@ -2,7 +2,9 @@ import { isPlainObject } from "../is.mjs";
2
2
  //#region src/internal/value/partial.ts
3
3
  function partial(value, providedKeys, omit) {
4
4
  if (!isPlainObject(value)) return {};
5
- const keys = omit ? Object.keys(value) : Array.isArray(providedKeys) ? providedKeys : [];
5
+ let keys;
6
+ if (omit) keys = Object.keys(value);
7
+ else keys = Array.isArray(providedKeys) ? providedKeys : [];
6
8
  const { length } = keys;
7
9
  if (length === 0) return omit ? value : {};
8
10
  const partials = {};
package/dist/logger.d.mts CHANGED
@@ -1,7 +1,19 @@
1
1
  import { Lumberjack, TimeLogger } from "./models/logger.model.mjs";
2
2
  //#region src/logger.d.ts
3
3
  declare function TimeLogger(this: any, label: string): void;
4
+ /**
5
+ * Is the value a _Logger_?
6
+ *
7
+ * @param value Value to check
8
+ * @returns `true` if the value is a _Logger_, otherwise `false`
9
+ */
4
10
  declare function isLogger(value: unknown): value is Lumberjack;
11
+ /**
12
+ * Is the value a _TimeLogger_?
13
+ *
14
+ * @param value Value to check
15
+ * @returns `true` if the value is a _TimeLogger_, otherwise `false`
16
+ */
5
17
  declare function isTimeLogger(value: unknown): value is TimeLogger;
6
18
  /**
7
19
  * A logger that can be used to log messages to the console
package/dist/logger.mjs CHANGED
@@ -64,12 +64,24 @@ function getTimeLoggerStop() {
64
64
  }
65
65
  return noop;
66
66
  }
67
+ /**
68
+ * Is the value a _Logger_?
69
+ *
70
+ * @param value Value to check
71
+ * @returns `true` if the value is a _Logger_, otherwise `false`
72
+ */
67
73
  function isLogger(value) {
68
74
  return isLoggerInstance(LOGGER_NAME, value);
69
75
  }
70
76
  function isLoggerInstance(name, value) {
71
77
  return typeof value === "object" && value !== null && "$logger" in value && value["$logger"] === name;
72
78
  }
79
+ /**
80
+ * Is the value a _TimeLogger_?
81
+ *
82
+ * @param value Value to check
83
+ * @returns `true` if the value is a _TimeLogger_, otherwise `false`
84
+ */
73
85
  function isTimeLogger(value) {
74
86
  return isLoggerInstance(LOGGER_NAME_TIMED, value);
75
87
  }
package/dist/math.d.mts CHANGED
@@ -8,6 +8,16 @@ import { floor, round } from "./internal/math/misc.mjs";
8
8
  * @param items List of items
9
9
  * @param callback Callback to get an item's value
10
10
  * @returns Average value, or `Number.NaN` if no average can be calculated
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * average([
15
+ * {value: 1},
16
+ * {value: 2},
17
+ * {value: 3},
18
+ * ], item => item.value); // => 2
19
+ * average([{value: 1}], item => item.nope); // => Number.NaN
20
+ * ```
11
21
  */
12
22
  export declare function average<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
13
23
  /**
@@ -16,6 +26,12 @@ export declare function average<Item>(items: Item[], callback: (item: Item, inde
16
26
  * @param items List of items
17
27
  * @param key Key to use for value
18
28
  * @returns Average value, or `Number.NaN` if no average can be calculated
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * average([{value: 1}, {value: 2}, {value: 3}], 'value'); // => 2
33
+ * average([{value: 1}], 'nope'); // => Number.NaN
34
+ * ```
19
35
  */
20
36
  export declare function average<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): number;
21
37
  /**
@@ -23,6 +39,12 @@ export declare function average<Item extends PlainObject>(items: Item[], key: ke
23
39
  *
24
40
  * @param numbers List of numbers
25
41
  * @returns Average value, or `Number.NaN` if no average can be calculated
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * average([1, 2, 3, 4, 5]); // => 3
46
+ * average([]); // => Number.NaN
47
+ * ```
26
48
  */
27
49
  export declare function average(numbers: number[]): number;
28
50
  /**
@@ -31,6 +53,13 @@ export declare function average(numbers: number[]): number;
31
53
  * @param value Number to round up
32
54
  * @param decimals Number of decimal places to round to _(defaults to `0`)_
33
55
  * @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * ceil(1.234, 2); // => 1.24
60
+ * ceil(1.234); // => 2
61
+ * ceil('abc'); // => Number.NaN
62
+ * ```
34
63
  */
35
64
  export declare function ceil(value: number, decimals?: number): number;
36
65
  /**
@@ -40,6 +69,14 @@ export declare function ceil(value: number, decimals?: number): number;
40
69
  * @param callback Callback to get an item's value
41
70
  * @param value Value to match and count
42
71
  * @returns Number of items that match the condition, or `Number.NaN` if no count can be calculated
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * count([1, 2, 3, 2], (item) => item, 2); // => 2
76
+ * count([{value: 1}, {value: 2}, {value: 3}], 'value', 2); // => 1
77
+ * count([1, 2, 3], (item) => item, 4); // => 0
78
+ * count([], (item) => item, 1); // => Number.NaN
79
+ * ```
43
80
  */
44
81
  export declare function count<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => unknown, value: unknown): number;
45
82
  /**
@@ -49,6 +86,12 @@ export declare function count<Item>(array: Item[], callback: (item: Item, index:
49
86
  * @param key Key to use for value
50
87
  * @param value Value to match and count
51
88
  * @returns Number of items with the specified key value, or `Number.NaN` if no count can be calculated
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * count([{value: 1}, {value: 2}, {value: 3}], 'value', 2); // => 1
93
+ * count([{value: 1}], 'nope', 1); // => Number.NaN
94
+ * ```
52
95
  */
53
96
  export declare function count<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
54
97
  /**
@@ -56,6 +99,12 @@ export declare function count<Item extends PlainObject, ItemKey extends keyof It
56
99
  *
57
100
  * @param values Array to count for
58
101
  * @returns Number of items, or `Number.NaN` if no count can be calculated
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * count([1, 2, 3]); // => 3
106
+ * count([]); // => Number.NaN
107
+ * ```
59
108
  */
60
109
  export declare function count(values: unknown[]): number;
61
110
  /**
@@ -64,6 +113,13 @@ export declare function count(values: unknown[]): number;
64
113
  * @param array List of items
65
114
  * @param callback Callback to get an item's value
66
115
  * @returns Median value, or `Number.NaN` if no median can be calculated
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * median([1, 2, 3, 4, 5]); // => 3
120
+ * median([1, 2, 3, 4]); // => 2.5
121
+ * median([]); // => Number.NaN
122
+ * ```
67
123
  */
68
124
  export declare function median<Item>(array: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
69
125
  /**
@@ -72,6 +128,13 @@ export declare function median<Item>(array: Item[], callback: (item: Item, index
72
128
  * @param array List of items
73
129
  * @param key Key to use for value
74
130
  * @returns Median value, or `Number.NaN` if no median can be calculated
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * median([{value: 1}, {value: 2}, {value: 3}], 'value'); // => 2
135
+ * median([{value: 1}, {value: 2}, {value: 3}, {value: 4}], 'value'); // => 2.5
136
+ * median([], 'value'); // => Number.NaN
137
+ * ```
75
138
  */
76
139
  export declare function median<Item extends PlainObject>(array: Item[], key: keyof NumericalValues<Item>): number;
77
140
  /**
@@ -79,6 +142,13 @@ export declare function median<Item extends PlainObject>(array: Item[], key: key
79
142
  *
80
143
  * @param array List of numbers
81
144
  * @returns Median value, or `Number.NaN` if no median can be calculated
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * median([1, 2, 3, 4, 5]); // => 3
149
+ * median([1, 2, 3, 4]); // => 2.5
150
+ * median([]); // => Number.NaN
151
+ * ```
82
152
  */
83
153
  export declare function median(array: number[]): number;
84
154
  /**
@@ -87,6 +157,13 @@ export declare function median(array: number[]): number;
87
157
  * @param items List of items
88
158
  * @param callback Callback to get an item's value
89
159
  * @returns Sum of the values, or `Number.NaN` if no sum can be calculated
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * sum([{value: 1}, {value: 2}, {value: 3}], 'value'); // => 6
164
+ * sum([{value: 1}, {value: 2}, {value: 3}], item => item.value); // => 6
165
+ * sum([]); // => Number.NaN
166
+ * ```
90
167
  */
91
168
  export declare function sum<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): number;
92
169
  /**
@@ -95,6 +172,13 @@ export declare function sum<Item>(items: Item[], callback: (item: Item, index: n
95
172
  * @param items List of items
96
173
  * @param key Key to use for value
97
174
  * @returns Sum of the values, or `Number.NaN` if no sum can be calculated
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * sum([{value: 1}, {value: 2}, {value: 3}], 'value'); // => 6
179
+ * sum([{value: 1}, {value: 2}, {value: 3}], item => item.value); // => 6
180
+ * sum([]); // => Number.NaN
181
+ * ```
98
182
  */
99
183
  export declare function sum<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): number;
100
184
  /**
@@ -102,6 +186,12 @@ export declare function sum<Item extends PlainObject>(items: Item[], key: keyof
102
186
  *
103
187
  * @param values List of numbers
104
188
  * @returns Sum of the numbers, or `Number.NaN` if no sum can be calculated
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * sum([1, 2, 3]); // => 6
193
+ * sum([]); // => Number.NaN
194
+ * ```
105
195
  */
106
196
  export declare function sum(values: number[]): number;
107
197
  //#endregion
package/dist/math.mjs CHANGED
@@ -13,6 +13,13 @@ function average(array, key) {
13
13
  * @param value Number to round up
14
14
  * @param decimals Number of decimal places to round to _(defaults to `0`)_
15
15
  * @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * ceil(1.234, 2); // => 1.24
20
+ * ceil(1.234); // => 2
21
+ * ceil('abc'); // => Number.NaN
22
+ * ```
16
23
  */
17
24
  function ceil(value, decimals) {
18
25
  return roundNumber(Math.ceil, value, decimals);