@oscarpalmer/atoms 0.218.0 → 0.220.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 (54) 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/last.d.mts +46 -10
  5. package/dist/array/partition.d.mts +24 -8
  6. package/dist/array/reverse.d.mts +6 -0
  7. package/dist/array/reverse.mjs +6 -0
  8. package/dist/array/select.d.mts +97 -116
  9. package/dist/array/select.mjs +19 -15
  10. package/dist/array/single.d.mts +22 -0
  11. package/dist/array/single.mjs +1 -1
  12. package/dist/array/sort.d.mts +54 -0
  13. package/dist/color/space/hex.d.mts +8 -0
  14. package/dist/color/space/hex.mjs +8 -0
  15. package/dist/index.d.mts +764 -189
  16. package/dist/index.mjs +508 -207
  17. package/dist/internal/array/callbacks.mjs +1 -1
  18. package/dist/internal/array/find.d.mts +3 -3
  19. package/dist/internal/array/find.mjs +71 -52
  20. package/dist/internal/array/shuffle.d.mts +5 -0
  21. package/dist/internal/array/shuffle.mjs +5 -0
  22. package/dist/internal/math/aggregate.d.mts +69 -21
  23. package/dist/internal/math/misc.d.mts +14 -0
  24. package/dist/internal/math/misc.mjs +14 -0
  25. package/dist/internal/number.d.mts +18 -0
  26. package/dist/internal/number.mjs +18 -0
  27. package/dist/internal/string/case.d.mts +63 -0
  28. package/dist/internal/string/case.mjs +63 -0
  29. package/dist/internal/string/misc.d.mts +20 -0
  30. package/dist/internal/string/misc.mjs +20 -0
  31. package/dist/logger.d.mts +12 -0
  32. package/dist/logger.mjs +12 -0
  33. package/dist/math.d.mts +90 -0
  34. package/dist/math.mjs +7 -0
  35. package/dist/models/array/array.find.model.d.mts +26 -0
  36. package/dist/models/array/array.misc.model.d.mts +2 -4
  37. package/dist/models/index.d.mts +1 -1
  38. package/dist/models/string/string.fuzzy.model.d.mts +46 -18
  39. package/dist/models/string/string.fuzzy.model.mjs +3 -1
  40. package/dist/models/value/value.merge.model.d.mts +3 -3
  41. package/dist/promise/misc.d.mts +6 -0
  42. package/dist/promise/misc.mjs +6 -0
  43. package/dist/promise/timed.d.mts +3 -0
  44. package/dist/promise/timed.mjs +3 -0
  45. package/dist/queue.d.mts +0 -1
  46. package/dist/queue.mjs +1 -1
  47. package/dist/string/fuzzy.d.mts +3 -3
  48. package/dist/string/fuzzy.mjs +171 -97
  49. package/dist/string/index.d.mts +15 -1
  50. package/dist/string/index.mjs +15 -1
  51. package/dist/string/match.d.mts +24 -0
  52. package/dist/string/match.mjs +24 -0
  53. package/dist/string/template.d.mts +4 -0
  54. package/package.json +1 -1
@@ -3,7 +3,7 @@ function getArrayCallback(value) {
3
3
  switch (typeof value) {
4
4
  case "function": return value;
5
5
  case "number":
6
- case "string": return typeof value === "string" && value.includes(".") ? void 0 : (obj) => obj[value];
6
+ case "string": return (obj) => obj?.[value];
7
7
  default: return;
8
8
  }
9
9
  }
@@ -1,8 +1,8 @@
1
- import { ArrayFindMapper, ArrayFindValueType, ArrayFindValuesResult, ArrayFindValuesType, ArrayParameters } from "../../models/array/array.find.model.mjs";
1
+ import { ArrayFindOptions, ArrayFindValueType, ArrayFindValuesResult, ArrayFindValuesType, ArrayParameters } from "../../models/array/array.find.model.mjs";
2
2
  //#region src/internal/array/find.d.ts
3
3
  export declare function createFindParameters(original: unknown[]): ArrayParameters;
4
+ export declare function findAbsoluteValueOrDefault(array: unknown[], parameters: unknown[], defaultValue: unknown, useDefaultValue: boolean, reversed: boolean): unknown;
4
5
  export declare function findValue(type: Exclude<ArrayFindValueType, "item">, array: unknown[], parameters: unknown[], reversed: boolean): number;
