nhb-toolbox 4.0.80 → 4.0.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/array/Finder.js +289 -0
- package/dist/cjs/colors/Color.js +1 -1
- package/dist/cjs/index.js +6 -4
- package/dist/dts/array/Finder.d.ts +74 -0
- package/dist/dts/array/Finder.d.ts.map +1 -0
- package/dist/dts/array/types.d.ts +15 -0
- package/dist/dts/array/types.d.ts.map +1 -1
- package/dist/dts/colors/Color.d.ts +1 -1
- package/dist/dts/index.d.ts +1 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/array/Finder.js +285 -0
- package/dist/esm/colors/Color.js +1 -1
- package/dist/esm/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
+
class Finder {
|
|
9
|
+
static DEFAULT_TTL = 1000 * 60 * 5;
|
|
10
|
+
#cache = new Map();
|
|
11
|
+
#sortedCache = new Map();
|
|
12
|
+
#ttl;
|
|
13
|
+
#items;
|
|
14
|
+
/**
|
|
15
|
+
* * Creates a new `Finder` instance.
|
|
16
|
+
*
|
|
17
|
+
* @param ttl Time-to-live (in milliseconds) for cached search results. Defaults to {@link Finder.DEFAULT_TTL 5 Minutes}.
|
|
18
|
+
* @param items The initial array of items to be used for searching.
|
|
19
|
+
*/
|
|
20
|
+
constructor(ttl = Finder.DEFAULT_TTL, items) {
|
|
21
|
+
this.#ttl = ttl;
|
|
22
|
+
this.#items = items;
|
|
23
|
+
}
|
|
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
|
+
clearCache(key) {
|
|
29
|
+
if (key) {
|
|
30
|
+
this.#cache.delete(key);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this.#cache.clear();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
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
|
+
findAll(matcher, keySelector, options) {
|
|
43
|
+
const { fuzzy = false, needSorting = true, cacheKey = 'finder-cache', forceBinary = false, caseInsensitive = true, data, } = options ?? {};
|
|
44
|
+
const source = typeof data === 'function' ? data() : (data ?? this.#items);
|
|
45
|
+
if (!source?.length)
|
|
46
|
+
return [];
|
|
47
|
+
const rawGetKey = typeof keySelector === 'function' ? keySelector : ((item) => item[keySelector]);
|
|
48
|
+
const getKey = Finder.#createMemoizedKeyGetter(rawGetKey);
|
|
49
|
+
const normalizedMatcher = caseInsensitive && typeof matcher === 'string' ?
|
|
50
|
+
matcher.toLowerCase()
|
|
51
|
+
: matcher;
|
|
52
|
+
if (cacheKey) {
|
|
53
|
+
const entry = this.#cache.get(cacheKey);
|
|
54
|
+
if (entry && Date.now() - entry.timestamp < this.#ttl) {
|
|
55
|
+
return entry.result;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.#cache.delete(cacheKey);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
let results = [];
|
|
62
|
+
if (source.length < 100 && !forceBinary) {
|
|
63
|
+
results = source.filter((item) => {
|
|
64
|
+
const key = getKey(item);
|
|
65
|
+
const value = caseInsensitive && typeof key === 'string' ?
|
|
66
|
+
key.toLowerCase()
|
|
67
|
+
: key;
|
|
68
|
+
return value === normalizedMatcher;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const sorted = needSorting ?
|
|
73
|
+
this.#sortAndCache(source, getKey, cacheKey)
|
|
74
|
+
: source;
|
|
75
|
+
const firstMatch = this.binarySearch(sorted, normalizedMatcher, getKey, caseInsensitive);
|
|
76
|
+
if (firstMatch) {
|
|
77
|
+
const baseKey = getKey(firstMatch);
|
|
78
|
+
const base = caseInsensitive && typeof baseKey === 'string' ?
|
|
79
|
+
baseKey.toLowerCase()
|
|
80
|
+
: baseKey;
|
|
81
|
+
results = sorted.filter((item) => {
|
|
82
|
+
const key = getKey(item);
|
|
83
|
+
const value = caseInsensitive && typeof key === 'string' ?
|
|
84
|
+
key.toLowerCase()
|
|
85
|
+
: key;
|
|
86
|
+
return value === base;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (!results.length && fuzzy && typeof normalizedMatcher === 'string') {
|
|
91
|
+
results = source.filter((item) => {
|
|
92
|
+
const rawKey = getKey(item);
|
|
93
|
+
const key = caseInsensitive && typeof rawKey === 'string' ?
|
|
94
|
+
rawKey.toLowerCase()
|
|
95
|
+
: String(rawKey);
|
|
96
|
+
return this.#match(key, normalizedMatcher);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (cacheKey) {
|
|
100
|
+
this.#cache.set(cacheKey, {
|
|
101
|
+
result: results,
|
|
102
|
+
timestamp: Date.now(),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return results;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @instance Finds first matching item that matches the provided matcher using optional caching or fuzzy logic.
|
|
109
|
+
* @param matcher The value to match.
|
|
110
|
+
* @param keySelector Property key or selector function.
|
|
111
|
+
* @param options Optional behavior flags and item source.
|
|
112
|
+
*/
|
|
113
|
+
findOne(matcher, keySelector, options) {
|
|
114
|
+
const { fuzzy = false, needSorting = true, cacheKey = 'finder-cache', forceBinary = false, caseInsensitive = true, data, } = options ?? {};
|
|
115
|
+
const source = typeof data === 'function' ? data() : (data ?? this.#items);
|
|
116
|
+
if (!source?.length)
|
|
117
|
+
return undefined;
|
|
118
|
+
const rawGetKey = typeof keySelector === 'function' ? keySelector : ((item) => item[keySelector]);
|
|
119
|
+
const getKey = Finder.#createMemoizedKeyGetter(rawGetKey);
|
|
120
|
+
const normalizedMatcher = caseInsensitive && typeof matcher === 'string' ?
|
|
121
|
+
matcher.toLowerCase()
|
|
122
|
+
: matcher;
|
|
123
|
+
if (cacheKey) {
|
|
124
|
+
const entry = this.#cache.get(cacheKey);
|
|
125
|
+
if (entry && Date.now() - entry.timestamp < this.#ttl) {
|
|
126
|
+
return entry.result[0];
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
this.#cache.delete(cacheKey);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
let result;
|
|
133
|
+
if (source.length < 100 && !forceBinary) {
|
|
134
|
+
result = source.find((item) => {
|
|
135
|
+
const key = getKey(item);
|
|
136
|
+
const value = caseInsensitive && typeof key === 'string' ?
|
|
137
|
+
key.toLowerCase()
|
|
138
|
+
: key;
|
|
139
|
+
return value === normalizedMatcher;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
result = this.binarySearch(needSorting ?
|
|
144
|
+
this.#sortAndCache(source, getKey, cacheKey)
|
|
145
|
+
: source, normalizedMatcher, getKey, caseInsensitive);
|
|
146
|
+
}
|
|
147
|
+
if (!result && fuzzy && typeof normalizedMatcher === 'string') {
|
|
148
|
+
return this.fuzzySearch(source, normalizedMatcher, getKey, caseInsensitive);
|
|
149
|
+
}
|
|
150
|
+
if (cacheKey && result) {
|
|
151
|
+
this.#cache.set(cacheKey, {
|
|
152
|
+
result: [result],
|
|
153
|
+
timestamp: Date.now(),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* @instance Asynchronous variant of `findAll` that accepts a promise-based data supplier.
|
|
160
|
+
* @param supplier Async function resolving the items list.
|
|
161
|
+
* @param matcher The value to match.
|
|
162
|
+
* @param keySelector Property key or selector function.
|
|
163
|
+
* @param options Optional settings for search behavior and cache.
|
|
164
|
+
*/
|
|
165
|
+
async findAllAsync(supplier, matcher, keySelector, options) {
|
|
166
|
+
const items = await supplier();
|
|
167
|
+
return this.findAll(matcher, keySelector, { ...options, data: items });
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* @instance Asynchronous variant of `findOne`.
|
|
171
|
+
* @param supplier Async function resolving the items list.
|
|
172
|
+
* @param matcher The value to match.
|
|
173
|
+
* @param keySelector Property key or selector function.
|
|
174
|
+
* @param options Optional settings for behavior and cache.
|
|
175
|
+
*/
|
|
176
|
+
async findOneAsync(supplier, matcher, keySelector, options) {
|
|
177
|
+
const items = await supplier();
|
|
178
|
+
return this.findOne(matcher, keySelector, { ...options, data: items });
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* @instance Performs a binary search on a sorted array using a custom key selector.
|
|
182
|
+
*
|
|
183
|
+
* @param sorted - The sorted array of items to search.
|
|
184
|
+
* @param matcher - The value to search for.
|
|
185
|
+
* @param keySelector - A function that extracts the comparable key from each item.
|
|
186
|
+
* @param caseInsensitive - Whether to compare string keys ignoring case.
|
|
187
|
+
* @returns The first matching item if found; otherwise, undefined.
|
|
188
|
+
*/
|
|
189
|
+
binarySearch(sorted, matcher, keySelector, caseInsensitive) {
|
|
190
|
+
let min = 0, max = sorted.length - 1;
|
|
191
|
+
while (min <= max) {
|
|
192
|
+
const mid = Math.floor((min + max) / 2);
|
|
193
|
+
const midKey = keySelector(sorted[mid]);
|
|
194
|
+
const key = caseInsensitive && typeof midKey === 'string' ?
|
|
195
|
+
midKey.toLowerCase()
|
|
196
|
+
: midKey;
|
|
197
|
+
if (key === matcher)
|
|
198
|
+
return sorted[mid];
|
|
199
|
+
if (key < matcher)
|
|
200
|
+
min = mid + 1;
|
|
201
|
+
else
|
|
202
|
+
max = mid - 1;
|
|
203
|
+
}
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* @instance Performs a fuzzy search on an array by matching characters in sequence.
|
|
208
|
+
*
|
|
209
|
+
* @param array - The array of items to search.
|
|
210
|
+
* @param matcher - The fuzzy search string to match against.
|
|
211
|
+
* @param keySelector - A function that extracts the key to search from each item.
|
|
212
|
+
* @param caseInsensitive - Whether to compare ignoring case for string values.
|
|
213
|
+
* @returns The first fuzzy-matching item if found; otherwise, undefined.
|
|
214
|
+
*/
|
|
215
|
+
fuzzySearch(array, matcher, keySelector, caseInsensitive) {
|
|
216
|
+
for (const item of array) {
|
|
217
|
+
const rawKey = keySelector(item);
|
|
218
|
+
const key = caseInsensitive && typeof rawKey === 'string' ?
|
|
219
|
+
rawKey.toLowerCase()
|
|
220
|
+
: String(rawKey);
|
|
221
|
+
if (this.#match(key, matcher))
|
|
222
|
+
return item;
|
|
223
|
+
}
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* @private Checks if the characters in the target string appear in order within the source string.
|
|
228
|
+
* @param source Source string to search within.
|
|
229
|
+
* @param target Target string to match against the source string.
|
|
230
|
+
* @returns True if the target string is a fuzzy match within the source string; otherwise, false.
|
|
231
|
+
*/
|
|
232
|
+
#match(source, target) {
|
|
233
|
+
let i = 0;
|
|
234
|
+
for (const char of target) {
|
|
235
|
+
i = source.indexOf(char, i);
|
|
236
|
+
if (i === -1)
|
|
237
|
+
return false;
|
|
238
|
+
i++;
|
|
239
|
+
}
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* @private Sorts an array and caches the result for a specified time-to-live (TTL).
|
|
244
|
+
* @param data Data to sort and cache.
|
|
245
|
+
* @param getKey Key extraction function.
|
|
246
|
+
* @param cacheKey Optional cache key for storing the result.
|
|
247
|
+
* @returns
|
|
248
|
+
*/
|
|
249
|
+
#sortAndCache(data, getKey, cacheKey) {
|
|
250
|
+
if (cacheKey) {
|
|
251
|
+
const entry = this.#sortedCache.get(cacheKey);
|
|
252
|
+
if (entry && Date.now() - entry.timestamp < this.#ttl) {
|
|
253
|
+
return entry.result;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
this.#sortedCache.delete(cacheKey);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const sorted = [...data].sort((a, b) => {
|
|
260
|
+
const keyA = getKey(a);
|
|
261
|
+
const keyB = getKey(b);
|
|
262
|
+
return (keyA < keyB ? -1
|
|
263
|
+
: keyA > keyB ? 1
|
|
264
|
+
: 0);
|
|
265
|
+
});
|
|
266
|
+
if (cacheKey) {
|
|
267
|
+
this.#sortedCache.set(cacheKey, {
|
|
268
|
+
result: sorted,
|
|
269
|
+
timestamp: Date.now(),
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
return sorted;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* @static @private Creates a memoized version of a key extractor.
|
|
276
|
+
* @param getKey Original key extraction function
|
|
277
|
+
*/
|
|
278
|
+
static #createMemoizedKeyGetter(getKey) {
|
|
279
|
+
const cache = new Map();
|
|
280
|
+
return (item) => {
|
|
281
|
+
if (cache.has(item))
|
|
282
|
+
return cache.get(item);
|
|
283
|
+
const key = getKey(item);
|
|
284
|
+
cache.set(item, key);
|
|
285
|
+
return key;
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
exports.Finder = Finder;
|
package/dist/cjs/colors/Color.js
CHANGED
|
@@ -383,7 +383,7 @@ class Color {
|
|
|
383
383
|
return (0, helpers_1._isHSLA)(color);
|
|
384
384
|
}
|
|
385
385
|
/**
|
|
386
|
-
*
|
|
386
|
+
* @static Checks if a color is a valid CSS color name.
|
|
387
387
|
* - This method checks against a predefined list of CSS color names.
|
|
388
388
|
* - It does not validate format types like Hex, RGB, or HSL or their alpha channels.
|
|
389
389
|
*
|
package/dist/cjs/index.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFibonacciNumbers = exports.getFibonacci = exports.generateFibonacci = exports.fibonacciGenerator = exports.calculatePercentage = exports.UnitConverter = exports.Unit = exports.Currency = exports.sumOfNumbers = exports.sumNumbers = exports.sumDigits = exports.reverseNumber = exports.getSumOfNumbers = exports.getRandomNumber = exports.getAverageOfNumbers = exports.getAverage = exports.convertToDecimal = exports.calculateLCM = exports.calculateLCD = exports.calculateHCF = exports.calculateGCD = exports.calculateAverage = exports.wordCount = exports.levenshteinDistance = exports.getLevenshteinDistance = exports.extractNumbersFromString = exports.countWordsInString = exports.countWords = exports.slugifyString = exports.reverseString = exports.replaceAllInString = exports.normalizeString = exports.maskString = exports.formatWithPlural = exports.formatUnitWithPlural = exports.formatNumberWithPluralUnit = exports.extractURLs = exports.extractEmails = exports.convertStringCase = exports.isSnakeCase = exports.isPascalCase = exports.isPalindrome = exports.isKebabCase = exports.isEmojiOnly = exports.isCamelCase = exports.generateAnagrams = exports.truncateString = exports.trimString = exports.generateRandomID = exports.capitalizeString = void 0;
|
|
4
4
|
exports.convertHslaToRgba = exports.convertHslaToHex8 = exports.convertHexToRgb = exports.convertHexToHsl = exports.convertHex8ToRgba = exports.convertHex8ToHsla = exports.convertColorCode = exports.generateRandomHSLColor = exports.generateRandomColorInHexRGB = exports.getColorForInitial = exports.getNumbersInRange = exports.roundToNearestInterval = exports.roundToNearest = exports.roundNumberToNearestInterval = exports.roundNumber = exports.numberToOrdinal = exports.getRandomFloat = exports.getRandomDecimal = exports.getOrdinalNumber = exports.getOrdinal = exports.formatCurrency = exports.convertToOrdinal = exports.convertNumberToOrdinal = exports.convertNumberToCurrency = exports.clampNumber = exports.cardinalToOrdinal = exports.isPrimeNumber = exports.isPrime = exports.getPrimeNumbers = exports.findPrimeNumbers = exports.numberToWords = exports.numericToRoman = exports.convertToRomanNumerals = exports.convertNumberToWords = exports.isPerfectSquare = exports.isParOfFibonacciSeries = exports.isParOfFibonacci = exports.isOddNumber = exports.isOdd = exports.isMultiple = exports.isInvalidNumbers = exports.isFibonacci = exports.isEvenNumber = exports.isEven = exports.areInvalidNumbers = exports.getNthFibonacci = exports.getMemoizedFibonacciSeries = exports.getMemoizedFibonacci = exports.getFibonacciSeriesMemo = exports.getFibonacciSeries = void 0;
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.isValidURL = exports.isValidEmail = exports.isUUID = exports.isURL = exports.isPhoneNumber = exports.isNumericString = exports.isNodeEnvironment = exports.isNodeENV = exports.isNode = exports.isIPAddress = exports.isExpectedNodeENV = exports.isEnvironment = exports.isEmailArray = exports.isEmail = exports.isDateString = exports.isBrowser = exports.isBase64 = exports.isValidSet = exports.isValidObject = exports.isValidMap = exports.isValidJSON = exports.isValidArray = exports.isSet = exports.isReturningPromise = exports.isRegularExpression = exports.isRegExp = exports.isPromise = exports.isObjectWithKeys = exports.isObjectEmpty = exports.isObject = exports.isNotEmptyObject = exports.isMethodDescriptor = exports.isMethod = exports.isMap = exports.isJSONObject = exports.isJSON = exports.isFunction = exports.isError = exports.isEmptyObjectGuard = exports.isEmptyObject = void 0;
|
|
5
|
+
exports.extractDuplicates = exports.createOptionsArray = exports.sortAnArray = exports.Finder = exports.shuffleArray = exports.isValidEmptyArray = exports.isInvalidOrEmptyArray = exports.getLastArrayElement = exports.flattenArray = exports.filterArrayOfObjects = exports.minutesToUTCOffset = exports.getTotalMinutesFromUTC = exports.getTotalMinutesFromTime = exports.getTotalMinutes = exports.getTimeStringFromUTC = exports.getMinutesFromUTC = exports.getCurrentTime = exports.getCurrentDateTime = exports.formatUTCOffset = exports.extractTotalMinutesFromTime = exports.extractTimeStringFromUTC = exports.extractTimeFromUTC = exports.extractMinutesFromUTC = exports.extractHourMinute = exports.convertMinutesToUTCOffset = exports.chronusts = exports.chronusjs = exports.chronus = exports.chronosts = exports.chronosjs = exports.chronos = exports.Chronus = exports.Chronos = exports.isValidUTCOffSet = exports.isValidUTC = exports.isValidTimeString = exports.isValidTime = exports.isLeapYear = exports.greet = exports.getGreeting = exports.generateGreeting = exports.Colour = exports.Color = exports.convertRgbToRgba = exports.convertRgbToHsl = exports.convertRgbToHex = exports.convertRgbaToHsla = exports.convertRgbaToHex8 = exports.convertHslToRgb = exports.convertHslToHex = void 0;
|
|
6
|
+
exports.remapFields = exports.pickObjectFieldsByCondition = exports.pickObjectFields = exports.pickFieldsByCondition = exports.pickFields = exports.convertObjectValues = exports.sanitizeData = exports.parseStringifiedValues = exports.parseStringifiedPrimitives = exports.parseStringifiedObjectValues = exports.parsePrimitives = exports.parsePrimitiveData = exports.parseObjectValues = exports.parseJsonToObject = exports.mergeObjects = exports.mergeAndFlattenObjects = exports.flattenObjectKeyValue = exports.flattenObjectDotNotation = exports.extractUpdatedFields = exports.extractUpdatedAndNewFields = exports.extractNewFields = exports.countObjectFields = exports.cloneObject = exports.isValidFormData = exports.isOriginFileObj = exports.isFileUpload = exports.isFileList = exports.isFileArray = exports.isCustomFileArray = exports.isCustomFile = exports.serializeForm = exports.parseFormData = exports.createFormData = exports.createControlledFormData = exports.convertIntoFormData = exports.naturalSortForString = exports.naturalSort = exports.compareSorter = exports.compareNaturally = exports.splitArray = exports.rotateArray = exports.removeDuplicatesFromArray = exports.removeDuplicates = exports.moveArrayElement = exports.getMissingElements = exports.getDuplicatesFromArray = exports.getDuplicates = exports.findMissingElements = exports.extractMissingElements = exports.extractDuplicatesFromArray = void 0;
|
|
7
|
+
exports.isBigInt = exports.isArrayWithLength = exports.isArrayOfType = exports.isArray = exports.doesReturnPromise = exports.isUndefined = exports.isTruthy = exports.isSymbol = exports.isString = exports.isPrimitive = exports.isPositiveInteger = exports.isNumber = exports.isNull = exports.isNonEmptyString = exports.isInteger = exports.isFalsy = exports.isBoolean = exports.throttleAction = exports.parsePrimitivesDeep = exports.parseJsonDeep = exports.parseJSON = exports.isDeepEqual = exports.getStaticMethodsCount = exports.getStaticMethodNames = exports.getInstanceMethodsCount = exports.getInstanceMethodNames = exports.getClassDetails = exports.deepParsePrimitives = exports.debounceAction = exports.countStaticMethods = exports.countInstanceMethods = exports.convertArrayToString = exports.saveToSessionStorage = exports.saveToLocalStorage = exports.removeFromSessionStorage = exports.removeFromLocalStorage = exports.getFromSessionStorage = exports.getFromLocalStorage = exports.toggleFullScreen = exports.smoothScrollTo = exports.copyToClipboard = exports.updateQueryParam = exports.getQueryStringAsObject = exports.queryStringToObject = exports.parseQueryString = exports.getQueryParams = exports.generateQueryParams = exports.formatQueryParams = exports.createQueryParams = exports.remapObjectFields = void 0;
|
|
8
|
+
exports.isValidURL = exports.isValidEmail = exports.isUUID = exports.isURL = exports.isPhoneNumber = exports.isNumericString = exports.isNodeEnvironment = exports.isNodeENV = exports.isNode = exports.isIPAddress = exports.isExpectedNodeENV = exports.isEnvironment = exports.isEmailArray = exports.isEmail = exports.isDateString = exports.isBrowser = exports.isBase64 = exports.isValidSet = exports.isValidObject = exports.isValidMap = exports.isValidJSON = exports.isValidArray = exports.isSet = exports.isReturningPromise = exports.isRegularExpression = exports.isRegExp = exports.isPromise = exports.isObjectWithKeys = exports.isObjectEmpty = exports.isObject = exports.isNotEmptyObject = exports.isMethodDescriptor = exports.isMethod = exports.isMap = exports.isJSONObject = exports.isJSON = exports.isFunction = exports.isError = exports.isEmptyObjectGuard = exports.isEmptyObject = exports.isDate = void 0;
|
|
9
9
|
// ! String Utilities
|
|
10
10
|
var basics_1 = require("./string/basics");
|
|
11
11
|
Object.defineProperty(exports, "capitalizeString", { enumerable: true, get: function () { return basics_1.capitalizeString; } });
|
|
@@ -182,6 +182,8 @@ Object.defineProperty(exports, "getLastArrayElement", { enumerable: true, get: f
|
|
|
182
182
|
Object.defineProperty(exports, "isInvalidOrEmptyArray", { enumerable: true, get: function () { return basics_3.isInvalidOrEmptyArray; } });
|
|
183
183
|
Object.defineProperty(exports, "isValidEmptyArray", { enumerable: true, get: function () { return basics_3.isInvalidOrEmptyArray; } });
|
|
184
184
|
Object.defineProperty(exports, "shuffleArray", { enumerable: true, get: function () { return basics_3.shuffleArray; } });
|
|
185
|
+
var Finder_1 = require("./array/Finder");
|
|
186
|
+
Object.defineProperty(exports, "Finder", { enumerable: true, get: function () { return Finder_1.Finder; } });
|
|
185
187
|
var sort_1 = require("./array/sort");
|
|
186
188
|
Object.defineProperty(exports, "sortAnArray", { enumerable: true, get: function () { return sort_1.sortAnArray; } });
|
|
187
189
|
var transform_1 = require("./array/transform");
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { FindOptions } from './types';
|
|
2
|
+
type KeySelector<T> = keyof T | ((item: T) => string | number);
|
|
3
|
+
/**
|
|
4
|
+
* The `Finder` class performs optimized searching on arrays.
|
|
5
|
+
* It supports binary search, fuzzy search, and smart caching with TTL.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Finder<T> {
|
|
8
|
+
#private;
|
|
9
|
+
static readonly DEFAULT_TTL: number;
|
|
10
|
+
/**
|
|
11
|
+
* * Creates a new `Finder` instance.
|
|
12
|
+
*
|
|
13
|
+
* @param ttl Time-to-live (in milliseconds) for cached search results. Defaults to {@link Finder.DEFAULT_TTL 5 Minutes}.
|
|
14
|
+
* @param items The initial array of items to be used for searching.
|
|
15
|
+
*/
|
|
16
|
+
constructor(ttl: number | undefined, items: T[]);
|
|
17
|
+
/**
|
|
18
|
+
* @instance Clears cache globally or for a specific key.
|
|
19
|
+
* @param key Optional key to clear only a specific cache entry.
|
|
20
|
+
*/
|
|
21
|
+
clearCache(key?: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* @instance Finds all items that match the provided matcher using optional caching or fuzzy logic.
|
|
24
|
+
* @param matcher The value to match against.
|
|
25
|
+
* @param keySelector Property key or selector function.
|
|
26
|
+
* @param options Optional settings for search behavior and source list.
|
|
27
|
+
*/
|
|
28
|
+
findAll(matcher: string | number, keySelector: KeySelector<T>, options?: FindOptions<T>): T[];
|
|
29
|
+
/**
|
|
30
|
+
* @instance Finds first matching item that matches the provided matcher using optional caching or fuzzy logic.
|
|
31
|
+
* @param matcher The value to match.
|
|
32
|
+
* @param keySelector Property key or selector function.
|
|
33
|
+
* @param options Optional behavior flags and item source.
|
|
34
|
+
*/
|
|
35
|
+
findOne(matcher: string | number, keySelector: KeySelector<T>, options?: FindOptions<T>): T | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* @instance Asynchronous variant of `findAll` that accepts a promise-based data supplier.
|
|
38
|
+
* @param supplier Async function resolving the items list.
|
|
39
|
+
* @param matcher The value to match.
|
|
40
|
+
* @param keySelector Property key or selector function.
|
|
41
|
+
* @param options Optional settings for search behavior and cache.
|
|
42
|
+
*/
|
|
43
|
+
findAllAsync(supplier: () => Promise<T[]>, matcher: string | number, keySelector: KeySelector<T>, options?: Omit<FindOptions<T>, 'items'>): Promise<T[]>;
|
|
44
|
+
/**
|
|
45
|
+
* @instance Asynchronous variant of `findOne`.
|
|
46
|
+
* @param supplier Async function resolving the items list.
|
|
47
|
+
* @param matcher The value to match.
|
|
48
|
+
* @param keySelector Property key or selector function.
|
|
49
|
+
* @param options Optional settings for behavior and cache.
|
|
50
|
+
*/
|
|
51
|
+
findOneAsync(supplier: () => Promise<T[]>, matcher: string | number, keySelector: KeySelector<T>, options?: Omit<FindOptions<T>, 'items'>): Promise<T | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* @instance Performs a binary search on a sorted array using a custom key selector.
|
|
54
|
+
*
|
|
55
|
+
* @param sorted - The sorted array of items to search.
|
|
56
|
+
* @param matcher - The value to search for.
|
|
57
|
+
* @param keySelector - A function that extracts the comparable key from each item.
|
|
58
|
+
* @param caseInsensitive - Whether to compare string keys ignoring case.
|
|
59
|
+
* @returns The first matching item if found; otherwise, undefined.
|
|
60
|
+
*/
|
|
61
|
+
binarySearch(sorted: T[], matcher: string | number, keySelector: (item: T) => string | number, caseInsensitive: boolean): T | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* @instance Performs a fuzzy search on an array by matching characters in sequence.
|
|
64
|
+
*
|
|
65
|
+
* @param array - The array of items to search.
|
|
66
|
+
* @param matcher - The fuzzy search string to match against.
|
|
67
|
+
* @param keySelector - A function that extracts the key to search from each item.
|
|
68
|
+
* @param caseInsensitive - Whether to compare ignoring case for string values.
|
|
69
|
+
* @returns The first fuzzy-matching item if found; otherwise, undefined.
|
|
70
|
+
*/
|
|
71
|
+
fuzzySearch(array: T[], matcher: string, keySelector: (item: T) => string | number, caseInsensitive: boolean): T | undefined;
|
|
72
|
+
}
|
|
73
|
+
export {};
|
|
74
|
+
//# sourceMappingURL=Finder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Finder.d.ts","sourceRoot":"","sources":["../../../src/array/Finder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,KAAK,WAAW,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,CAAC,CAAC;AAG/D;;;GAGG;AACH,qBAAa,MAAM,CAAC,CAAC;;IACpB,MAAM,CAAC,QAAQ,CAAC,WAAW,SAAiB;IAO5C;;;;;OAKG;gBACS,GAAG,EAAE,MAAM,YAAqB,EAAE,KAAK,EAAE,CAAC,EAAE;IAKxD;;;OAGG;IACH,UAAU,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAQ9B;;;;;OAKG;IACH,OAAO,CACN,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,EAC3B,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GACtB,CAAC,EAAE;IAyGN;;;;;OAKG;IACH,OAAO,CACN,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,EAC3B,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GACtB,CAAC,GAAG,SAAS;IA8EhB;;;;;;OAMG;IACG,YAAY,CACjB,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,EAC5B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,EAC3B,OAAO,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GACrC,OAAO,CAAC,CAAC,EAAE,CAAC;IAMf;;;;;;OAMG;IACG,YAAY,CACjB,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,EAC5B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,EAC3B,OAAO,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GACrC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAMzB;;;;;;;;OAQG;IACH,YAAY,CACX,MAAM,EAAE,CAAC,EAAE,EACX,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,EACzC,eAAe,EAAE,OAAO,GACtB,CAAC,GAAG,SAAS;IAoBhB;;;;;;;;OAQG;IACH,WAAW,CACV,KAAK,EAAE,CAAC,EAAE,EACV,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,EACzC,eAAe,EAAE,OAAO,GACtB,CAAC,GAAG,SAAS;CAyFhB"}
|
|
@@ -57,4 +57,19 @@ export interface SortNature {
|
|
|
57
57
|
/** If true, uses localeCompare for string chunk comparisons. Defaults to `false`. */
|
|
58
58
|
localeAware?: boolean;
|
|
59
59
|
}
|
|
60
|
+
/** * Options for customizing the search behavior. */
|
|
61
|
+
export interface FindOptions<T = unknown> {
|
|
62
|
+
/** * Enables fuzzy matching when exact match fails. Defaults to `false`. */
|
|
63
|
+
fuzzy?: boolean;
|
|
64
|
+
/** * Optional key for caching the result. Defaults to `finder-cache` */
|
|
65
|
+
cacheKey?: string;
|
|
66
|
+
/** * Forces binary search even for small datasets. Defaults to `false`. */
|
|
67
|
+
forceBinary?: boolean;
|
|
68
|
+
/** * If true, matcher and keys will be normalized to lowercase. Defaults to `true`. */
|
|
69
|
+
caseInsensitive?: boolean;
|
|
70
|
+
/** * If true, uses built in `Array.sort()`. Defaults to `true`. Pass `false` if data is already sorted. */
|
|
71
|
+
needSorting?: boolean;
|
|
72
|
+
/** * Optional data source to use instead of constructor items. */
|
|
73
|
+
data?: T[] | (() => T[]);
|
|
74
|
+
}
|
|
60
75
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/array/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,uCAAuC;AACvC,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEpE;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE;IACvC;;;OAGG;IACH,aAAa,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAE/B;;;OAGG;IACH,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAEhC;;;;OAIG;IACH,cAAc,CAAC,EAAE,EAAE,CAAC;IAEpB;;;;OAIG;IACH,eAAe,CAAC,EAAE,EAAE,CAAC;CACrB;AAED,kCAAkC;AAClC,MAAM,WAAW,WAAW;IAC3B;;;;OAIG;IACH,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC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WAAW,YAAY,CAAC,CAAC,SAAS,aAAa,CAAE,SAAQ,WAAW;IACzE,2DAA2D;IAC3D,WAAW,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;CACnC;AAED,mCAAmC;AACnC,MAAM,MAAM,WAAW,CAAC,CAAC,IACxB,CAAC,SAAS,aAAa,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;AAEzD,0DAA0D;AAC1D,MAAM,WAAW,UAAU;IAC1B,oFAAoF;IACpF,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,qFAAqF;IACrF,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB;AACD,qDAAqD;AACrD,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO;IACvC,4EAA4E;IAC5E,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uFAAuF;IACvF,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,2GAA2G;IAC3G,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kEAAkE;IAClE,IAAI,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;CACzB"}
|
|
@@ -240,7 +240,7 @@ export declare class Color {
|
|
|
240
240
|
*/
|
|
241
241
|
static isHSLA(color: string): color is HSLA;
|
|
242
242
|
/**
|
|
243
|
-
*
|
|
243
|
+
* @static Checks if a color is a valid CSS color name.
|
|
244
244
|
* - This method checks against a predefined list of CSS color names.
|
|
245
245
|
* - It does not validate format types like Hex, RGB, or HSL or their alpha channels.
|
|
246
246
|
*
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export { Chronos, Chronos as Chronus } from './date/Chronos';
|
|
|
23
23
|
export { chronos, chronos as chronosjs, chronos as chronosts, chronos as chronus, chronos as chronusjs, chronos as chronusts, } from './date/chronos-fn';
|
|
24
24
|
export { formatUTCOffset as convertMinutesToUTCOffset, extractHourMinute, extractMinutesFromUTC, extractTimeFromUTC, extractTimeFromUTC as extractTimeStringFromUTC, getTotalMinutes as extractTotalMinutesFromTime, formatUTCOffset, getCurrentDateTime, getCurrentDateTime as getCurrentTime, extractMinutesFromUTC as getMinutesFromUTC, extractTimeFromUTC as getTimeStringFromUTC, getTotalMinutes, getTotalMinutes as getTotalMinutesFromTime, extractMinutesFromUTC as getTotalMinutesFromUTC, formatUTCOffset as minutesToUTCOffset, } from './date/utils';
|
|
25
25
|
export { filterArrayOfObjects, flattenArray, getLastArrayElement, isInvalidOrEmptyArray, isInvalidOrEmptyArray as isValidEmptyArray, shuffleArray, } from './array/basics';
|
|
26
|
+
export { Finder } from './array/Finder';
|
|
26
27
|
export { sortAnArray } from './array/sort';
|
|
27
28
|
export { createOptionsArray, getDuplicates as extractDuplicates, getDuplicates as extractDuplicatesFromArray, findMissingElements as extractMissingElements, findMissingElements, getDuplicates, getDuplicates as getDuplicatesFromArray, findMissingElements as getMissingElements, moveArrayElement, removeDuplicatesFromArray as removeDuplicates, removeDuplicatesFromArray, rotateArray, splitArray, } from './array/transform';
|
|
28
29
|
export { naturalSort as compareNaturally, naturalSort as compareSorter, naturalSort, naturalSort as naturalSortForString, } from './array/utils';
|
package/dist/dts/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,cAAc,GACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EACN,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,iBAAiB,EACjB,aAAa,E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ACX,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACN,kBAAkB,IAAI,iBAAiB,EACvC,OAAO,EACP,aAAa,EACb,YAAY,IAAI,iBAAiB,EACjC,QAAQ,EACR,MAAM,EACN,aAAa,EACb,aAAa,IAAI,kBAAkB,EACnC,OAAO,EACP,UAAU,EACV,MAAM,EACN,MAAM,IAAI,YAAY,EACtB,KAAK,EACL,kBAAkB,IAAI,QAAQ,EAC9B,kBAAkB,EAClB,gBAAgB,EAChB,QAAQ,EACR,aAAa,IAAI,aAAa,EAC9B,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,QAAQ,IAAI,mBAAmB,EAC/B,kBAAkB,EAClB,KAAK,EACL,YAAY,EACZ,MAAM,IAAI,WAAW,EACrB,KAAK,IAAI,UAAU,EACnB,gBAAgB,IAAI,aAAa,EACjC,KAAK,IAAI,UAAU,GACnB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACN,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,aAAa,EACb,aAAa,IAAI,iBAAiB,EAClC,WAAW,EACX,MAAM,EACN,aAAa,IAAI,SAAS,EAC1B,aAAa,IAAI,iBAAiB,EAClC,eAAe,EACf,aAAa,EACb,KAAK,EACL,MAAM,EACN,OAAO,IAAI,YAAY,EACvB,KAAK,IAAI,UAAU,GACnB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `Finder` class performs optimized searching on arrays.
|
|
3
|
+
* It supports binary search, fuzzy search, and smart caching with TTL.
|
|
4
|
+
*/
|
|
5
|
+
export class Finder {
|
|
6
|
+
static DEFAULT_TTL = 1000 * 60 * 5;
|
|
7
|
+
#cache = new Map();
|
|
8
|
+
#sortedCache = new Map();
|
|
9
|
+
#ttl;
|
|
10
|
+
#items;
|
|
11
|
+
/**
|
|
12
|
+
* * Creates a new `Finder` instance.
|
|
13
|
+
*
|
|
14
|
+
* @param ttl Time-to-live (in milliseconds) for cached search results. Defaults to {@link Finder.DEFAULT_TTL 5 Minutes}.
|
|
15
|
+
* @param items The initial array of items to be used for searching.
|
|
16
|
+
*/
|
|
17
|
+
constructor(ttl = Finder.DEFAULT_TTL, items) {
|
|
18
|
+
this.#ttl = ttl;
|
|
19
|
+
this.#items = items;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @instance Clears cache globally or for a specific key.
|
|
23
|
+
* @param key Optional key to clear only a specific cache entry.
|
|
24
|
+
*/
|
|
25
|
+
clearCache(key) {
|
|
26
|
+
if (key) {
|
|
27
|
+
this.#cache.delete(key);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.#cache.clear();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @instance Finds all items that match the provided matcher using optional caching or fuzzy logic.
|
|
35
|
+
* @param matcher The value to match against.
|
|
36
|
+
* @param keySelector Property key or selector function.
|
|
37
|
+
* @param options Optional settings for search behavior and source list.
|
|
38
|
+
*/
|
|
39
|
+
findAll(matcher, keySelector, options) {
|
|
40
|
+
const { fuzzy = false, needSorting = true, cacheKey = 'finder-cache', forceBinary = false, caseInsensitive = true, data, } = options ?? {};
|
|
41
|
+
const source = typeof data === 'function' ? data() : (data ?? this.#items);
|
|
42
|
+
if (!source?.length)
|
|
43
|
+
return [];
|
|
44
|
+
const rawGetKey = typeof keySelector === 'function' ? keySelector : ((item) => item[keySelector]);
|
|
45
|
+
const getKey = Finder.#createMemoizedKeyGetter(rawGetKey);
|
|
46
|
+
const normalizedMatcher = caseInsensitive && typeof matcher === 'string' ?
|
|
47
|
+
matcher.toLowerCase()
|
|
48
|
+
: matcher;
|
|
49
|
+
if (cacheKey) {
|
|
50
|
+
const entry = this.#cache.get(cacheKey);
|
|
51
|
+
if (entry && Date.now() - entry.timestamp < this.#ttl) {
|
|
52
|
+
return entry.result;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.#cache.delete(cacheKey);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
let results = [];
|
|
59
|
+
if (source.length < 100 && !forceBinary) {
|
|
60
|
+
results = source.filter((item) => {
|
|
61
|
+
const key = getKey(item);
|
|
62
|
+
const value = caseInsensitive && typeof key === 'string' ?
|
|
63
|
+
key.toLowerCase()
|
|
64
|
+
: key;
|
|
65
|
+
return value === normalizedMatcher;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const sorted = needSorting ?
|
|
70
|
+
this.#sortAndCache(source, getKey, cacheKey)
|
|
71
|
+
: source;
|
|
72
|
+
const firstMatch = this.binarySearch(sorted, normalizedMatcher, getKey, caseInsensitive);
|
|
73
|
+
if (firstMatch) {
|
|
74
|
+
const baseKey = getKey(firstMatch);
|
|
75
|
+
const base = caseInsensitive && typeof baseKey === 'string' ?
|
|
76
|
+
baseKey.toLowerCase()
|
|
77
|
+
: baseKey;
|
|
78
|
+
results = sorted.filter((item) => {
|
|
79
|
+
const key = getKey(item);
|
|
80
|
+
const value = caseInsensitive && typeof key === 'string' ?
|
|
81
|
+
key.toLowerCase()
|
|
82
|
+
: key;
|
|
83
|
+
return value === base;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (!results.length && fuzzy && typeof normalizedMatcher === 'string') {
|
|
88
|
+
results = source.filter((item) => {
|
|
89
|
+
const rawKey = getKey(item);
|
|
90
|
+
const key = caseInsensitive && typeof rawKey === 'string' ?
|
|
91
|
+
rawKey.toLowerCase()
|
|
92
|
+
: String(rawKey);
|
|
93
|
+
return this.#match(key, normalizedMatcher);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (cacheKey) {
|
|
97
|
+
this.#cache.set(cacheKey, {
|
|
98
|
+
result: results,
|
|
99
|
+
timestamp: Date.now(),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return results;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* @instance Finds first matching item that matches the provided matcher using optional caching or fuzzy logic.
|
|
106
|
+
* @param matcher The value to match.
|
|
107
|
+
* @param keySelector Property key or selector function.
|
|
108
|
+
* @param options Optional behavior flags and item source.
|
|
109
|
+
*/
|
|
110
|
+
findOne(matcher, keySelector, options) {
|
|
111
|
+
const { fuzzy = false, needSorting = true, cacheKey = 'finder-cache', forceBinary = false, caseInsensitive = true, data, } = options ?? {};
|
|
112
|
+
const source = typeof data === 'function' ? data() : (data ?? this.#items);
|
|
113
|
+
if (!source?.length)
|
|
114
|
+
return undefined;
|
|
115
|
+
const rawGetKey = typeof keySelector === 'function' ? keySelector : ((item) => item[keySelector]);
|
|
116
|
+
const getKey = Finder.#createMemoizedKeyGetter(rawGetKey);
|
|
117
|
+
const normalizedMatcher = caseInsensitive && typeof matcher === 'string' ?
|
|
118
|
+
matcher.toLowerCase()
|
|
119
|
+
: matcher;
|
|
120
|
+
if (cacheKey) {
|
|
121
|
+
const entry = this.#cache.get(cacheKey);
|
|
122
|
+
if (entry && Date.now() - entry.timestamp < this.#ttl) {
|
|
123
|
+
return entry.result[0];
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
this.#cache.delete(cacheKey);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
let result;
|
|
130
|
+
if (source.length < 100 && !forceBinary) {
|
|
131
|
+
result = source.find((item) => {
|
|
132
|
+
const key = getKey(item);
|
|
133
|
+
const value = caseInsensitive && typeof key === 'string' ?
|
|
134
|
+
key.toLowerCase()
|
|
135
|
+
: key;
|
|
136
|
+
return value === normalizedMatcher;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
result = this.binarySearch(needSorting ?
|
|
141
|
+
this.#sortAndCache(source, getKey, cacheKey)
|
|
142
|
+
: source, normalizedMatcher, getKey, caseInsensitive);
|
|
143
|
+
}
|
|
144
|
+
if (!result && fuzzy && typeof normalizedMatcher === 'string') {
|
|
145
|
+
return this.fuzzySearch(source, normalizedMatcher, getKey, caseInsensitive);
|
|
146
|
+
}
|
|
147
|
+
if (cacheKey && result) {
|
|
148
|
+
this.#cache.set(cacheKey, {
|
|
149
|
+
result: [result],
|
|
150
|
+
timestamp: Date.now(),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @instance Asynchronous variant of `findAll` that accepts a promise-based data supplier.
|
|
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 search behavior and cache.
|
|
161
|
+
*/
|
|
162
|
+
async findAllAsync(supplier, matcher, keySelector, options) {
|
|
163
|
+
const items = await supplier();
|
|
164
|
+
return this.findAll(matcher, keySelector, { ...options, data: items });
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* @instance Asynchronous variant of `findOne`.
|
|
168
|
+
* @param supplier Async function resolving the items list.
|
|
169
|
+
* @param matcher The value to match.
|
|
170
|
+
* @param keySelector Property key or selector function.
|
|
171
|
+
* @param options Optional settings for behavior and cache.
|
|
172
|
+
*/
|
|
173
|
+
async findOneAsync(supplier, matcher, keySelector, options) {
|
|
174
|
+
const items = await supplier();
|
|
175
|
+
return this.findOne(matcher, keySelector, { ...options, data: items });
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* @instance Performs a binary search on a sorted array using a custom key selector.
|
|
179
|
+
*
|
|
180
|
+
* @param sorted - The sorted array of items to search.
|
|
181
|
+
* @param matcher - The value to search for.
|
|
182
|
+
* @param keySelector - A function that extracts the comparable key from each item.
|
|
183
|
+
* @param caseInsensitive - Whether to compare string keys ignoring case.
|
|
184
|
+
* @returns The first matching item if found; otherwise, undefined.
|
|
185
|
+
*/
|
|
186
|
+
binarySearch(sorted, matcher, keySelector, caseInsensitive) {
|
|
187
|
+
let min = 0, max = sorted.length - 1;
|
|
188
|
+
while (min <= max) {
|
|
189
|
+
const mid = Math.floor((min + max) / 2);
|
|
190
|
+
const midKey = keySelector(sorted[mid]);
|
|
191
|
+
const key = caseInsensitive && typeof midKey === 'string' ?
|
|
192
|
+
midKey.toLowerCase()
|
|
193
|
+
: midKey;
|
|
194
|
+
if (key === matcher)
|
|
195
|
+
return sorted[mid];
|
|
196
|
+
if (key < matcher)
|
|
197
|
+
min = mid + 1;
|
|
198
|
+
else
|
|
199
|
+
max = mid - 1;
|
|
200
|
+
}
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* @instance Performs a fuzzy search on an array by matching characters in sequence.
|
|
205
|
+
*
|
|
206
|
+
* @param array - The array of items to search.
|
|
207
|
+
* @param matcher - The fuzzy search string to match against.
|
|
208
|
+
* @param keySelector - A function that extracts the key to search from each item.
|
|
209
|
+
* @param caseInsensitive - Whether to compare ignoring case for string values.
|
|
210
|
+
* @returns The first fuzzy-matching item if found; otherwise, undefined.
|
|
211
|
+
*/
|
|
212
|
+
fuzzySearch(array, matcher, keySelector, caseInsensitive) {
|
|
213
|
+
for (const item of array) {
|
|
214
|
+
const rawKey = keySelector(item);
|
|
215
|
+
const key = caseInsensitive && typeof rawKey === 'string' ?
|
|
216
|
+
rawKey.toLowerCase()
|
|
217
|
+
: String(rawKey);
|
|
218
|
+
if (this.#match(key, matcher))
|
|
219
|
+
return item;
|
|
220
|
+
}
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* @private Checks if the characters in the target string appear in order within the source string.
|
|
225
|
+
* @param source Source string to search within.
|
|
226
|
+
* @param target Target string to match against the source string.
|
|
227
|
+
* @returns True if the target string is a fuzzy match within the source string; otherwise, false.
|
|
228
|
+
*/
|
|
229
|
+
#match(source, target) {
|
|
230
|
+
let i = 0;
|
|
231
|
+
for (const char of target) {
|
|
232
|
+
i = source.indexOf(char, i);
|
|
233
|
+
if (i === -1)
|
|
234
|
+
return false;
|
|
235
|
+
i++;
|
|
236
|
+
}
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* @private Sorts an array and caches the result for a specified time-to-live (TTL).
|
|
241
|
+
* @param data Data to sort and cache.
|
|
242
|
+
* @param getKey Key extraction function.
|
|
243
|
+
* @param cacheKey Optional cache key for storing the result.
|
|
244
|
+
* @returns
|
|
245
|
+
*/
|
|
246
|
+
#sortAndCache(data, getKey, cacheKey) {
|
|
247
|
+
if (cacheKey) {
|
|
248
|
+
const entry = this.#sortedCache.get(cacheKey);
|
|
249
|
+
if (entry && Date.now() - entry.timestamp < this.#ttl) {
|
|
250
|
+
return entry.result;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
this.#sortedCache.delete(cacheKey);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const sorted = [...data].sort((a, b) => {
|
|
257
|
+
const keyA = getKey(a);
|
|
258
|
+
const keyB = getKey(b);
|
|
259
|
+
return (keyA < keyB ? -1
|
|
260
|
+
: keyA > keyB ? 1
|
|
261
|
+
: 0);
|
|
262
|
+
});
|
|
263
|
+
if (cacheKey) {
|
|
264
|
+
this.#sortedCache.set(cacheKey, {
|
|
265
|
+
result: sorted,
|
|
266
|
+
timestamp: Date.now(),
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
return sorted;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* @static @private Creates a memoized version of a key extractor.
|
|
273
|
+
* @param getKey Original key extraction function
|
|
274
|
+
*/
|
|
275
|
+
static #createMemoizedKeyGetter(getKey) {
|
|
276
|
+
const cache = new Map();
|
|
277
|
+
return (item) => {
|
|
278
|
+
if (cache.has(item))
|
|
279
|
+
return cache.get(item);
|
|
280
|
+
const key = getKey(item);
|
|
281
|
+
cache.set(item, key);
|
|
282
|
+
return key;
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
}
|
package/dist/esm/colors/Color.js
CHANGED
|
@@ -380,7 +380,7 @@ export class Color {
|
|
|
380
380
|
return _isHSLA(color);
|
|
381
381
|
}
|
|
382
382
|
/**
|
|
383
|
-
*
|
|
383
|
+
* @static Checks if a color is a valid CSS color name.
|
|
384
384
|
* - This method checks against a predefined list of CSS color names.
|
|
385
385
|
* - It does not validate format types like Hex, RGB, or HSL or their alpha channels.
|
|
386
386
|
*
|
package/dist/esm/index.js
CHANGED
|
@@ -28,6 +28,7 @@ export { chronos, chronos as chronosjs, chronos as chronosts, chronos as chronus
|
|
|
28
28
|
export { formatUTCOffset as convertMinutesToUTCOffset, extractHourMinute, extractMinutesFromUTC, extractTimeFromUTC, extractTimeFromUTC as extractTimeStringFromUTC, getTotalMinutes as extractTotalMinutesFromTime, formatUTCOffset, getCurrentDateTime, getCurrentDateTime as getCurrentTime, extractMinutesFromUTC as getMinutesFromUTC, extractTimeFromUTC as getTimeStringFromUTC, getTotalMinutes, getTotalMinutes as getTotalMinutesFromTime, extractMinutesFromUTC as getTotalMinutesFromUTC, formatUTCOffset as minutesToUTCOffset, } from './date/utils';
|
|
29
29
|
// ! Array Utilities
|
|
30
30
|
export { filterArrayOfObjects, flattenArray, getLastArrayElement, isInvalidOrEmptyArray, isInvalidOrEmptyArray as isValidEmptyArray, shuffleArray, } from './array/basics';
|
|
31
|
+
export { Finder } from './array/Finder';
|
|
31
32
|
export { sortAnArray } from './array/sort';
|
|
32
33
|
export { createOptionsArray, getDuplicates as extractDuplicates, getDuplicates as extractDuplicatesFromArray, findMissingElements as extractMissingElements, findMissingElements, getDuplicates, getDuplicates as getDuplicatesFromArray, findMissingElements as getMissingElements, moveArrayElement, removeDuplicatesFromArray as removeDuplicates, removeDuplicatesFromArray, rotateArray, splitArray, } from './array/transform';
|
|
33
34
|
export { naturalSort as compareNaturally, naturalSort as compareSorter, naturalSort, naturalSort as naturalSortForString, } from './array/utils';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nhb-toolbox",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.88",
|
|
4
4
|
"description": "A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|