moderndash 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -7,12 +7,12 @@
7
7
  *
8
8
  * chunk(['a', 'b', 'c', 'd'], 3)
9
9
  * // => [['a', 'b', 'c'], ['d']]
10
- * @param size The length of each chunk
10
+ * @param chunkSize The length of each chunk
11
11
  * @param array The array to chunk.
12
12
  * @template TElem The type of the array elements.
13
13
  * @returns Returns the new array of chunks.
14
14
  */
15
- declare function chunk<TElem>(array: TElem[], size: number): TElem[][];
15
+ declare function chunk<TElem>(array: readonly TElem[], chunkSize: number): TElem[][];
16
16
 
17
17
  /**
18
18
  * Creates an object with counts of occurrences of items in the array.
@@ -24,18 +24,18 @@ declare function chunk<TElem>(array: TElem[], size: number): TElem[][];
24
24
  * { 'user': 'fred', 'active': true, age: 40 }
25
25
  * ]
26
26
  *
27
- * count(users, value => value.active);
28
- * // => { 'true': 2, 'false': 1 }
27
+ * count(users, value => value.active ? 'active' : 'inactive');
28
+ * // => { 'active': 2, 'inactive': 1 }
29
29
  *
30
30
  * count(users, value => value.age);
31
- * // => { '36': 2, '40': 1 }
31
+ * // => { 36: 2, 40: 1 }
32
32
  *
33
33
  * @param criteria The criteria to count by.
34
34
  * @param array The array or record to iterate over.
35
35
  * @template TElem The type of the array elements.
36
36
  * @returns Returns the composed aggregate object.
37
37
  */
38
- declare function count<TElem, TKey extends PropertyKey>(array: TElem[], criteria: (value: TElem) => TKey): Record<TKey, number>;
38
+ declare function count<TElem, TKey extends PropertyKey>(array: readonly TElem[], criteria: (value: TElem) => TKey): Record<TKey, number>;
39
39
 
40
40
  /**
41
41
  * This type builds an array with a minimum length.
@@ -77,8 +77,8 @@ type BuildArrayMinLength<TElem, TMinLength extends number, Current extends TElem
77
77
  * @template TElem The type of the array elements.
78
78
  * @returns Returns the new array of filtered values.
79
79
  */
80
- declare function difference<TElem>(...arrays: ArrayMinLength<TElem[], 2>): TElem[];
81
- declare function difference<TElem>(arrayOrCompFn: (a: TElem, b: TElem) => boolean, ...arrays: ArrayMinLength<TElem[], 2>): TElem[];
80
+ declare function difference<TElem>(...arrays: ArrayMinLength<readonly TElem[], 2>): TElem[];
81
+ declare function difference<TElem>(arrayOrCompFn: (a: TElem, b: TElem) => boolean, ...arrays: ArrayMinLength<readonly TElem[], 2>): TElem[];
82
82
 
83
83
  /**
84
84
  * Creates a slice of `array` excluding elements dropped from the end.
@@ -91,14 +91,14 @@ declare function difference<TElem>(arrayOrCompFn: (a: TElem, b: TElem) => boolea
91
91
  * { 'user': 'pebbles', 'active': true }
92
92
  * ]
93
93
  *
94
- * dropRightWhile(users, ({ active }) => active)
94
+ * dropRightWhile(users, user => user.active)
95
95
  * // => objects for ['barney']
96
96
  * @param predicate The function invoked per iteration.
97
97
  * @param array The array to query.
98
98
  * @template TElem The type of the array elements.
99
99
  * @returns Returns the slice of `array`.
100
100
  */
101
- declare function dropRightWhile<TElem>(array: TElem[], predicate: (value: TElem) => boolean): TElem[];
101
+ declare function dropRightWhile<TElem>(array: readonly TElem[], predicate: (value: TElem) => boolean): TElem[];
102
102
 