5
6
  export declare function findValue(type: Exclude<ArrayFindValueType, "index">, array: unknown[], parameters: unknown[], reversed: boolean): unknown;
6
- export declare function findAbsoluteValueOrDefault(array: unknown[], parameters: unknown[], defaultValue: unknown, useDefaultValue: boolean, reversed: boolean): unknown;
7
- export declare function findValues(type: ArrayFindValuesType, array: unknown[], parameters: unknown[], mapper?: ArrayFindMapper): ArrayFindValuesResult;
7
+ export declare function findValues(type: ArrayFindValuesType, array: unknown[], parameters: unknown[], options?: ArrayFindOptions): ArrayFindValuesResult;
8
8
  //#endregion
@@ -1,6 +1,15 @@
1
1
  import { ARRAY_FIND_VALUE_INDEX } from "../../models/array/array.find.model.mjs";
2
2
  import { getArrayCallback, getArrayCallbacks } from "./callbacks.mjs";
3
3
  //#region src/internal/array/find.ts
4
+ function addResult(result, mapped, flat) {
5
+ if (!flat) {
6
+ result.matched.push(mapped);
7
+ return;
8
+ }
9
+ const array = Array.isArray(mapped) ? mapped : [mapped];
10
+ const { length } = array;
11
+ for (let index = 0; index < length; index += 1) result.matched.push(array[index]);
12
+ }
4
13
  function createFindParameters(original) {
5
14
  const { length } = original;
6
15
  return {
@@ -9,24 +18,27 @@ function createFindParameters(original) {
9
18
  value: length === 1 && typeof original[0] !== "function" ? original[0] : original[1]
10
19
  };
11
20
  }
21
+ function findAbsoluteValueOrDefault(array, parameters, defaultValue, useDefaultValue, reversed) {
22
+ if (parameters.length === 0) {
23
+ if (Array.isArray(array) && array.length > 0) return reversed ? array.at(-1) : array[0];
24
+ return useDefaultValue ? defaultValue : void 0;
25
+ }
26
+ const index = findValue(ARRAY_FIND_VALUE_INDEX, array, parameters, reversed);
27
+ if (index === -1) return useDefaultValue ? defaultValue : void 0;
28
+ return array[index];
29
+ }
12
30
  function findComplexValues(parameters) {
13
- const { array, keyCallback, length, mapAfter, mapBefore, result, type, value } = parameters;
31
+ const { array, arrayLength, callback, limit, result, type, value } = parameters;
14
32
  const keys = /* @__PURE__ */ new Set();
15
- for (let index = 0; index < length; index += 1) {
16
- const item = array[index];
17
- let keyed;
18
- let transformed;
19
- if (mapBefore == null) {
20
- keyed = keyCallback?.(item, index, array) ?? item;
21
- transformed = item;
22
- } else {
23
- transformed = mapBefore(item, index, array);
24
- keyed = keyCallback?.(transformed, index, array) ?? transformed;
25
- }
33
+ for (let arrayIndex = 0; arrayIndex < arrayLength; arrayIndex += 1) {
34
+ const arrayItem = array[arrayIndex];
35
+ const keyed = callback == null ? arrayItem : callback(arrayItem, arrayIndex, array);
36
+ const mapped = arrayItem;
26
37
  if (type === "all" && Object.is(keyed, value) || type === "unique" && !keys.has(keyed)) {
27
38
  keys.add(keyed);
28
- result.matched.push(mapAfter?.(item, index, array) ?? transformed);
29
- } else result.notMatched.push(item);
39
+ result.matched.push(mapped);
40
+ if (result.matched.length >= limit) return result;
41
+ } else result.notMatched.push(arrayItem);
30
42
  }
31
43
  return result;
32
44
  }
@@ -34,13 +46,28 @@ function findSimpleValue(array, value, findIndex, reversed) {
34
46
  if (findIndex) return reversed ? array.lastIndexOf(value) : array.indexOf(value);
35
47
  return reversed ? array.findLast((item) => Object.is(item, value)) : array.find((item) => Object.is(item, value));
36
48
  }
37
- function findSimpleValues(array, length, value, boolCallback, mapBefore, mapAfter, result) {
38
- const callback = boolCallback ?? ((item) => Object.is(item, value));
39
- for (let index = 0; index < length; index += 1) {
40
- const item = array[index];
41
- const transformed = mapBefore?.(item, index, array) ?? item;
42
- if (callback(transformed, index, array)) result.matched.push(mapAfter?.(item, index, array) ?? transformed);
43
- else result.notMatched.push(item);
49
+ function findSimpleValues(parameters) {
50
+ const { array, arrayLength, callback, flat, limit, map, result, value } = parameters;
51
+ const { after, before } = map ?? {};
52
+ const handler = callback ?? ((item) => Object.is(item, value));
53
+ for (let arrayIndex = 0; arrayIndex < arrayLength; arrayIndex += 1) {
54
+ const arrayItem = array[arrayIndex];
55
+ let mapped = before == null ? arrayItem : before(arrayItem, arrayIndex, array);
56
+ if (!flat || after != null) {
57
+ if (handler(mapped, arrayIndex, array)) {
58
+ mapped = after == null ? mapped : after(arrayItem, arrayIndex, array);
59
+ addResult(result, mapped, flat);
60
+ if (result.matched.length >= limit) return result;
61
+ } else result.notMatched.push(arrayItem);
62
+ continue;
63
+ }
64
+ const flatItems = Array.isArray(mapped) ? mapped : [mapped];
65
+ const flatLength = flatItems.length;
66
+ for (let flatIndex = 0; flatIndex < flatLength; flatIndex += 1) {
67
+ const flatItem = flatItems[flatIndex];
68
+ if (handler(flatItem, arrayIndex, array)) result.matched.push(flatItem);
69
+ else result.notMatched.push(flatItem);
70
+ }
44
71
  }
45
72
  return result;
46
73
  }
@@ -64,50 +91,42 @@ function findValueInArray(array, callback, value, findIndex, reversed) {
64
91
  }
65
92
  return findIndex ? -1 : void 0;
66
93
  }
67
- function findAbsoluteValueOrDefault(array, parameters, defaultValue, useDefaultValue, reversed) {
68
- if (parameters.length === 0) {
69
- if (Array.isArray(array) && array.length > 0) return reversed ? array.at(-1) : array[0];
70
- return useDefaultValue ? defaultValue : void 0;
71
- }
72
- const index = findValue(ARRAY_FIND_VALUE_INDEX, array, parameters, reversed);
73
- if (index === -1) return useDefaultValue ? defaultValue : void 0;
74
- return array[index];
75
- }
76
- function findValues(type, array, parameters, mapper) {
94
+ function findValues(type, array, parameters, options) {
77
95
  const result = {
78
96
  matched: [],
79
97
  notMatched: []
80
98
  };
81
- if (!Array.isArray(array) || array.length === 0) return result;
82
- const { length } = array;
99
+ if (!Array.isArray(array)) return result;
100
+ const arrayLength = array.length;
101
+ if (arrayLength === 0) return result;
83
102
  const { bool, key, value } = createFindParameters(parameters);
84
103
  const callbacks = getArrayCallbacks(bool, key);
85
- if (type === "unique" && callbacks?.keyed == null && length >= 100) {
104
+ if (type === "unique" && callbacks?.keyed == null && arrayLength >= 100) {
86
105
  result.matched = [...new Set(array)];
87
106
  return result;
88
107
  }
89
- const mapCallback = getArrayCallback(mapper?.callback);
90
- const mapReverse = mapper?.reverse ?? false;
91
- let mapAfter;
92
- let mapBefore;
93
- if (mapCallback == null) {
94
- mapAfter = void 0;
95
- mapBefore = void 0;
96
- } else {
97
- mapAfter = mapReverse ? void 0 : mapCallback;
98
- mapBefore = mapReverse ? mapCallback : void 0;
99
- }
100
- if (callbacks?.bool != null || type === "all" && key == null) return findSimpleValues(array, length, value, callbacks?.bool, mapBefore, mapAfter, result);
101
- return findComplexValues({
108
+ const limit = options?.limit ?? Number.POSITIVE_INFINITY;
109
+ const flat = options?.map?.flat ?? false;
110
+ const mapCallback = getArrayCallback(options?.map?.callback);
111
+ const mapReverse = options?.map?.reverse ?? false;
112
+ let map;
113
+ if (mapCallback != null) map = {
114
+ before: mapReverse ? mapCallback : void 0,
115
+ after: mapReverse ? void 0 : mapCallback
116
+ };
117
+ const simple = callbacks?.bool != null || type === "all" && key == null;
118
+ const findParameters = {
102
119
  array,
103
- length,
104
- mapAfter,
105
- mapBefore,
120
+ arrayLength,
121
+ flat,
122
+ limit,
123
+ map,
106
124
  result,
107
125
  type,
108
126
  value,
109
- keyCallback: callbacks?.keyed
110
- });
127
+ callback: simple ? callbacks?.bool : callbacks?.keyed
128
+ };
129
+ return simple ? findSimpleValues(findParameters) : findComplexValues(findParameters);
111
130
  }
112
131
  //#endregion
113
132
  export { createFindParameters, findAbsoluteValueOrDefault, findValue, findValues };
@@ -4,6 +4,11 @@
4
4
  *
5
5
  * @param array Original array
6
6
  * @returns Shuffled array
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * shuffle([1, 2, 3]); // => [3, 1, 2] (maybe? it's random, you know)
11
+ * ```
7
12
  */
8
13
  export declare function shuffle<Item>(array: Item[]): Item[];
9
14
  //#endregion
@@ -5,6 +5,11 @@ import { getRandomInteger } from "../random.mjs";
5
5
  *
6
6
  * @param array Original array
7
7
  * @returns Shuffled array
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * shuffle([1, 2, 3]); // => [3, 1, 2] (maybe? it's random, you know)
12
+ * ```
8
13
  */
9
14
  function shuffle(array) {
10
15
  if (!Array.isArray(array)) return [];
@@ -7,6 +7,11 @@ export declare function getAggregated(type: NonAverageAggregationType, array: un
7
7
  /**
8
8
  * Get the maximum value from a list of items
9
9
  *
10
+ * @param items List of items
11
+ * @param callback Callback to get an item's value
12
+ * @param first Return only the first item with the maximum value
13
+ * @returns Item with the maximum value, or `undefined` if no maximum can be found
14
+ *
10
15
  * @example
11
16
  * ```typescript
12
17
  * max(
@@ -16,16 +21,16 @@ export declare function getAggregated(type: NonAverageAggregationType, array: un
16
21
  *
17
22
  * max([], item => item.value); // => []
18
23
  * ```
19
- *
20
- * @param items List of items
21
- * @param callback Callback to get an item's value
22
- * @param first Return only the first item with the maximum value
23
- * @returns Item with the maximum value, or `undefined` if no maximum can be found
24
24
  */
25
25
  export declare function max<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number, first: true): Item | undefined;
26
26
  /**
27
27
  * Get the maximum value from a list of items
28
28
  *
29
+ * @param items List of items
30
+ * @param key Key to use for value
31
+ * @param first Return only the first item with the maximum value
32
+ * @returns Item with the maximum value, or `undefined` if no maximum can be found
33
+ *
29
34
  * @example
30
35
  * ```typescript
31
36
  * max(
@@ -35,16 +40,15 @@ export declare function max<Item>(items: Item[], callback: (item: Item, index: n
35
40
  *
36
41
  * max([], 'value'); // => []
37
42
  * ```
38
- *
39
- * @param items List of items
40
- * @param key Key to use for value
41
- * @param first Return only the first item with the maximum value
42
- * @returns Item with the maximum value, or `undefined` if no maximum can be found
43
43
  */
44
44
  export declare function max<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>, first: true): Item | undefined;
45
45
  /**
46
46
  * Get the maximum value from a list of items
47
47
  *
48
+ * @param items List of items
49
+ * @param callback Callback to get an item's value
50
+ * @returns Items with the maximum value
51
+ *
48
52
  * @example
49
53
  * ```typescript
50
54
  * max(
@@ -54,15 +58,15 @@ export declare function max<Item extends PlainObject>(items: Item[], key: keyof
54
58
  *
55
59
  * max([], item => item.value); // => []
56
60
  * ```
57
- *
58
- * @param items List of items
59
- * @param callback Callback to get an item's value
60
- * @returns Items with the maximum value
61
61
  */
62
62
  export declare function max<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): Item[];
63
63
  /**
64
64
  * Get the maximum value from a list of items
65
65
  *
66
+ * @param items List of items
67
+ * @param key Key to use for value
68
+ * @returns Items with the maximum value
69
+ *
66
70
  * @example
67
71
  * ```typescript
68
72
  * max(
@@ -72,23 +76,19 @@ export declare function max<Item>(items: Item[], callback: (item: Item, index: n
72
76
  *
73
77
  * max([], 'value'); // => []
74
78
  * ```
75
- *
76
- * @param items List of items
77
- * @param key Key to use for value
78
- * @returns Items with the maximum value
79
79
  */
80
80
  export declare function max<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): Item[];
81
81
  /**
82
82
  * Get the maximum value from a list of numbers
83
83
  *
84
+ * @param values List of numbers
85
+ * @returns Maximum value, or `Number.NaN` if no maximum can be found
86
+ *
84
87
  * @example
85
88
  * ```typescript
86
89
  * max([10, 20]); // => 20
87
90
  * max([]); // => Number.NaN
88
91
  * ```
89
- *
90
- * @param values List of numbers
91
- * @returns Maximum value, or `Number.NaN` if no maximum can be found
92
92
  */
93
93
  export declare function max(values: number[]): number;
94
94
  /**
@@ -98,6 +98,17 @@ export declare function max(values: number[]): number;
98
98
  * @param callback Callback to get an item's value
99
99
  * @param first Return only the first item with the minimum value
100
100
  * @returns First item with the minimum value, or `undefined` if no minimum can be found
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * min(
105
+ * [{id: 1, value: 10}, {id: 2, value: 5}],
106
+ * item => item.value,
107
+ * true,
108
+ * ); // => {id: 2, value: 5}
109
+ *
110
+ * min([], item => item.value, true); // => undefined
111
+ * ```
101
112
  */
102
113
  export declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number, first: true): Item | undefined;
103
114
  /**
@@ -107,6 +118,17 @@ export declare function min<Item>(items: Item[], callback: (item: Item, index: n
107
118
  * @param key Key to use for value
108
119
  * @param first Return only the first item with the minimum value
109
120
  * @returns First item with the minimum value, or `undefined` if no minimum can be found
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * min(
125
+ * [{id: 1, value: 10}, {id: 2, value: 5}],
126
+ * 'value',
127
+ * true,
128
+ * ); // => {id: 2, value: 5}
129
+ *
130
+ * min([], 'value', true); // => undefined
131
+ * ```
110
132
  */
111
133
  export declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>, first: true): Item | undefined;
