moderndash 3.2.0 → 3.3.1

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
@@ -51,7 +51,7 @@ declare function count<TElem, TKey extends PropertyKey>(array: readonly TElem[],
51
51
  * @template TMinLength The minimum length of the array.
52
52
  */
53
53
  type ArrayMinLength<TElem, TMinLenght extends number> = BuildArrayMinLength<TElem, TMinLenght, []>;
54
- type BuildArrayMinLength<TElem, TMinLength extends number, Current extends TElem[]> = Current['length'] extends TMinLength ? [...Current, ...TElem[]] : BuildArrayMinLength<TElem, TMinLength, [...Current, TElem]>;
54
+ type BuildArrayMinLength<TElem, TMinLength extends number, Current extends TElem[]> = Current["length"] extends TMinLength ? [...Current, ...TElem[]] : BuildArrayMinLength<TElem, TMinLength, [...Current, TElem]>;
55
55
 
56
56
  type CompareFunction<TArrays extends ArrayMinLength<unknown[], 2>> = (a: TArrays[0][number], b: ArrayTail<TArrays>[number][number]) => boolean;
57
57
  type ArrayTail<TArray extends unknown[]> = TArray extends [unknown, ...infer U] ? U : never;
@@ -227,7 +227,7 @@ declare function shuffle<TElem>(array: readonly TElem[]): TElem[];
227
227
  * @returns Returns a new sorted array.
228
228
  */
229
229
  declare function sort<TElem>(array: readonly TElem[], ...orders: {
230
- order?: 'asc' | 'desc';
230
+ order?: "asc" | "desc";
231
231
  by?: (item: TElem) => number | bigint | Date | string;
232
232
  }[]): TElem[];
233
233
 
@@ -337,7 +337,7 @@ type JsonPrimitive = string | number | boolean | null;
337
337
  */
338
338
  type Jsonifiable = JsonPrimitive | JsonifiableObject | JsonifiableArray;
339
339
 
340
- type SupportedAlgorithms = 'SHA-256' | 'SHA-384' | 'SHA-512';
340
+ type SupportedAlgorithms = "SHA-256" | "SHA-384" | "SHA-512";
341
341
  /**
342
342
  * Generates a hash from the given data using the specified algorithm.
343
343
  *
@@ -435,7 +435,7 @@ declare function randomString(length: number, charSet?: string): string;
435
435
  *
436
436
  * Look at {@link debounce} for the non-decorator version.
437
437
  *
438
- * *Requires TypeScript >=5.0 or `experimentalDecorators` flag enabled.*
438
+ * *Requires the [experimentalDecorators](https://www.typescriptlang.org/tsconfig#experimentalDecorators) flag to be set.*
439
439
  *
440
440
  * @example
441
441
  * ```typescript
@@ -461,7 +461,7 @@ declare function decDebounce(wait: number): (target: unknown, key: string, descr
461
461
  *
462
462
  * Look at {@link maxCalls} for the non-decorator version.
463
463
  *
464
- * *Requires TypeScript >=5.0 or `experimentalDecorators` flag enabled.*
464
+ * *Requires the [experimentalDecorators](https://www.typescriptlang.org/tsconfig#experimentalDecorators) flag to be set.*
465
465
  *
466
466
  * @example
467
467
  * ```typescript
@@ -545,7 +545,7 @@ declare function memoize<TFunc extends GenericFunction<TFunc>, Cache extends Map
545
545
  *
546
546
  * Look at {@link memoize} for the non-decorator version.
547
547
  *
548
- * *Requires TypeScript >=5.0 or `experimentalDecorators` flag enabled.*
548
+ * *Requires the [experimentalDecorators](https://www.typescriptlang.org/tsconfig#experimentalDecorators) flag to be set.*
549
549
  *
550
550
  * @example
551
551
  * ```typescript
@@ -573,7 +573,7 @@ declare function decMemoize(options?: Parameters<typeof memoize>[1]): (target: u
573
573
  *
574
574
  * Look at {@link minCalls} for the non-decorator version.
575
575
  *
576
- * *Requires TypeScript >=5.0 or `experimentalDecorators` flag enabled.*
576
+ * *Requires the [experimentalDecorators](https://www.typescriptlang.org/tsconfig#experimentalDecorators) flag to be set.*
577
577
  * @example
578
578
  * ```typescript
579
579
  * class TestClass {
@@ -596,7 +596,7 @@ declare function decMinCalls(n: number): (target: unknown, key: string, descript
596
596
  *
597
597
  * Look at {@link throttle} for the non-decorator version.
598
598
  *
599
- * *Requires TypeScript >=5.0 or `experimentalDecorators` flag enabled.*
599
+ * *Requires the [experimentalDecorators](https://www.typescriptlang.org/tsconfig#experimentalDecorators) flag to be set.*
600
600
  *
601
601
  * @example
602
602
  * ```typescript
@@ -1214,6 +1214,7 @@ declare function snakeCase(str: string): string;
1214
1214
  * // => ['hello', 'world', '123']
1215
1215
  *
1216
1216
  * @param str The string to split into words.
1217
+ * @param forceFallback Force the use of the positive lookahead fallback. Only used for testing.
1217
1218
  * @returns An array of words.
1218
1219
  */
1219
1220
  declare function splitWords(str: string): string[];
@@ -1293,8 +1294,9 @@ declare function trimStart(str: string, chars: string): string;
1293
1294
  declare function unescapeHtml(str: string): string;
1294
1295
 
1295
1296
  /**
1296
- * Checks if `value` is an empty object, collection, map, or set.
1297
+ * Checks if a value is empty.
1297
1298
  *
1299
+ * Supports: strings, arrays, objects, maps, sets, typed arrays.
1298
1300
  * @example
1299
1301
  * isEmpty(null)
1300
1302
  * // => true
@@ -1314,7 +1316,7 @@ declare function unescapeHtml(str: string): string;
1314
1316
  * isEmpty({ 'a': 1 })
1315
1317
  * // => false
1316
1318
  * @param value The value to check.
1317
- * @returns Returns `true` if given vlaue is empty, else `false`.
1319
+ * @returns Returns `true` if `value` is empty, else `false`.
1318
1320
  */
1319
1321
  declare function isEmpty(value: string | object | null | undefined): boolean;
1320
1322
 
@@ -1322,9 +1324,11 @@ declare function isEmpty(value: string | object | null | undefined): boolean;
1322
1324
  * Performs a deep comparison between two values to determine if they are
1323
1325
  * equivalent.
1324
1326
  *
1327
+ * Supports: primitives, arrays, objects, dates, regexes, maps, sets, buffers, typed arrays
1328
+ *
1325
1329
  * @example
1326
- * var object = { 'a': 1 };
1327
- * var other = { 'a': 1 };
1330
+ * var object = { a: { b: 2 } };
1331
+ * var other = { a: { b: 2 } };
1328
1332
  *
1329
1333
  * isEqual(object, other);
1330
1334
  * // => true
package/dist/index.js CHANGED
@@ -646,12 +646,9 @@ async function tryCatch(promise) {
646
646
  }
647
647
 
648
648
  // src/string/splitWords.ts
649
- var splitWordsRegex = new RegExp(
650
- "[^\\dA-Za-z]|(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])"
651
- // lookahead for an uppercase letter followed by a lowercase letter
652
- );
649
+ var wordsRegex = /(\d*[a-z]+)|([A-Z][a-z]+)|(\d*[A-Z]+(?=[^a-z]|$))|(\d+)/g;
653
650
  function splitWords(str) {
654
- return str.split(splitWordsRegex).filter(Boolean);
651
+ return str.match(wordsRegex) ?? [];
655
652
  }
656
653
 
657
654
  // src/string/deburr.ts
@@ -788,18 +785,16 @@ function unescapeHtml(str) {
788
785
 
789
786
  // src/validate/isEmpty.ts
790
787
  function isEmpty(value) {
791
- if (value === null || value === void 0) {
788
+ if (value === null || value === void 0)
792
789
  return true;
793
- }
794
- if (typeof value === "string" || Array.isArray(value)) {
790
+ if (typeof value === "string" || Array.isArray(value))
795
791
  return value.length === 0;
796
- }
797
- if (value instanceof Map || value instanceof Set) {
792
+ if (value instanceof Map || value instanceof Set)
798
793
  return value.size === 0;
799
- }
800
- if (typeof value === "object") {
794
+ if (ArrayBuffer.isView(value))
795
+ return value.byteLength === 0;
796
+ if (typeof value === "object")
801
797
  return Object.keys(value).length === 0;
802
- }
803
798
  return false;
804
799
  }
805
800
 
@@ -809,17 +804,22 @@ function isEqual(a, b) {
809
804
  return true;
810
805
  if (typeof a !== typeof b)
811
806
  return false;
812
- if (Array.isArray(a) && Array.isArray(b)) {
807
+ if (Array.isArray(a) && Array.isArray(b))
813
808
  return isSameArray(a, b);
814
- }
815
- if (a instanceof Date && b instanceof Date) {
809
+ if (a instanceof Date && b instanceof Date)
816
810
  return a.getTime() === b.getTime();
817
- }
818
- if (a instanceof RegExp && b instanceof RegExp) {
811
+ if (a instanceof RegExp && b instanceof RegExp)
819
812
  return a.toString() === b.toString();
820
- }
821
- if (isPlainObject(a) && isPlainObject(b)) {
813
+ if (isPlainObject(a) && isPlainObject(b))
822
814
  return isSameObject(a, b);
815
+ if (a instanceof ArrayBuffer && b instanceof ArrayBuffer)
816
+ return dataViewsAreEqual(new DataView(a), new DataView(b));
817
+ if (a instanceof DataView && b instanceof DataView)
818
+ return dataViewsAreEqual(a, b);
819
+ if (isTypedArray(a) && isTypedArray(b)) {
820
+ if (a.byteLength !== b.byteLength)
821
+ return false;
822
+ return isSameArray(a, b);
823
823
  }
824
824
  return false;
825
825
  }
@@ -837,12 +837,20 @@ function isSameObject(a, b) {
837
837
  function isSameArray(a, b) {
838
838
  if (a.length !== b.length)
839
839
  return false;
840
- for (const [i, element] of a.entries()) {
841
- if (!isEqual(element, b[i]))
840
+ return a.every((element, index) => isEqual(element, b[index]));
841
+ }
842
+ function dataViewsAreEqual(a, b) {
843
+ if (a.byteLength !== b.byteLength)
844
+ return false;
845
+ for (let offset = 0; offset < a.byteLength; offset++) {
846
+ if (a.getUint8(offset) !== b.getUint8(offset))
842
847
  return false;
843
848
  }
844
849
  return true;
845
850
  }
851
+ function isTypedArray(value) {
852
+ return ArrayBuffer.isView(value) && !(value instanceof DataView);
853
+ }
846
854
 
847
855
  // src/validate/isUrl.ts
848
856
  function isUrl(str) {