103
103
  /**
104
104
  * Creates a slice of `array` excluding elements dropped from the beginning.
@@ -111,14 +111,14 @@ declare function dropRightWhile<TElem>(array: TElem[], predicate: (value: TElem)
111
111
  * { 'user': 'pebbles', 'active': false }
112
112
  * ]
113
113
  *
114
- * dropWhile(users, ({ active }) => active)
114
+ * dropWhile(users, user => user.active)
115
115
  * // => objects for ['pebbles']
116
116
  * @param predicate The function invoked per iteration.
117
117
  * @param array The array to query.
118
118
  * @template TElem The type of the array elements.
119
119
  * @returns Returns the slice of `array`.
120
120
  */
121
- declare function dropWhile<TElem>(array: TElem[], predicate: (value: TElem) => boolean): TElem[];
121
+ declare function dropWhile<TElem>(array: readonly TElem[], predicate: (value: TElem) => boolean): TElem[];
122
122
 
123
123
  /**
124
124
  * Creates an object with grouped items in the array.
@@ -127,15 +127,15 @@ declare function dropWhile<TElem>(array: TElem[], predicate: (value: TElem) => b
127
127
  * group([6.1, 4.2, 6.3], Math.floor)
128
128
  * // => { 4: [4.2], 6: [6.1, 6.3] }
129
129
  *
130
- * group([6.1, 4.2, 6.3], value => value > 5)
131
- * // => { 'false': [4.2], 'true': [6.1, 6.3] }
130
+ * group([6.1, 4.2, 6.3], value => value > 5 ? '>5' : '<=5')
131
+ * // => { '<=5': [4.2], '>5': [6.1, 6.3] }
132
132
  *
133
133
  * @param collection The array or object to iterate over.
134
134
  * @param getGroupKey A function that returns the group id for each item.
135
135
  * @template TElem The type of the array elements.
136
136
  * @returns An object with grouped items.
137
137
  */
138
- declare function group<TElem, TKey extends PropertyKey>(array: TElem[], getGroupKey: (value: TElem) => TKey): Record<TKey, TElem[]>;
138
+ declare function group<TElem, TKey extends PropertyKey>(array: readonly TElem[], getGroupKey: (elem: TElem) => TKey): Record<TKey, TElem[]>;
139
139
 
140
140
  /**
141
141
  * Create an array with unique values from all input arrays, with order based on the first array.
@@ -158,10 +158,11 @@ declare function group<TElem, TKey extends PropertyKey>(array: TElem[], getGroup
158
158
  * intersection((a, b) => a.id === b.id, arr1, arr2)
159
159
  * // => [{ id: 3, name: 'John' }]
160
160
  * @param arrays The arrays to inspect.
161
+ * @template TElem The type of the array elements.
161
162
  * @returns Returns the new array of intersecting values.
162
163
  */
163
- declare function intersection<TArr>(...arrays: ArrayMinLength<TArr[], 2>): TArr[];
164
- declare function intersection<TArr>(arrayOrCompFn: (a: TArr, b: TArr) => boolean, ...arrays: ArrayMinLength<TArr[], 2>): TArr[];
164
+ declare function intersection<TElem>(...arrays: ArrayMinLength<readonly TElem[], 2>): TElem[];
165
+ declare function intersection<TElem>(arrayOrCompFn: (a: TElem, b: TElem) => boolean, ...arrays: ArrayMinLength<readonly TElem[], 2>): TElem[];
165
166
 
166
167
  /**
167
168
  * Generates an iterable sequence of numbers starting from `start`, up to and including `end`,
@@ -192,9 +193,10 @@ declare function range(start: number, end: number, step?: number): Generator<num
192
193
  * shuffle([1, 2, 3, 4])
193
194
  * // => [4, 1, 3, 2]
194
195
  * @param array The array or object to shuffle.
196
+ * @template TElem The type of the array elements.
195
197
  * @returns Returns a new shuffled array.
196
198
  */
197
- declare function shuffle<TElem>(array: TElem[]): TElem[];
199
+ declare function shuffle<TElem>(array: readonly TElem[]): TElem[];
198
200
 