112
134
  /**
@@ -115,6 +137,16 @@ export declare function min<Item extends PlainObject>(items: Item[], key: keyof
115
137
  * @param items List of items
116
138
  * @param callback Callback to get an item's value
117
139
  * @returns Items with the minimum value
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * min(
144
+ * [{id: 1, value: 10}, {id: 2, value: 5}],
145
+ * item => item.value,
146
+ * ); // => [{id: 2, value: 5}]
147
+ *
148
+ * min([], item => item.value); // => []
149
+ * ```
118
150
  */
119
151
  export declare function min<Item>(items: Item[], callback: (item: Item, index: number, array: Item[]) => number): Item[];
120
152
  /**
@@ -123,6 +155,16 @@ export declare function min<Item>(items: Item[], callback: (item: Item, index: n
123
155
  * @param items List of items
124
156
  * @param key Key to use for value
125
157
  * @returns Items with the minimum value
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * min(
162
+ * [{id: 1, value: 10}, {id: 2, value: 5}],
163
+ * 'value',
164
+ * ); // => [{id: 2, value: 5}]
165
+ *
166
+ * min([], 'value'); // => []
167
+ * ```
126
168
  */
127
169
  export declare function min<Item extends PlainObject>(items: Item[], key: keyof NumericalValues<Item>): Item[];
