nhb-toolbox 4.20.27 → 4.20.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/dist/cjs/array/Finder.js +0 -75
- package/dist/cjs/array/basics.js +0 -35
- package/dist/cjs/array/calc.js +0 -63
- package/dist/cjs/array/helpers.js +0 -15
- package/dist/cjs/array/sort.js +0 -16
- package/dist/cjs/array/transform.js +0 -73
- package/dist/cjs/array/utils.js +0 -19
- package/dist/cjs/colors/Color.js +0 -199
- package/dist/cjs/colors/constants.js +0 -2
- package/dist/cjs/colors/convert.js +0 -114
- package/dist/cjs/colors/css-colors.js +0 -1
- package/dist/cjs/colors/helpers.js +0 -73
- package/dist/cjs/colors/initials.js +0 -17
- package/dist/cjs/colors/random.js +0 -17
- package/dist/cjs/colors/utils.js +0 -18
- package/dist/cjs/date/Chronos.js +11 -595
- package/dist/cjs/date/chronos-fn.js +0 -112
- package/dist/cjs/date/constants.js +1 -161
- package/dist/cjs/date/greet.js +0 -6
- package/dist/cjs/date/guards.js +0 -29
- package/dist/cjs/date/plugins/businessPlugin.js +0 -3
- package/dist/cjs/date/plugins/dayPartPlugin.js +0 -2
- package/dist/cjs/date/plugins/fromNowPlugin.js +0 -2
- package/dist/cjs/date/plugins/palindromePlugin.js +0 -1
- package/dist/cjs/date/plugins/relativeTimePlugin.js +0 -3
- package/dist/cjs/date/plugins/seasonPlugin.js +0 -2
- package/dist/cjs/date/plugins/timeZonePlugin.js +0 -1
- package/dist/cjs/date/plugins/zodiacPlugin.js +0 -1
- package/dist/cjs/date/seasons.js +14 -25
- package/dist/cjs/date/utils.js +0 -48
- package/dist/cjs/dom/query.js +0 -38
- package/dist/cjs/dom/storage.js +0 -36
- package/dist/cjs/dom/utils.js +1 -15
- package/dist/cjs/form/convert.js +0 -26
- package/dist/cjs/form/guards.js +0 -45
- package/dist/cjs/form/transform.js +0 -16
- package/dist/cjs/guards/non-primitives.js +0 -88
- package/dist/cjs/guards/primitives.js +0 -70
- package/dist/cjs/guards/specials.js +0 -62
- package/dist/cjs/http-status/HttpStatus.js +0 -93
- package/dist/cjs/http-status/constants.js +0 -258
- package/dist/cjs/index.js +0 -34
- package/dist/cjs/number/Currency.js +0 -73
- package/dist/cjs/number/Unit.js +0 -128
- package/dist/cjs/number/basics.js +0 -67
- package/dist/cjs/number/constants.js +161 -182
- package/dist/cjs/number/convert.js +0 -55
- package/dist/cjs/number/fibonacci.js +0 -25
- package/dist/cjs/number/guards.js +0 -37
- package/dist/cjs/number/helpers.js +0 -26
- package/dist/cjs/number/percent.js +0 -20
- package/dist/cjs/number/prime.js +0 -13
- package/dist/cjs/number/range.js +0 -15
- package/dist/cjs/number/utilities.js +0 -52
- package/dist/cjs/object/basics.js +0 -12
- package/dist/cjs/object/convert.js +0 -64
- package/dist/cjs/object/objectify.js +0 -88
- package/dist/cjs/object/sanitize.js +0 -58
- package/dist/cjs/pluralize/Pluralizer.js +0 -138
- package/dist/cjs/pluralize/rules.js +0 -10
- package/dist/cjs/string/anagram.js +0 -11
- package/dist/cjs/string/basics.js +0 -31
- package/dist/cjs/string/case.js +1 -86
- package/dist/cjs/string/constants.js +0 -5
- package/dist/cjs/string/convert.js +0 -53
- package/dist/cjs/string/guards.js +0 -30
- package/dist/cjs/string/utilities.js +0 -17
- package/dist/cjs/utils/Paginator.js +0 -99
- package/dist/cjs/utils/constants.js +0 -12
- package/dist/cjs/utils/helpers.js +0 -15
- package/dist/cjs/utils/index.js +0 -114
- package/dist/cjs/utils/stylog.js +3 -276
- package/dist/cjs/verbalizer/Verbalizer.js +0 -124
- package/dist/cjs/verbalizer/rules.js +16 -23
- package/dist/dts/array/Finder.d.ts +0 -1
- package/dist/dts/array/basics.d.ts +0 -1
- package/dist/dts/array/calc.d.ts +0 -1
- package/dist/dts/array/helpers.d.ts +0 -1
- package/dist/dts/array/sort.d.ts +0 -1
- package/dist/dts/array/transform.d.ts +0 -1
- package/dist/dts/array/types.d.ts +0 -1
- package/dist/dts/array/utils.d.ts +0 -1
- package/dist/dts/colors/Color.d.ts +0 -1
- package/dist/dts/colors/constants.d.ts +0 -1
- package/dist/dts/colors/convert.d.ts +0 -1
- package/dist/dts/colors/css-colors.d.ts +0 -1
- package/dist/dts/colors/helpers.d.ts +0 -1
- package/dist/dts/colors/initials.d.ts +0 -1
- package/dist/dts/colors/random.d.ts +0 -1
- package/dist/dts/colors/types.d.ts +0 -1
- package/dist/dts/colors/utils.d.ts +0 -1
- package/dist/dts/constants.d.ts +0 -1
- package/dist/dts/date/Chronos.d.ts +0 -1
- package/dist/dts/date/chronos-fn.d.ts +0 -1
- package/dist/dts/date/constants.d.ts +0 -1
- package/dist/dts/date/greet.d.ts +0 -1
- package/dist/dts/date/guards.d.ts +0 -1
- package/dist/dts/date/plugins/businessPlugin.d.ts +0 -1
- package/dist/dts/date/plugins/dayPartPlugin.d.ts +0 -1
- package/dist/dts/date/plugins/fromNowPlugin.d.ts +0 -1
- package/dist/dts/date/plugins/palindromePlugin.d.ts +0 -1
- package/dist/dts/date/plugins/relativeTimePlugin.d.ts +0 -1
- package/dist/dts/date/plugins/seasonPlugin.d.ts +0 -1
- package/dist/dts/date/plugins/timeZonePlugin.d.ts +0 -1
- package/dist/dts/date/plugins/zodiacPlugin.d.ts +0 -1
- package/dist/dts/date/seasons.d.ts +0 -1
- package/dist/dts/date/types.d.ts +0 -1
- package/dist/dts/date/utils.d.ts +0 -1
- package/dist/dts/dom/query.d.ts +0 -1
- package/dist/dts/dom/storage.d.ts +0 -1
- package/dist/dts/dom/utils.d.ts +0 -1
- package/dist/dts/form/convert.d.ts +0 -1
- package/dist/dts/form/guards.d.ts +0 -1
- package/dist/dts/form/transform.d.ts +0 -1
- package/dist/dts/form/types.d.ts +0 -1
- package/dist/dts/guards/non-primitives.d.ts +0 -1
- package/dist/dts/guards/primitives.d.ts +0 -1
- package/dist/dts/guards/specials.d.ts +0 -1
- package/dist/dts/http-status/HttpStatus.d.ts +0 -1
- package/dist/dts/http-status/constants.d.ts +0 -1
- package/dist/dts/http-status/types.d.ts +0 -1
- package/dist/dts/index.d.ts +0 -1
- package/dist/dts/number/Currency.d.ts +0 -1
- package/dist/dts/number/Unit.d.ts +0 -1
- package/dist/dts/number/basics.d.ts +0 -1
- package/dist/dts/number/constants.d.ts +0 -1
- package/dist/dts/number/convert.d.ts +0 -1
- package/dist/dts/number/fibonacci.d.ts +0 -1
- package/dist/dts/number/guards.d.ts +0 -1
- package/dist/dts/number/helpers.d.ts +0 -1
- package/dist/dts/number/percent.d.ts +0 -1
- package/dist/dts/number/prime.d.ts +0 -1
- package/dist/dts/number/range.d.ts +0 -1
- package/dist/dts/number/types.d.ts +0 -1
- package/dist/dts/number/utilities.d.ts +0 -1
- package/dist/dts/object/basics.d.ts +0 -1
- package/dist/dts/object/convert.d.ts +0 -1
- package/dist/dts/object/objectify.d.ts +0 -1
- package/dist/dts/object/sanitize.d.ts +0 -1
- package/dist/dts/object/types.d.ts +0 -1
- package/dist/dts/pluralize/Pluralizer.d.ts +0 -1
- package/dist/dts/pluralize/rules.d.ts +0 -1
- package/dist/dts/pluralize/types.d.ts +0 -1
- package/dist/dts/string/anagram.d.ts +0 -1
- package/dist/dts/string/basics.d.ts +0 -1
- package/dist/dts/string/case.d.ts +0 -1
- package/dist/dts/string/constants.d.ts +0 -1
- package/dist/dts/string/convert.d.ts +0 -1
- package/dist/dts/string/guards.d.ts +0 -1
- package/dist/dts/string/types.d.ts +0 -1
- package/dist/dts/string/utilities.d.ts +0 -1
- package/dist/dts/types/index.d.ts +0 -1
- package/dist/dts/utils/Paginator.d.ts +0 -1
- package/dist/dts/utils/constants.d.ts +0 -1
- package/dist/dts/utils/helpers.d.ts +0 -1
- package/dist/dts/utils/index.d.ts +0 -1
- package/dist/dts/utils/stylog.d.ts +0 -1
- package/dist/dts/utils/types.d.ts +0 -1
- package/dist/dts/verbalizer/Verbalizer.d.ts +5 -2
- package/dist/dts/verbalizer/rules.d.ts +0 -1
- package/dist/dts/verbalizer/types.d.ts +0 -1
- package/dist/esm/array/Finder.js +0 -75
- package/dist/esm/array/basics.js +0 -35
- package/dist/esm/array/calc.js +0 -63
- package/dist/esm/array/helpers.js +0 -15
- package/dist/esm/array/sort.js +0 -16
- package/dist/esm/array/transform.js +0 -73
- package/dist/esm/array/utils.js +0 -19
- package/dist/esm/colors/Color.js +0 -199
- package/dist/esm/colors/constants.js +2 -4
- package/dist/esm/colors/convert.js +0 -114
- package/dist/esm/colors/css-colors.js +1 -2
- package/dist/esm/colors/helpers.js +0 -73
- package/dist/esm/colors/initials.js +0 -17
- package/dist/esm/colors/random.js +0 -17
- package/dist/esm/colors/utils.js +0 -18
- package/dist/esm/date/Chronos.js +11 -595
- package/dist/esm/date/chronos-fn.js +0 -112
- package/dist/esm/date/constants.js +20 -180
- package/dist/esm/date/greet.js +0 -6
- package/dist/esm/date/guards.js +0 -29
- package/dist/esm/date/plugins/businessPlugin.js +0 -3
- package/dist/esm/date/plugins/dayPartPlugin.js +0 -2
- package/dist/esm/date/plugins/fromNowPlugin.js +0 -2
- package/dist/esm/date/plugins/palindromePlugin.js +0 -1
- package/dist/esm/date/plugins/relativeTimePlugin.js +0 -3
- package/dist/esm/date/plugins/seasonPlugin.js +0 -2
- package/dist/esm/date/plugins/timeZonePlugin.js +0 -1
- package/dist/esm/date/plugins/zodiacPlugin.js +0 -1
- package/dist/esm/date/seasons.js +25 -36
- package/dist/esm/date/utils.js +0 -48
- package/dist/esm/dom/query.js +0 -38
- package/dist/esm/dom/storage.js +0 -36
- package/dist/esm/dom/utils.js +1 -15
- package/dist/esm/form/convert.js +0 -26
- package/dist/esm/form/guards.js +0 -45
- package/dist/esm/form/transform.js +0 -16
- package/dist/esm/guards/non-primitives.js +0 -88
- package/dist/esm/guards/primitives.js +0 -70
- package/dist/esm/guards/specials.js +0 -62
- package/dist/esm/http-status/HttpStatus.js +0 -93
- package/dist/esm/http-status/constants.js +2 -260
- package/dist/esm/index.js +0 -34
- package/dist/esm/number/Currency.js +0 -73
- package/dist/esm/number/Unit.js +0 -128
- package/dist/esm/number/basics.js +0 -67
- package/dist/esm/number/constants.js +173 -194
- package/dist/esm/number/convert.js +0 -55
- package/dist/esm/number/fibonacci.js +0 -25
- package/dist/esm/number/guards.js +0 -37
- package/dist/esm/number/helpers.js +0 -26
- package/dist/esm/number/percent.js +0 -20
- package/dist/esm/number/prime.js +0 -13
- package/dist/esm/number/range.js +0 -15
- package/dist/esm/number/utilities.js +0 -52
- package/dist/esm/object/basics.js +0 -12
- package/dist/esm/object/convert.js +0 -64
- package/dist/esm/object/objectify.js +0 -88
- package/dist/esm/object/sanitize.js +0 -58
- package/dist/esm/pluralize/Pluralizer.js +0 -138
- package/dist/esm/pluralize/rules.js +4 -14
- package/dist/esm/string/anagram.js +0 -11
- package/dist/esm/string/basics.js +0 -31
- package/dist/esm/string/case.js +1 -86
- package/dist/esm/string/constants.js +1 -6
- package/dist/esm/string/convert.js +0 -53
- package/dist/esm/string/guards.js +0 -30
- package/dist/esm/string/utilities.js +0 -17
- package/dist/esm/utils/Paginator.js +0 -99
- package/dist/esm/utils/constants.js +4 -16
- package/dist/esm/utils/helpers.js +0 -15
- package/dist/esm/utils/index.js +0 -114
- package/dist/esm/utils/stylog.js +3 -276
- package/dist/esm/verbalizer/Verbalizer.js +0 -124
- package/dist/esm/verbalizer/rules.js +18 -25
- package/package.json +1 -1
- package/dist/dts/array/Finder.d.ts.map +0 -1
- package/dist/dts/array/basics.d.ts.map +0 -1
- package/dist/dts/array/calc.d.ts.map +0 -1
- package/dist/dts/array/helpers.d.ts.map +0 -1
- package/dist/dts/array/sort.d.ts.map +0 -1
- package/dist/dts/array/transform.d.ts.map +0 -1
- package/dist/dts/array/types.d.ts.map +0 -1
- package/dist/dts/array/utils.d.ts.map +0 -1
- package/dist/dts/colors/Color.d.ts.map +0 -1
- package/dist/dts/colors/constants.d.ts.map +0 -1
- package/dist/dts/colors/convert.d.ts.map +0 -1
- package/dist/dts/colors/css-colors.d.ts.map +0 -1
- package/dist/dts/colors/helpers.d.ts.map +0 -1
- package/dist/dts/colors/initials.d.ts.map +0 -1
- package/dist/dts/colors/random.d.ts.map +0 -1
- package/dist/dts/colors/types.d.ts.map +0 -1
- package/dist/dts/colors/utils.d.ts.map +0 -1
- package/dist/dts/constants.d.ts.map +0 -1
- package/dist/dts/date/Chronos.d.ts.map +0 -1
- package/dist/dts/date/chronos-fn.d.ts.map +0 -1
- package/dist/dts/date/constants.d.ts.map +0 -1
- package/dist/dts/date/greet.d.ts.map +0 -1
- package/dist/dts/date/guards.d.ts.map +0 -1
- package/dist/dts/date/plugins/businessPlugin.d.ts.map +0 -1
- package/dist/dts/date/plugins/dayPartPlugin.d.ts.map +0 -1
- package/dist/dts/date/plugins/fromNowPlugin.d.ts.map +0 -1
- package/dist/dts/date/plugins/palindromePlugin.d.ts.map +0 -1
- package/dist/dts/date/plugins/relativeTimePlugin.d.ts.map +0 -1
- package/dist/dts/date/plugins/seasonPlugin.d.ts.map +0 -1
- package/dist/dts/date/plugins/timeZonePlugin.d.ts.map +0 -1
- package/dist/dts/date/plugins/zodiacPlugin.d.ts.map +0 -1
- package/dist/dts/date/seasons.d.ts.map +0 -1
- package/dist/dts/date/types.d.ts.map +0 -1
- package/dist/dts/date/utils.d.ts.map +0 -1
- package/dist/dts/dom/query.d.ts.map +0 -1
- package/dist/dts/dom/storage.d.ts.map +0 -1
- package/dist/dts/dom/utils.d.ts.map +0 -1
- package/dist/dts/form/convert.d.ts.map +0 -1
- package/dist/dts/form/guards.d.ts.map +0 -1
- package/dist/dts/form/transform.d.ts.map +0 -1
- package/dist/dts/form/types.d.ts.map +0 -1
- package/dist/dts/guards/non-primitives.d.ts.map +0 -1
- package/dist/dts/guards/primitives.d.ts.map +0 -1
- package/dist/dts/guards/specials.d.ts.map +0 -1
- package/dist/dts/http-status/HttpStatus.d.ts.map +0 -1
- package/dist/dts/http-status/constants.d.ts.map +0 -1
- package/dist/dts/http-status/types.d.ts.map +0 -1
- package/dist/dts/index.d.ts.map +0 -1
- package/dist/dts/number/Currency.d.ts.map +0 -1
- package/dist/dts/number/Unit.d.ts.map +0 -1
- package/dist/dts/number/basics.d.ts.map +0 -1
- package/dist/dts/number/constants.d.ts.map +0 -1
- package/dist/dts/number/convert.d.ts.map +0 -1
- package/dist/dts/number/fibonacci.d.ts.map +0 -1
- package/dist/dts/number/guards.d.ts.map +0 -1
- package/dist/dts/number/helpers.d.ts.map +0 -1
- package/dist/dts/number/percent.d.ts.map +0 -1
- package/dist/dts/number/prime.d.ts.map +0 -1
- package/dist/dts/number/range.d.ts.map +0 -1
- package/dist/dts/number/types.d.ts.map +0 -1
- package/dist/dts/number/utilities.d.ts.map +0 -1
- package/dist/dts/object/basics.d.ts.map +0 -1
- package/dist/dts/object/convert.d.ts.map +0 -1
- package/dist/dts/object/objectify.d.ts.map +0 -1
- package/dist/dts/object/sanitize.d.ts.map +0 -1
- package/dist/dts/object/types.d.ts.map +0 -1
- package/dist/dts/pluralize/Pluralizer.d.ts.map +0 -1
- package/dist/dts/pluralize/rules.d.ts.map +0 -1
- package/dist/dts/pluralize/types.d.ts.map +0 -1
- package/dist/dts/string/anagram.d.ts.map +0 -1
- package/dist/dts/string/basics.d.ts.map +0 -1
- package/dist/dts/string/case.d.ts.map +0 -1
- package/dist/dts/string/constants.d.ts.map +0 -1
- package/dist/dts/string/convert.d.ts.map +0 -1
- package/dist/dts/string/guards.d.ts.map +0 -1
- package/dist/dts/string/types.d.ts.map +0 -1
- package/dist/dts/string/utilities.d.ts.map +0 -1
- package/dist/dts/types/index.d.ts.map +0 -1
- package/dist/dts/utils/Paginator.d.ts.map +0 -1
- package/dist/dts/utils/constants.d.ts.map +0 -1
- package/dist/dts/utils/helpers.d.ts.map +0 -1
- package/dist/dts/utils/index.d.ts.map +0 -1
- package/dist/dts/utils/stylog.d.ts.map +0 -1
- package/dist/dts/utils/types.d.ts.map +0 -1
- package/dist/dts/verbalizer/Verbalizer.d.ts.map +0 -1
- package/dist/dts/verbalizer/rules.d.ts.map +0 -1
- package/dist/dts/verbalizer/types.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,11 @@ All notable changes to the package will be documented here.
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [4.20.30] - 2025-09-17
|
|
10
|
+
|
|
11
|
+
- **Reduced** _unpacked size_ by **removing** _tsdoc comments_ from js (both `cjs` and `esm`) outputs.
|
|
12
|
+
- **Updated** tsdoc for `Verbalizer/verbalizer`: **added** reference to documentation site.
|
|
13
|
+
|
|
9
14
|
## [4.20.27] - 2025-09-16
|
|
10
15
|
|
|
11
16
|
- **Fixed** _issues_: (**failed to convert already past/participle regular verbs**) with `toPast()` and `toParticiple()` methods in `Verbalizer/verbalizer`.
|
package/dist/cjs/array/Finder.js
CHANGED
|
@@ -1,30 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Finder = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* The `Finder` class performs optimized searching on arrays.
|
|
6
|
-
* It supports binary search, fuzzy search, and smart caching with TTL.
|
|
7
|
-
*/
|
|
8
4
|
class Finder {
|
|
9
5
|
static #DEFAULT_TTL = 1000 * 60 * 5;
|
|
10
6
|
#cachedResult = new Map();
|
|
11
7
|
#sortedCache = new Map();
|
|
12
8
|
#ttl;
|
|
13
9
|
#items;
|
|
14
|
-
/**
|
|
15
|
-
* * Creates a new `Finder` instance.
|
|
16
|
-
*
|
|
17
|
-
* @param data The initial array of items or a callback returning them.
|
|
18
|
-
* @param ttl Time-to-live (in milliseconds) for cached search results. Defaults to {@link Finder.#DEFAULT_TTL 5 Minutes}.
|
|
19
|
-
*/
|
|
20
10
|
constructor(data, ttl = Finder.#DEFAULT_TTL) {
|
|
21
11
|
this.#ttl = ttl;
|
|
22
12
|
this.#items = typeof data === 'function' ? data() : data;
|
|
23
13
|
}
|
|
24
|
-
/**
|
|
25
|
-
* @instance Clears cache globally or for a specific key.
|
|
26
|
-
* @param key Optional key to clear only a specific cache entry.
|
|
27
|
-
*/
|
|
28
14
|
clearCache(key) {
|
|
29
15
|
if (key) {
|
|
30
16
|
this.#cachedResult.delete(key);
|
|
@@ -33,12 +19,6 @@ class Finder {
|
|
|
33
19
|
this.#cachedResult.clear();
|
|
34
20
|
}
|
|
35
21
|
}
|
|
36
|
-
/**
|
|
37
|
-
* @instance Finds all items that match the provided matcher using optional caching or fuzzy logic.
|
|
38
|
-
* @param matcher The value to match against.
|
|
39
|
-
* @param keySelector Property key or selector function.
|
|
40
|
-
* @param options Optional settings for search behavior and source list.
|
|
41
|
-
*/
|
|
42
22
|
findAll(matcher, keySelector, options) {
|
|
43
23
|
const { fuzzy = false, needSorting = true, cacheKey = 'finder-cache', forceBinary = false, caseInsensitive = true, data, } = options ?? {};
|
|
44
24
|
const source = typeof data === 'function' ? data() : (data ?? this.#items);
|
|
@@ -96,12 +76,6 @@ class Finder {
|
|
|
96
76
|
}
|
|
97
77
|
return results;
|
|
98
78
|
}
|
|
99
|
-
/**
|
|
100
|
-
* @instance Finds first matching item that matches the provided matcher using optional caching or fuzzy logic.
|
|
101
|
-
* @param matcher The value to match.
|
|
102
|
-
* @param keySelector Property key or selector function.
|
|
103
|
-
* @param options Optional behavior flags and item source.
|
|
104
|
-
*/
|
|
105
79
|
findOne(matcher, keySelector, options) {
|
|
106
80
|
const { fuzzy = false, needSorting = true, cacheKey = 'finder-cache', forceBinary = false, caseInsensitive = true, data, } = options ?? {};
|
|
107
81
|
const source = typeof data === 'function' ? data() : (data ?? this.#items);
|
|
@@ -141,37 +115,14 @@ class Finder {
|
|
|
141
115
|
}
|
|
142
116
|
return result;
|
|
143
117
|
}
|
|
144
|
-
/**
|
|
145
|
-
* @instance Asynchronous variant of `findAll` that accepts a promise-based data supplier.
|
|
146
|
-
* @param supplier Async function resolving the items list.
|
|
147
|
-
* @param matcher The value to match.
|
|
148
|
-
* @param keySelector Property key or selector function.
|
|
149
|
-
* @param options Optional settings for search behavior and cache.
|
|
150
|
-
*/
|
|
151
118
|
async findAllAsync(supplier, matcher, keySelector, options) {
|
|
152
119
|
const items = await supplier();
|
|
153
120
|
return this.findAll(matcher, keySelector, { ...options, data: items });
|
|
154
121
|
}
|
|
155
|
-
/**
|
|
156
|
-
* @instance Asynchronous variant of `findOne`.
|
|
157
|
-
* @param supplier Async function resolving the items list.
|
|
158
|
-
* @param matcher The value to match.
|
|
159
|
-
* @param keySelector Property key or selector function.
|
|
160
|
-
* @param options Optional settings for behavior and cache.
|
|
161
|
-
*/
|
|
162
122
|
async findOneAsync(supplier, matcher, keySelector, options) {
|
|
163
123
|
const items = await supplier();
|
|
164
124
|
return this.findOne(matcher, keySelector, { ...options, data: items });
|
|
165
125
|
}
|
|
166
|
-
/**
|
|
167
|
-
* @instance Performs a binary search on a sorted array using a custom key selector.
|
|
168
|
-
*
|
|
169
|
-
* @param sorted - The sorted array of items to search.
|
|
170
|
-
* @param matcher - The value to search for.
|
|
171
|
-
* @param keySelector - A function that extracts the comparable key from each item.
|
|
172
|
-
* @param caseInsensitive - Whether to compare string keys ignoring case.
|
|
173
|
-
* @returns The first matching item if found; otherwise, undefined.
|
|
174
|
-
*/
|
|
175
126
|
binarySearch(sorted, matcher, keySelector, caseInsensitive) {
|
|
176
127
|
let min = 0, max = sorted?.length - 1;
|
|
177
128
|
while (min <= max) {
|
|
@@ -187,15 +138,6 @@ class Finder {
|
|
|
187
138
|
}
|
|
188
139
|
return undefined;
|
|
189
140
|
}
|
|
190
|
-
/**
|
|
191
|
-
* @instance Performs a fuzzy search on an array by matching characters in sequence.
|
|
192
|
-
*
|
|
193
|
-
* @param array - The array of items to search.
|
|
194
|
-
* @param matcher - The fuzzy search string to match against.
|
|
195
|
-
* @param keySelector - A function that extracts the key to search from each item.
|
|
196
|
-
* @param caseInsensitive - Whether to compare ignoring case for string values.
|
|
197
|
-
* @returns The first fuzzy-matching item if found; otherwise, undefined.
|
|
198
|
-
*/
|
|
199
141
|
fuzzySearch(array, matcher, keySelector, caseInsensitive) {
|
|
200
142
|
for (const item of array) {
|
|
201
143
|
const rawKey = keySelector(item);
|
|
@@ -207,12 +149,6 @@ class Finder {
|
|
|
207
149
|
}
|
|
208
150
|
return undefined;
|
|
209
151
|
}
|
|
210
|
-
/**
|
|
211
|
-
* @private Checks if the characters in the target string appear in order within the source string.
|
|
212
|
-
* @param source Source string to search within.
|
|
213
|
-
* @param target Target string to match against the source string.
|
|
214
|
-
* @returns True if the target string is a fuzzy match within the source string; otherwise, false.
|
|
215
|
-
*/
|
|
216
152
|
#match(source, target) {
|
|
217
153
|
let i = 0;
|
|
218
154
|
for (const char of target) {
|
|
@@ -223,13 +159,6 @@ class Finder {
|
|
|
223
159
|
}
|
|
224
160
|
return true;
|
|
225
161
|
}
|
|
226
|
-
/**
|
|
227
|
-
* @private Sorts an array and caches the result for a specified time-to-live (TTL).
|
|
228
|
-
* @param data Data to sort and cache.
|
|
229
|
-
* @param getKey Key extraction function.
|
|
230
|
-
* @param cacheKey Optional cache key for storing the result.
|
|
231
|
-
* @returns
|
|
232
|
-
*/
|
|
233
162
|
#sortAndCache(data, getKey, cacheKey) {
|
|
234
163
|
if (cacheKey) {
|
|
235
164
|
const entry = this.#sortedCache.get(cacheKey);
|
|
@@ -255,10 +184,6 @@ class Finder {
|
|
|
255
184
|
}
|
|
256
185
|
return sorted;
|
|
257
186
|
}
|
|
258
|
-
/**
|
|
259
|
-
* @static @private Creates a memoized version of a key extractor.
|
|
260
|
-
* @param getKey Original key extraction function
|
|
261
|
-
*/
|
|
262
187
|
static #createMemoizedKeyGetter(getKey) {
|
|
263
188
|
const cache = new Map();
|
|
264
189
|
return (item) => {
|
package/dist/cjs/array/basics.js
CHANGED
|
@@ -1,31 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getLastArrayElement = exports.shuffleArray = exports.isInvalidOrEmptyArray = exports.filterArrayOfObjects = exports.flattenArray = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* * Flattens a nested array recursively or wraps any non-array data type in an array.
|
|
6
|
-
*
|
|
7
|
-
* @param input - The input value, which can be a nested array or a non-array value.
|
|
8
|
-
* @returns A fully flattened array of type `Flatten<T>`. If the input is not an array, it wraps it in a single-element array.
|
|
9
|
-
*/
|
|
10
4
|
const flattenArray = (input) => {
|
|
11
5
|
if (!Array.isArray(input))
|
|
12
6
|
return [input];
|
|
13
7
|
return input.reduce((acc, item) => {
|
|
14
|
-
// If item is an array, recursively flatten it; otherwise, add it directly.
|
|
15
8
|
return acc.concat(Array.isArray(item) ? (0, exports.flattenArray)(item) : [item]);
|
|
16
9
|
}, []);
|
|
17
10
|
};
|
|
18
11
|
exports.flattenArray = flattenArray;
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated _Please, use `findAll` instance method from `Finder` class for **more advanced filtering and searching.**_
|
|
21
|
-
*
|
|
22
|
-
* * Filters an array of objects based on multiple conditions for specified keys.
|
|
23
|
-
* @param array - The array of objects to filter.
|
|
24
|
-
* @param conditions - An object where keys represent the property names and values represent filter conditions.
|
|
25
|
-
* The conditions can be a function `(value: T[K]) => boolean`.
|
|
26
|
-
* @returns The filtered array of objects.
|
|
27
|
-
* @throws `Error` If the input is not a valid array.
|
|
28
|
-
*/
|
|
29
12
|
const filterArrayOfObjects = (array, conditions) => {
|
|
30
13
|
if (!Array.isArray(array)) {
|
|
31
14
|
throw new Error('The provided input is not a valid array!');
|
|
@@ -38,12 +21,6 @@ const filterArrayOfObjects = (array, conditions) => {
|
|
|
38
21
|
}));
|
|
39
22
|
};
|
|
40
23
|
exports.filterArrayOfObjects = filterArrayOfObjects;
|
|
41
|
-
/**
|
|
42
|
-
* * Checks if a value is an empty array or an array with only empty values.
|
|
43
|
-
*
|
|
44
|
-
* @param value - The value to check.
|
|
45
|
-
* @returns `true` if the value is not an array, an empty array, or an array containing only `null`, `undefined`, empty objects, or empty arrays.
|
|
46
|
-
*/
|
|
47
24
|
const isInvalidOrEmptyArray = (value) => {
|
|
48
25
|
if (!Array.isArray(value))
|
|
49
26
|
return true;
|
|
@@ -54,12 +31,6 @@ const isInvalidOrEmptyArray = (value) => {
|
|
|
54
31
|
(typeof item === 'object' && Object.keys(item || {})?.length === 0));
|
|
55
32
|
};
|
|
56
33
|
exports.isInvalidOrEmptyArray = isInvalidOrEmptyArray;
|
|
57
|
-
/**
|
|
58
|
-
* * Shuffle the elements of an array.
|
|
59
|
-
*
|
|
60
|
-
* @param array Array to shuffle.
|
|
61
|
-
* @returns Shuffled array.
|
|
62
|
-
*/
|
|
63
34
|
const shuffleArray = (array) => {
|
|
64
35
|
if ((0, exports.isInvalidOrEmptyArray)(array))
|
|
65
36
|
return array;
|
|
@@ -71,12 +42,6 @@ const shuffleArray = (array) => {
|
|
|
71
42
|
return shuffled;
|
|
72
43
|
};
|
|
73
44
|
exports.shuffleArray = shuffleArray;
|
|
74
|
-
/**
|
|
75
|
-
* * Get the last element of an array.
|
|
76
|
-
*
|
|
77
|
-
* @param array Array to get the last element from.
|
|
78
|
-
* @returns The last element or `undefined` if the array is empty.
|
|
79
|
-
*/
|
|
80
45
|
const getLastArrayElement = (array) => {
|
|
81
46
|
return array?.length > 0 ? array[array?.length - 1] : undefined;
|
|
82
47
|
};
|
package/dist/cjs/array/calc.js
CHANGED
|
@@ -9,19 +9,6 @@ const non_primitives_1 = require("../guards/non-primitives");
|
|
|
9
9
|
const basics_1 = require("../number/basics");
|
|
10
10
|
const helpers_1 = require("./helpers");
|
|
11
11
|
const transform_1 = require("./transform");
|
|
12
|
-
/**
|
|
13
|
-
* * Calculates the sum of differences between two numeric fields for each item in the array.
|
|
14
|
-
*
|
|
15
|
-
* @param data - The array of objects to process.
|
|
16
|
-
* @param first - The field name to subtract **from** (minuend), supports nested dot notation.
|
|
17
|
-
* @param second - The field name to subtract (subtrahend), supports nested dot notation.
|
|
18
|
-
* @param roundTo - Decimal places to round the result to. Defaults to 2.
|
|
19
|
-
* @returns The total sum of differences between the two fields across all items.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* sumFieldDifference([{ buy: 10, sell: 3 }, { buy: 8, sell: 5 }], 'buy', 'sell');
|
|
23
|
-
* // => 10
|
|
24
|
-
*/
|
|
25
12
|
function sumFieldDifference(data, first, second, roundTo = 2) {
|
|
26
13
|
if (!(0, non_primitives_1.isValidArray)(data))
|
|
27
14
|
return 0;
|
|
@@ -30,55 +17,18 @@ function sumFieldDifference(data, first, second, roundTo = 2) {
|
|
|
30
17
|
}, 0);
|
|
31
18
|
return (0, basics_1.roundNumber)(total, roundTo);
|
|
32
19
|
}
|
|
33
|
-
/**
|
|
34
|
-
* * Calculates the total sum of a numeric field across all items.
|
|
35
|
-
*
|
|
36
|
-
* @param data - The array of objects to process.
|
|
37
|
-
* @param field - The field to sum values from. Supports nested dot notation.
|
|
38
|
-
* @param roundTo - Decimal places to round the result to. Defaults to 2.
|
|
39
|
-
* @returns The rounded total sum.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* sumByField([{ a: 5 }, { a: 3 }], 'a');
|
|
43
|
-
* // => 8
|
|
44
|
-
*/
|
|
45
20
|
function sumByField(data, field, roundTo = 2) {
|
|
46
21
|
if (!(0, non_primitives_1.isValidArray)(data))
|
|
47
22
|
return 0;
|
|
48
23
|
const total = data?.reduce((acc, item) => acc + (0, helpers_1._getNumericProp)(item, field), 0);
|
|
49
24
|
return (0, basics_1.roundNumber)(total, roundTo);
|
|
50
25
|
}
|
|
51
|
-
/**
|
|
52
|
-
* * Calculates the average of a numeric field across all items.
|
|
53
|
-
*
|
|
54
|
-
* @param data - The array of objects to process.
|
|
55
|
-
* @param field - The field to calculate the average from. Supports nested dot notation.
|
|
56
|
-
* @param roundTo - Decimal places to round the result to. Defaults to 2.
|
|
57
|
-
* @returns The rounded average.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* averageByField([{ a: 4 }, { a: 6 }], 'a');
|
|
61
|
-
* // => 5
|
|
62
|
-
*/
|
|
63
26
|
function averageByField(data, field, roundTo = 2) {
|
|
64
27
|
if (!(0, non_primitives_1.isValidArray)(data))
|
|
65
28
|
return 0;
|
|
66
29
|
const total = data?.reduce((acc, item) => acc + (0, helpers_1._getNumericProp)(item, field), 0);
|
|
67
30
|
return (0, basics_1.roundNumber)(total / data.length, roundTo);
|
|
68
31
|
}
|
|
69
|
-
/**
|
|
70
|
-
* * Groups an array of objects by a primitive field and sums another numeric field per group.
|
|
71
|
-
*
|
|
72
|
-
* @param data - The array of objects to group.
|
|
73
|
-
* @param groupBy - The field to group by. Supports nested dot notation.
|
|
74
|
-
* @param sumBy - The numeric field to sum within each group. Supports nested dot notation.
|
|
75
|
-
* @param roundTo - Decimal places to round each group’s result to. Defaults to 2.
|
|
76
|
-
* @returns An array of records, each with the group key and its corresponding summed value.
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* groupAndSumByField([{ type: 'A', val: 2 }, { type: 'A', val: 3 }, { type: 'B', val: 1 }], 'type', 'val');
|
|
80
|
-
* // => [{ A: 5 }, { B: 1 }]
|
|
81
|
-
*/
|
|
82
32
|
function groupAndSumByField(data, groupBy, sumBy, roundTo = 2) {
|
|
83
33
|
if (!(0, non_primitives_1.isValidArray)(data))
|
|
84
34
|
return [];
|
|
@@ -88,19 +38,6 @@ function groupAndSumByField(data, groupBy, sumBy, roundTo = 2) {
|
|
|
88
38
|
}));
|
|
89
39
|
return result;
|
|
90
40
|
}
|
|
91
|
-
/**
|
|
92
|
-
* * Groups an array of objects by a primitive field and averages another numeric field per group.
|
|
93
|
-
*
|
|
94
|
-
* @param data - The array of objects to group.
|
|
95
|
-
* @param groupBy - The field to group by. Supports nested dot notation.
|
|
96
|
-
* @param averageBy - The numeric field to average within each group. Supports nested dot notation.
|
|
97
|
-
* @param roundTo - Decimal places to round each group’s average to. Defaults to 2.
|
|
98
|
-
* @returns An array of records, each with the group key and its corresponding average value.
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* groupAndAverageByField([{ type: 'A', val: 2 }, { type: 'A', val: 4 }, { type: 'B', val: 6 }], 'type', 'val');
|
|
102
|
-
* // => [{ A: 3 }, { B: 6 }]
|
|
103
|
-
*/
|
|
104
41
|
function groupAndAverageByField(data, groupBy, averageBy, roundTo = 2) {
|
|
105
42
|
if (!(0, non_primitives_1.isValidArray)(data))
|
|
106
43
|
return [];
|
|
@@ -4,13 +4,6 @@ exports._resolveNestedKey = _resolveNestedKey;
|
|
|
4
4
|
exports._getNumericProp = _getNumericProp;
|
|
5
5
|
const non_primitives_1 = require("../guards/non-primitives");
|
|
6
6
|
const utilities_1 = require("../number/utilities");
|
|
7
|
-
/**
|
|
8
|
-
* Safely resolves nested keys from a dot-separated string like "user.city".
|
|
9
|
-
*
|
|
10
|
-
* @param obj - The source object
|
|
11
|
-
* @param path - The nested path string (e.g. "user.city")
|
|
12
|
-
* @returns The resolved value or `undefined`
|
|
13
|
-
*/
|
|
14
7
|
function _resolveNestedKey(obj, path) {
|
|
15
8
|
if ((0, non_primitives_1.isNotEmptyObject)(obj)) {
|
|
16
9
|
return path?.split('.').reduce((acc, key) => {
|
|
@@ -20,14 +13,6 @@ function _resolveNestedKey(obj, path) {
|
|
|
20
13
|
}, obj);
|
|
21
14
|
}
|
|
22
15
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Retrieves a numeric value from a nested property in dot notation.
|
|
25
|
-
* Falls back to 0 if value is not a number or numeric string.
|
|
26
|
-
*
|
|
27
|
-
* @param obj - The source object to read from.
|
|
28
|
-
* @param path - The path string like 'user.income.tax'.
|
|
29
|
-
* @returns The numeric value at that path, or 0 if not valid.
|
|
30
|
-
*/
|
|
31
16
|
function _getNumericProp(obj, path) {
|
|
32
17
|
if ((0, non_primitives_1.isNotEmptyObject)(obj)) {
|
|
33
18
|
const value = path?.split('.').reduce((acc, key) => {
|
package/dist/cjs/array/sort.js
CHANGED
|
@@ -4,34 +4,18 @@ exports.sortAnArray = sortAnArray;
|
|
|
4
4
|
const non_primitives_1 = require("../guards/non-primitives");
|
|
5
5
|
const primitives_1 = require("../guards/primitives");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
-
/**
|
|
8
|
-
* * Sorts an array of strings, numbers, booleans, or objects based on the provided options.
|
|
9
|
-
*
|
|
10
|
-
* - If the array contains strings, it sorts them alphabetically.
|
|
11
|
-
* - If the array contains numbers, it sorts them numerically.
|
|
12
|
-
* - If the array contains booleans, it sorts them by their boolean value.
|
|
13
|
-
* - If the array contains objects, it sorts them by the specified field in the options `sortByField`.
|
|
14
|
-
*
|
|
15
|
-
* @param array - The array to sort.
|
|
16
|
-
* @param options - Sorting options for objects.
|
|
17
|
-
* @returns The sorted array.
|
|
18
|
-
*/
|
|
19
7
|
function sortAnArray(array, options) {
|
|
20
8
|
if (!(0, non_primitives_1.isValidArray)(array))
|
|
21
9
|
return array;
|
|
22
|
-
// Check if the array contains strings
|
|
23
10
|
if ((0, non_primitives_1.isArrayOfType)(array, primitives_1.isString)) {
|
|
24
11
|
return [...array].sort((a, b) => options?.sortOrder === 'desc' ? (0, utils_1.naturalSort)(b, a) : (0, utils_1.naturalSort)(a, b));
|
|
25
12
|
}
|
|
26
|
-
// Check if the array contains numbers
|
|
27
13
|
if ((0, non_primitives_1.isArrayOfType)(array, primitives_1.isNumber)) {
|
|
28
14
|
return [...array].sort((a, b) => (options?.sortOrder === 'desc' ? b - a : a - b));
|
|
29
15
|
}
|
|
30
|
-
// Check if the array contains booleans
|
|
31
16
|
if ((0, non_primitives_1.isArrayOfType)(array, primitives_1.isBoolean)) {
|
|
32
17
|
return [...array].sort((a, b) => options?.sortOrder === 'desc' ? Number(b) - Number(a) : Number(a) - Number(b));
|
|
33
18
|
}
|
|
34
|
-
// Handle array of objects
|
|
35
19
|
if ((0, non_primitives_1.isArrayOfType)(array, non_primitives_1.isObject) && options && 'sortByField' in options) {
|
|
36
20
|
return [...array].sort((a, b) => {
|
|
37
21
|
const _getKeyValue = (obj, path) => {
|
|
@@ -12,13 +12,6 @@ const non_primitives_1 = require("../guards/non-primitives");
|
|
|
12
12
|
const primitives_1 = require("../guards/primitives");
|
|
13
13
|
const index_1 = require("../utils/index");
|
|
14
14
|
const helpers_1 = require("./helpers");
|
|
15
|
-
/**
|
|
16
|
-
* * Converts an array of objects into a formatted array of options.
|
|
17
|
-
*
|
|
18
|
-
* @param data - An array of objects to convert into options.
|
|
19
|
-
* @param config - The configuration object to specify the keys for the `value` (firstFieldName) and `label` (secondFieldName) fields and rename as needed.
|
|
20
|
-
* @returns An array of options, where each option has `value` and `label` fields as default or as specified by user in the config options.
|
|
21
|
-
*/
|
|
22
15
|
function createOptionsArray(data, config) {
|
|
23
16
|
const { firstFieldKey, secondFieldKey, firstFieldName = 'value', secondFieldName = 'label', retainNumberValue = false, } = config || {};
|
|
24
17
|
if (data && data?.length) {
|
|
@@ -36,21 +29,9 @@ function createOptionsArray(data, config) {
|
|
|
36
29
|
return [];
|
|
37
30
|
}
|
|
38
31
|
}
|
|
39
|
-
/**
|
|
40
|
-
* * Removes duplicate values from an array, supporting deep comparison for objects and arrays.
|
|
41
|
-
*
|
|
42
|
-
* @param array - The array from which duplicates need to be removed.
|
|
43
|
-
* @returns A new array with duplicates removed.
|
|
44
|
-
*/
|
|
45
32
|
function removeDuplicatesFromArray(array) {
|
|
46
33
|
return array?.filter((item, index, self) => index === self?.findIndex((el) => (0, index_1.isDeepEqual)(el, item)));
|
|
47
34
|
}
|
|
48
|
-
/**
|
|
49
|
-
* * Finds duplicate values in an array, runs deep comparison for objects and arrays.
|
|
50
|
-
*
|
|
51
|
-
* @param array - The array in which to find duplicates.
|
|
52
|
-
* @returns An array containing all duplicate entries (each one only once).
|
|
53
|
-
*/
|
|
54
35
|
function getDuplicates(array) {
|
|
55
36
|
const seen = [];
|
|
56
37
|
const duplicates = [];
|
|
@@ -66,34 +47,11 @@ function getDuplicates(array) {
|
|
|
66
47
|
}
|
|
67
48
|
return duplicates;
|
|
68
49
|
}
|
|
69
|
-
/**
|
|
70
|
-
* * Finds elements missing from one array compared to another using deep comparison.
|
|
71
|
-
*
|
|
72
|
-
* @param options - Configuration to specify which array to compare and direction of check.
|
|
73
|
-
* @returns An array of missing elements based on the comparison direction.
|
|
74
|
-
*/
|
|
75
|
-
/**
|
|
76
|
-
* * Finds elements missing from one array compared to another using deep comparison.
|
|
77
|
-
*
|
|
78
|
-
* @param array1 The first array to compare.
|
|
79
|
-
* @param array2 The second array to compare.
|
|
80
|
-
* @param missingFrom Which direction to compare for missing values:.
|
|
81
|
-
* - `'from-first'` → values in `array1` missing in `array2`.
|
|
82
|
-
* - `'from-second'` → values in `array2` missing in `array1`.
|
|
83
|
-
* @returns An array of missing elements based on the comparison direction.
|
|
84
|
-
*/
|
|
85
50
|
function findMissingElements(array1, array2, missingFrom) {
|
|
86
51
|
const source = (missingFrom === 'from-first' ? array1 : array2) ?? [];
|
|
87
52
|
const target = (missingFrom === 'from-first' ? array2 : array1) ?? [];
|
|
88
53
|
return source.filter((s) => !target?.some((t) => (0, index_1.isDeepEqual)(t, s)));
|
|
89
54
|
}
|
|
90
|
-
/**
|
|
91
|
-
* * Splits an array into chunks of a given size.
|
|
92
|
-
*
|
|
93
|
-
* @param arr The array to split.
|
|
94
|
-
* @param chunkSize The size of each chunk.
|
|
95
|
-
* @returns An array of chunked arrays.
|
|
96
|
-
*/
|
|
97
55
|
function splitArray(arr, chunkSize) {
|
|
98
56
|
const result = [];
|
|
99
57
|
for (let i = 0; i < arr?.length; i += chunkSize) {
|
|
@@ -101,22 +59,6 @@ function splitArray(arr, chunkSize) {
|
|
|
101
59
|
}
|
|
102
60
|
return result;
|
|
103
61
|
}
|
|
104
|
-
/**
|
|
105
|
-
* * Group an array of objects by a specified key, returning only arrays of grouped objects.
|
|
106
|
-
*
|
|
107
|
-
* @param source - The source array of objects to group.
|
|
108
|
-
* @param property - The property to group the array by. Property can be a string, number, boolean, undefined or null. Supports nested dot notation.
|
|
109
|
-
*
|
|
110
|
-
* @returns An array of grouped arrays. Each sub-array contains objects that share the same value for the specified property.
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* splitArrayByProperty([{ type: 'a' }, { type: 'b' }, { type: 'a' }, { type: undefined }], 'type')
|
|
114
|
-
* // => [ [{ type: 'a' }, { type: 'a' }], [{ type: 'b' }], [{ type: undefined }] ]
|
|
115
|
-
*
|
|
116
|
-
* @notes
|
|
117
|
-
* - Returns an empty array if the input is invalid or empty.
|
|
118
|
-
* - Groups objects even when the group key is `undefined` or `null` (object with `null` & `undefined` property-values are grouped together).
|
|
119
|
-
*/
|
|
120
62
|
function splitArrayByProperty(source, property) {
|
|
121
63
|
if (!(0, non_primitives_1.isValidArray)(source))
|
|
122
64
|
return [];
|
|
@@ -131,13 +73,6 @@ function splitArrayByProperty(source, property) {
|
|
|
131
73
|
});
|
|
132
74
|
return Object.values(grouped);
|
|
133
75
|
}
|
|
134
|
-
/**
|
|
135
|
-
* * Rotates an array left or right by a given number of steps.
|
|
136
|
-
*
|
|
137
|
-
* @param arr The array to rotate.
|
|
138
|
-
* @param steps The number of positions to rotate (positive: right, negative: left).
|
|
139
|
-
* @returns The rotated array.
|
|
140
|
-
*/
|
|
141
76
|
function rotateArray(arr, steps) {
|
|
142
77
|
const length = arr?.length;
|
|
143
78
|
if (length === 0)
|
|
@@ -145,14 +80,6 @@ function rotateArray(arr, steps) {
|
|
|
145
80
|
const offset = ((steps % length) + length) % length;
|
|
146
81
|
return arr.slice(-offset).concat(arr.slice(0, -offset));
|
|
147
82
|
}
|
|
148
|
-
/**
|
|
149
|
-
* * Moves an element within an array from one index to another.
|
|
150
|
-
*
|
|
151
|
-
* @param arr The array to modify.
|
|
152
|
-
* @param fromIndex The index of the element to move.
|
|
153
|
-
* @param toIndex The new index for the element.
|
|
154
|
-
* @returns A new array with the element moved.
|
|
155
|
-
*/
|
|
156
83
|
function moveArrayElement(arr, fromIndex, toIndex) {
|
|
157
84
|
const newArr = [...arr];
|
|
158
85
|
const [item] = newArr.splice(fromIndex, 1);
|
package/dist/cjs/array/utils.js
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.naturalSort = naturalSort;
|
|
4
|
-
/**
|
|
5
|
-
* * Compare two strings using natural sorting (e.g., "file2" < "file10").
|
|
6
|
-
* Optionally supports case-insensitive and locale-aware string chunk comparisons.
|
|
7
|
-
*
|
|
8
|
-
* @param a - The first string to compare.
|
|
9
|
-
* @param b - The second string to compare.
|
|
10
|
-
* @param options - Optional settings to configure comparison behavior.
|
|
11
|
-
* @param options.caseInsensitive - If true, compares string chunks without case sensitivity. Defaults to `true`.
|
|
12
|
-
* @param options.localeAware - If true, uses localeCompare for string chunk comparisons. Defaults to `false`.
|
|
13
|
-
* @returns A negative number if `a` comes before `b`, a positive number if `a` comes after `b`, or 0 if equal.
|
|
14
|
-
*/
|
|
15
4
|
function naturalSort(a, b, options) {
|
|
16
5
|
const { caseInsensitive = true, localeAware = false } = options || {};
|
|
17
|
-
/**
|
|
18
|
-
* * Splits a string into an array of number and non-number chunks.
|
|
19
|
-
* @param str - The string to split.
|
|
20
|
-
* @returns An array of string and number parts.
|
|
21
|
-
*/
|
|
22
6
|
const _createChunks = (str) => {
|
|
23
7
|
const chunks = [];
|
|
24
8
|
let current = '';
|
|
@@ -49,16 +33,13 @@ function naturalSort(a, b, options) {
|
|
|
49
33
|
for (let i = 0; i < Math.min(aChunks?.length, bChunks?.length); i++) {
|
|
50
34
|
let aChunk = aChunks[i];
|
|
51
35
|
let bChunk = bChunks[i];
|
|
52
|
-
// Normalize string chunks if case-insensitive
|
|
53
36
|
if (caseInsensitive && typeof aChunk === 'string' && typeof bChunk === 'string') {
|
|
54
37
|
aChunk = aChunk?.toLowerCase();
|
|
55
38
|
bChunk = bChunk?.toLowerCase();
|
|
56
39
|
}
|
|
57
|
-
// Compare types: number vs string
|
|
58
40
|
if (typeof aChunk !== typeof bChunk) {
|
|
59
41
|
return typeof aChunk === 'string' ? 1 : -1;
|
|
60
42
|
}
|
|
61
|
-
// Compare same-type chunks
|
|
62
43
|
if (aChunk !== bChunk) {
|
|
63
44
|
if (typeof aChunk === 'number' && typeof bChunk === 'number') {
|
|
64
45
|
return aChunk - bChunk;
|