199
201
  /**
200
202
  * Creates a new sorted array in ascending or descending order based on one or multiple sorting criteria.
@@ -215,12 +217,13 @@ declare function shuffle<TElem>(array: TElem[]): TElem[];
215
217
  * @param orders The sorting criteria, one or multiple objects with properties order (either 'asc' or 'desc') and by (iteratee function to sort based on a specific property).
216
218
  * @param orders.order - The order to sort in, either 'asc' or 'desc'.
217
219
  * @param orders.by - The iteratee function to sort based on a specific property.
220
+ * @template TElem The type of the array elements.
218
221
  * @returns Returns a new sorted array.
219
222
  */
220
- declare function sort<TInput>(array: TInput[], ...orders: {
223
+ declare function sort<TElem>(array: readonly TElem[], ...orders: {
221
224
  order?: 'asc' | 'desc';
222
- by?: (item: TInput) => number | bigint | Date | string;
223
- }[]): TInput[];
225
+ by?: (item: TElem) => number | bigint | Date | string;
226
+ }[]): TElem[];
224
227
 
225
228
  /**
226
229
  * Creates a slice of `array` with elements taken from the end.
@@ -233,13 +236,14 @@ declare function sort<TInput>(array: TInput[], ...orders: {
233
236
  * { 'user': 'pebbles', 'active': true }
234
237
  * ]
235
238
  *
236
- * takeRightWhile(users, ({ active }) => active)
239
+ * takeRightWhile(users, user => user.active)
237
240
  * // => objects for ['fred', 'pebbles']
238
241
  * @param predicate The function invoked per iteration.
239
242
  * @param array The array to query.
243
+ * @template TElem The type of the array elements.
240
244
  * @returns Returns the slice of `array`.
241
245
  */
242
- declare function takeRightWhile<TArr>(array: TArr[], predicate: (elem: TArr) => boolean): TArr[];
246
+ declare function takeRightWhile<TElem>(array: readonly TElem[], predicate: (elem: TElem) => boolean): TElem[];
243
247
 
244
248
  /**
245
249
  * Creates a slice of `array` with elements taken from the beginning.
@@ -252,13 +256,14 @@ declare function takeRightWhile<TArr>(array: TArr[], predicate: (elem: TArr) =>
252
256
  * { 'user': 'pebbles', 'active': false }
253
257
  * ]
254
258
  *
255
- * takeWhile(users, ({ active }) => active)
259
+ * takeWhile(users, user => user.active)
256
260
  * // => objects for ['barney', 'fred']
257
261
  * @param predicate The function invoked per iteration.
258
262
  * @param array The array to query.
263
+ * @template TElem The type of the array elements.
259
264
  * @returns Returns the slice of `array`.
260
265
  */
261
- declare function takeWhile<TArr>(array: TArr[], predicate: (elem: TArr) => boolean): TArr[];
266
+ declare function takeWhile<TElem>(array: readonly TElem[], predicate: (elem: TElem) => boolean): TElem[];
262
267
 
263
268
  /**
264
269
  * Creates a duplicate-free version of an array, in which only the first occurrence of each element is kept.
@@ -273,7 +278,7 @@ declare function takeWhile<TArr>(array: TArr[], predicate: (elem: TArr) => boole
273
278
  * // compare by object values
274
279
  * const users = [
275
280
  * { id: 1, name: 'john' },
276
- * { id: 2, name: 'john' }
281
+ * { id: 2, name: 'john' },
277
282
  * { id: 2, name: 'john' },
278
283
  * ]
279
284
  *
@@ -286,9 +291,10 @@ declare function takeWhile<TArr>(array: TArr[], predicate: (elem: TArr) => boole
286
291
  *
287
292
  * @param array The array to inspect.
288
293
  * @param iteratee The iteratee invoked per element.
294
+ * @template TElem The type of the array elements.
289
295
  * @returns Returns the new duplicate free array.
290
296
  */
291
- declare function unique<TInput>(array: TInput[], compareFn?: (a: TInput, b: TInput) => boolean): TInput[];
297
+ declare function unique<TElem>(array: readonly TElem[], compareFn?: (a: TElem, b: TElem) => boolean): TElem[];
292
298
 