128
170
  /**
@@ -130,6 +172,12 @@ export declare function min<Item extends PlainObject>(items: Item[], key: keyof
130
172
  *
131
173
  * @param values List of numbers
132
174
  * @returns Minimum value, or `Number.NaN` if no minimum can be found
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * min([10, 20]); // => 10
179
+ * min([]); // => Number.NaN
180
+ * ```
133
181
  */
134
182
  export declare function min(values: number[]): number;
135
183
  //#endregion
@@ -5,6 +5,13 @@
5
5
  * @param value Number to round down
6
6
  * @param decimals Number of decimal places to round to _(defaults to `0`)_
7
7
  * @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * floor(10.567, 2); // => 10.56
12
+ * floor(10.567); // => 10
13
+ * floor('abc'); // => Number.NaN
14
+ * ```
8
15
  */
9
16
  export declare function floor(value: number, decimals?: number): number;
10
17
  /**
@@ -13,6 +20,13 @@ export declare function floor(value: number, decimals?: number): number;
13
20
  * @param value Number to round
14
21
  * @param decimals Number of decimal places to round to _(defaults to `0`)_
15
22
  * @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * round(10.567, 2); // => 10.57
27
+ * round(10.567); // => 11
28
+ * round('abc'); // => Number.NaN
29
+ * ```
16
30
  */
17
31
  export declare function round(value: number, decimals?: number): number;
18
32
  export declare function roundNumber(callback: (value: number) => number, value: number, decimals?: number): number;
@@ -5,6 +5,13 @@
5
5
  * @param value Number to round down
6
6
  * @param decimals Number of decimal places to round to _(defaults to `0`)_
7
7
  * @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * floor(10.567, 2); // => 10.56
12
+ * floor(10.567); // => 10
13
+ * floor('abc'); // => Number.NaN
14
+ * ```
8
15
  */
9
16
  function floor(value, decimals) {
10
17
  return roundNumber(Math.floor, value, decimals);
@@ -15,6 +22,13 @@ function floor(value, decimals) {
15
22
  * @param value Number to round
16
23
  * @param decimals Number of decimal places to round to _(defaults to `0`)_
17
24
  * @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * round(10.567, 2); // => 10.57
29
+ * round(10.567); // => 11
30
+ * round('abc'); // => Number.NaN
31
+ * ```
18
32
  */
19
33
  function round(value, decimals) {
20
34
  return roundNumber(Math.round, value, decimals);
@@ -6,6 +6,13 @@
6
6
  * @param minimum Minimum value
7
7
  * @param maximum Maximum value _(inclusive)_
8
8
  * @returns `true` if the value is between the minimum and maximum, otherwise `false`
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * between(5, 1, 10); // => true
13
+ * between(0, 1, 10); // => false
14
+ * between(10, 10, 10); // => true
15
+ * ```
9
16
  */
10
17
  export declare function between(value: number, minimum: number, maximum: number): boolean;
11
18
  /**
@@ -31,6 +38,17 @@ export declare function clamp(value: number, minimum: number, maximum: number, l
31
38
  *
32
39
  * @param value Original value
33
40
  * @returns Original value as a number, or `Number.NaN` if the value is unable to be parsed
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * getNumber(null) // => Number.NaN
45
+ * getNumber('foo') // => Number.NaN
46
+ * getNumber('123') // => 123
47
+ * getNumber(true) // => 1
48
+ * getNumber([1, 2, 3]) // => Number.NaN
49
+ * getNumber({a: 1}) // => Number.NaN
50
+ * getNumber(() => 123) // => 123
51
+ * ```
34
52
  */
35
53
  export declare function getNumber(value: unknown): number;
36
54
  //#endregion
@@ -9,6 +9,13 @@ import { EXPRESSION_NUMBER_BINARY, EXPRESSION_NUMBER_OCTAL, EXPRESSION_NUMBER_ZE
9
9
  * @param minimum Minimum value
10
10
  * @param maximum Maximum value _(inclusive)_
11
11
  * @returns `true` if the value is between the minimum and maximum, otherwise `false`
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * between(5, 1, 10); // => true
16
+ * between(0, 1, 10); // => false
17
+ * between(10, 10, 10); // => true
18
+ * ```
12
19
  */
13
20
  function between(value, minimum, maximum) {
14
21
  if (![
@@ -51,6 +58,17 @@ function clamp(value, minimum, maximum, loop) {
51
58
  *
52
59
  * @param value Original value
53
60
  * @returns Original value as a number, or `Number.NaN` if the value is unable to be parsed
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * getNumber(null) // => Number.NaN
65
+ * getNumber('foo') // => Number.NaN
66
+ * getNumber('123') // => 123
67
+ * getNumber(true) // => 1
68
+ * getNumber([1, 2, 3]) // => Number.NaN
69
+ * getNumber({a: 1}) // => Number.NaN
70
+ * getNumber(() => 123) // => 123
71
+ * ```
54
72
  */
55
73
  function getNumber(value) {
56
74
  if (typeof value === "number") return value;
@@ -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