293
299
  type JsonifiableObject = {
294
300
  [Key in string]?: Jsonifiable;
@@ -472,16 +478,18 @@ declare function decMaxCalls(n: number): (target: unknown, key: string, descript
472
478
  type GenericFunction<TFunc extends (...args: any) => any> = (...args: Parameters<TFunc>) => ReturnType<TFunc>;
473
479
 
474
480
  /**
475
- * Creates a function that caches the result of `func`.
476
- *
477
- * The cache key is either determined by the provided `resolver` or by the arguments used in the cached function.
481
+ * Creates a function that memoizes the result of a given function.
478
482
  *
479
- * The `cache` property is exposed on the cached function. It is an instance of `Map` and can be used to clear or inspect the cache.
480
- * The cache property can be replaced by a custom cache as long as it implements the `Map` interface.
483
+ * The cache key is determined by the `resolver` or by the arguments from the function call.
481
484
  *
482
485
  * **Options:**
483
- * - `resolver` A function that determines the cache key for storing the result based on the arguments provided.
484
- * - `ttl` sets the time to live for the cache in milliseconds. After `ttl` milliseconds, the next call to the memoized function will result in a cache miss.
486
+ * - `resolver` A function that determines the cache key based on the arguments provided.
487
+ * - `ttl` the time to live for the cache entries in milliseconds.
488
+ *
489
+ * **Properties:**
490
+ * - `cache` The cache is an instance of `Map` and can be used to clear or inspect the cache.
491
+ * It can be replaced by a custom cache that matches the `Map` interface.
492
+ *
485
493
  *
486
494
  * This function can be used as a decorator with {@link decMemoize}.
487
495
  *
@@ -742,7 +750,7 @@ declare function times<TInput>(func: (index: number) => TInput, n: number): TInp
742
750
  * @param numbers The input array of numbers
743
751
  * @returns The average of the input array, or NaN if the input array is empty
744
752
  */
745
- declare function average(numbers: number[]): number;
753
+ declare function average(numbers: readonly number[]): number;
746
754
 
747
755
  /**
748
756
  * Calculates the median of an array of numbers
@@ -755,7 +763,7 @@ declare function average(numbers: number[]): number;
755
763
  * @param numbers The input array of numbers
756
764
  * @returns The median of the input array
757
765
  */
758
- declare function median(numbers: number[]): number;
766
+ declare function median(numbers: readonly number[]): number;
759
767
 
760
768
  /**
761
769
  * Rounds a number to the given precision.
@@ -781,7 +789,7 @@ declare function round(number: number, precision?: number): number;
781
789
  * @param numbers The input array of numbers
782
790
  * @returns The sum of the input array
783
791
  */
784
- declare function sum(numbers: number[]): number;
792
+ declare function sum(numbers: readonly number[]): number;
785
793
 
786
794
  /**
787
795
  * The type of a plain object.
@@ -797,6 +805,20 @@ declare function sum(numbers: number[]): number;
797
805
  */
798
806
  type PlainObject = Record<PropertyKey, unknown>;
799
807
 
808
+ /**
809
+ * Flattens an object into a single level object.
810
+ *
811
+ * @example
812
+ * const obj = { a: { b: 2, c: [{ d: 3 }, {d: 4 }] } };
813
+ * flatKeys(obj);
814
+ * // => { 'a.b': 2, 'a.c[0].d': 3, 'a.c[1].d': 4 }
815
+ *
816
+ * @param obj The object to flatten.
817
+ * @template TObj The type of the object to flatten.
818
+ * @returns A new object with flattened keys.
819
+ */
820
+ declare function flatKeys<TObj extends PlainObject>(obj: TObj): Record<string, unknown>;
821
+
800
822
  /**
801
823
  * This function combines two or more objects into a single new object. Arrays and other types are overwritten.
802
824
  *
@@ -813,6 +835,8 @@ type PlainObject = Record<PropertyKey, unknown>;
813
835
  * // => { a: "Yes" }
814
836
  * @param target The target object
815
837
  * @param sources The source objects
838
+ * @template TTarget The type of the target object
839
+ * @template TSources The type of the source objects
816
840
  * @returns A new merged object
817
841
  */
818
842
  declare function merge<TTarget extends PlainObject, TSources extends ArrayMinLength<PlainObject, 1>>(target: TTarget, ...sources: TSources): MergeDeepObjects<[TTarget, ...TSources]>;
@@ -840,8 +864,8 @@ type MergeDeepObjects<A extends readonly [...unknown[]]> = A extends [infer L, .
840
864
  *
841
865
  * @param object The object to filter
842
866
  * @param keysToOmit The keys to exclude from the returned object
867
+ * @template TObj The type of the object
843
868
  * @returns - An object without the specified keys
844
- *
845
869
  */
846
870
  declare function omit<TObj extends PlainObject, Key extends keyof TObj>(object: TObj, keysToOmit: Key[]): Omit<TObj, Key>;
847
871
 
@@ -855,9 +879,10 @@ declare function omit<TObj extends PlainObject, Key extends keyof TObj>(object:
855
879
  * // => { 'a': 1, 'c': 3 }
856
880
  * @param object The source object.
857
881
  * @param keysToPick The property paths to pick.
882
+ * @template TObj The type of the object.
858
883
  * @returns Returns the new object.
859
884
  */
860
- declare function pick<TInput extends PlainObject, Key extends keyof TInput>(object: TInput, keysToPick: Key[]): Pick<TInput, Key>;
885
+ declare function pick<TObj extends PlainObject, Key extends keyof TObj>(object: TObj, keysToPick: Key[]): Pick<TObj, Key>;
861
886
 
862
887
  /**
863
888
  * Sets the value at path of object. If a portion of path doesn’t exist, it’s created.
@@ -867,12 +892,25 @@ declare function pick<TInput extends PlainObject, Key extends keyof TInput>(obje
867
892
  * set(obj, 'a.c', 1);
868
893
  * // => { a: { b: 2, c: 1 } }
869
894
  *
895
+ * // `[number]` can be used to access array elements
896
+ * set(obj, 'a.c[0]', 'hello');
897
+ * // => { a: { b: 2, c: ['hello'] } }
898
+ *
899
+ * // numbers with dots are treated as keys
900
+ * set(obj, 'a.c.0.d', 'world');
901
+ * // => { a: { b: 2, c: { 0: { d: 'world' } } }
902
+ *
903
+ * // supports numbers in keys
904
+ * set(obj, 'a.e0.a', 1);
905
+ * // => { a: { e0: { a: 1 } } }
906
+ *
870
907
  * @param obj The object to modify.
871
908
  * @param path The path of the property to set.
872
909
  * @param value The value to set.
910
+ * @template TObj The type of the object.
873
911
  * @returns The modified object.
874
912
  */
875
- declare function set<TObj extends PlainObject>(obj: TObj, path: string, value: unknown): TObj;
913
+ declare function set(obj: PlainObject, path: string, value: unknown): PlainObject;
876
914
 
877
915
  /**
878
916
  * A class for managing a queue of async functions that runs a set number concurrently.
@@ -1277,4 +1315,4 @@ declare function isPlainObject(value: unknown): value is PlainObject;
1277
1315
  */
1278
1316
  declare function isUrl(str: string): boolean;
1279
1317
 
1280
- export { ArrayMinLength, GenericFunction, Jsonifiable, PlainObject, Queue, average, camelCase, capitalize, chunk, count, debounce, deburr, decDebounce, decMaxCalls, decMemoize, decMinCalls, decThrottle, difference, dropRightWhile, dropWhile, escapeHtml, escapeRegExp, group, hash, intersection, isEmpty, isEqual, isPlainObject, isUrl, kebabCase, maxCalls, median, memoize, merge, minCalls, omit, pascalCase, pick, races, randomElem, randomFloat, randomInt, randomString, range, retry, round, set, shuffle, sleep, snakeCase, sort, splitWords, sum, takeRightWhile, takeWhile, throttle, timeout, times, titleCase, toDecorator, tryCatch, unescapeHtml, unique };
1318
+ export { ArrayMinLength, GenericFunction, Jsonifiable, PlainObject, Queue, average, camelCase, capitalize, chunk, count, debounce, deburr, decDebounce, decMaxCalls, decMemoize, decMinCalls, decThrottle, difference, dropRightWhile, dropWhile, escapeHtml, escapeRegExp, flatKeys, group, hash, intersection, isEmpty, isEqual, isPlainObject, isUrl, kebabCase, maxCalls, median, memoize, merge, minCalls, omit, pascalCase, pick, races, randomElem, randomFloat, randomInt, randomString, range, retry, round, set, shuffle, sleep, snakeCase, sort, splitWords, sum, takeRightWhile, takeWhile, throttle, timeout, times, titleCase, toDecorator, tryCatch, unescapeHtml, unique };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/array/chunk.ts
2
- function chunk(array, size) {
3
- const intSize = Math.trunc(size);
2
+ function chunk(array, chunkSize) {
3
+ const intSize = Math.trunc(chunkSize);
4
4
  if (array.length === 0 || intSize < 1) {
5
5
  return [];
6
6
  }
@@ -116,12 +116,10 @@ function intersection(arrayOrCompFn, ...arrays) {
116
116
 
117
117
  // src/array/range.ts
118
118
  function* range(start, end, step = 1) {
119
- if (start > end) {
119
+ if (start > end)
120
120
  throw new Error("The start of the range must be less than or equal to the end.");
121
- }
122
- if (step <= 0) {
121
+ if (step <= 0)
123
122
  throw new Error("The step must be greater than 0.");
124
- }
125
123
  for (let i = start; i <= end; i += step) {
126
124
  yield i;
127
125
  }
@@ -404,6 +402,29 @@ function isPlainObject(value) {
404
402
  return value?.constructor === Object;
405
403
  }
406
404
 
405
+ // src/object/flatKeys.ts
406
+ function flatKeys(obj) {
407
+ const result = {};
408
+ function addToResult(prefix, value) {
409
+ if (isPlainObject(value)) {
410
+ const flatObj = flatKeys(value);
411
+ for (const [flatKey, flatValue] of Object.entries(flatObj)) {
412
+ result[`${prefix}.${flatKey}`] = flatValue;
413
+ }
414
+ } else if (Array.isArray(value)) {
415
+ for (const [index, element] of value.entries()) {
416
+ addToResult(`${prefix}[${index}]`, element);
417
+ }
418
+ } else {
419
+ result[prefix] = value;
420
+ }
421
+ }
422
+ for (const [key, value] of Object.entries(obj)) {
423
+ addToResult(key, value);
424
+ }
425
+ return result;
426
+ }
427
+
407
428
  // src/object/merge.ts
408
429
  function merge(target, ...sources) {
409
430
  const targetCopy = { ...target };
@@ -432,18 +453,28 @@ function omit(object, keysToOmit) {
432
453
  }
433
454
 
434
455
  // src/object/set.ts
456
+ var validPathRegex = /^(?:[^.[\]]+(?:\[\d+])*(?:\.|\[\d+]))+(?:[^.[\]]+(?:\[\d+])*)+$/;
457
+ var pathSplitRegex = /\.|(?=\[)/g;
458
+ var matchBracketsRegex = /[[\]]/g;
435
459
  function set(obj, path, value) {
436
- const pathParts = path.split(/[.[\]]/g).filter((x) => Boolean(x.trim()));
460
+ if (!validPathRegex.test(path))
461
+ throw new Error("Invalid path, look at the examples for the correct format.");
462
+ const pathParts = path.split(pathSplitRegex);
437
463
  let currentObj = obj;
438
464
  for (let index = 0; index < pathParts.length; index++) {
439
- const key = pathParts[index];
465
+ const key = pathParts[index].replace(matchBracketsRegex, "");
440
466
  if (index === pathParts.length - 1) {
441
467
  currentObj[key] = value;
442
468
  break;
443
469
  }
444
- const nextIsNumber = !Number.isNaN(Number.parseInt(pathParts[index + 1]));
445
- if (currentObj[key] === void 0)
446
- currentObj[key] = nextIsNumber ? [] : {};
470
+ const nextElemIn = pathParts[index + 1].startsWith("[") ? "array" : "object";
471
+ if (currentObj[key] === void 0) {
472
+ currentObj[key] = nextElemIn === "array" ? [] : {};
473
+ } else if (nextElemIn === "array" && !Array.isArray(currentObj[key])) {
474
+ currentObj[key] = [];
475
+ } else if (nextElemIn === "object" && !isPlainObject(currentObj[key])) {
476
+ currentObj[key] = {};
477
+ }
447
478
  currentObj = currentObj[key];
448
479
  }
449
480
  return obj;
@@ -600,17 +631,18 @@ async function tryCatch(promise) {
600
631
  }
601
632
 
602
633
  // src/string/splitWords.ts
634
+ var splitWordsRegex = new RegExp(
635
+ "[^\\dA-Za-z]|(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])"
636
+ // lookahead for an uppercase letter followed by a lowercase letter
637
+ );
603
638
  function splitWords(str) {
604
- const regex = new RegExp(
605
- "[^\\dA-Za-z]|(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])"
606
- // lookahead for an uppercase letter followed by a lowercase letter
607
- );
608
- return str.split(regex).filter(Boolean);
639
+ return str.split(splitWordsRegex).filter(Boolean);
609
640
  }
610
641
 
611
642
  // src/string/deburr.ts
643
+ var accentControlRegex = /[\u0300-\u036F]/g;
612
644
  function deburr(str) {
613
- return str.normalize("NFD").replace(/[\u0300-\u036F]/g, "");
645
+ return str.normalize("NFD").replace(accentControlRegex, "");
614
646
  }
615
647
 
616
648
  // src/string/camelCase.ts
@@ -632,20 +664,22 @@ function capitalize(str) {
632
664
  }
633
665
 
634
666
  // src/string/escapeHtml.ts
667
+ var charRegex = /["&'<>]/g;
668
+ var escapeChars = /* @__PURE__ */ new Map([
669
+ ["&", "&amp;"],
670
+ ["<", "&lt;"],
671
+ [">", "&gt;"],
672
+ ["'", "&#39;"],
673
+ ['"', "&quot;"]
674
+ ]);
635
675
  function escapeHtml(str) {
636
- const escapeChars = {
637
- "&": "&amp;",
638
- "<": "&lt;",
639
- ">": "&gt;",
640
- "'": "&#39;",
641
- '"': "&quot;"
642
- };
643
- return str.replace(/["&'<>]/g, (char) => escapeChars[char]);
676
+ return str.replace(charRegex, (char) => escapeChars.get(char));
644
677
  }
645
678
 
646
679
  // src/string/escapeRegExp.ts
680
+ var escapleCharsRegex = /[$()*+.?[\\\]^{|}]/g;
647
681
  function escapeRegExp(str) {
648
- return str.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&");
682
+ return str.replace(escapleCharsRegex, "\\$&");
649
683
  }
650
684
 
651
685
  // src/string/kebabCase.ts
@@ -696,15 +730,16 @@ function titleCase(str) {
696
730
  }
697
731
 
698
732
  // src/string/unescapeHtml.ts
733
+ var htmlEntitiesRegex = /&(?:amp|lt|gt|quot|#39);/g;
734
+ var entityMap = /* @__PURE__ */ new Map([
735
+ ["&amp;", "&"],
736
+ ["&lt;", "<"],
737
+ ["&gt;", ">"],
738
+ ["&quot;", '"'],
739
+ ["&#39;", "'"]
740
+ ]);
699
741
  function unescapeHtml(str) {
700
- const entityMap = {
701
- "&amp;": "&",
702
- "&lt;": "<",
703
- "&gt;": ">",
704
- "&quot;": '"',
705
- "&#39;": "'"
706
- };
707
- return str.replace(/&(?:amp|lt|gt|quot|#(0+)?39);/g, (entity) => entityMap[entity]);
742
+ return str.replace(htmlEntitiesRegex, (entity) => entityMap.get(entity));
708
743
  }
709
744
 
710
745
  // src/validate/isEmpty.ts
@@ -793,6 +828,7 @@ export {
793
828
  dropWhile,
794
829
  escapeHtml,
795
830
  escapeRegExp,
831
+ flatKeys,
796
832
  group,
797
833
  hash,
798
834
  intersection,