moderndash 3.2.0 → 3.3.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/README.md +5 -3
- package/dist/index.cjs +47 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -13
- package/dist/index.js +47 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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[
|
|
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?:
|
|
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 =
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
599
|
+
* *Requires the [experimentalDecorators](https://www.typescriptlang.org/tsconfig#experimentalDecorators) flag to be set.*
|
|
600
600
|
*
|
|
601
601
|
* @example
|
|
602
602
|
* ```typescript
|
|
@@ -1214,9 +1214,10 @@ 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
|
-
declare function splitWords(str: string): string[];
|
|
1220
|
+
declare function splitWords(str: string, forceFallback?: boolean): string[];
|
|
1220
1221
|
|
|
1221
1222
|
/**
|
|
1222
1223
|
* Converts a string to Title Case.
|
|
@@ -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
|
|
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
|
|
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 = {
|
|
1327
|
-
* var other = {
|
|
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,25 @@ async function tryCatch(promise) {
|
|
|
646
646
|
}
|
|
647
647
|
|
|
648
648
|
// src/string/splitWords.ts
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
)
|
|
653
|
-
|
|
654
|
-
|
|
649
|
+
function splitWords(str, forceFallback = false) {
|
|
650
|
+
return lookbehindWordBoundary && !forceFallback ? str.split(lookbehindWordBoundary).filter(Boolean) : splitWordsFallback(str);
|
|
651
|
+
}
|
|
652
|
+
var wordBoundaryFallback = /[^\dA-Za-z]|(?=[A-Z][a-z])/;
|
|
653
|
+
var lookbehindReplacement = /([a-z])([A-Z])/g;
|
|
654
|
+
var lookbehindWordBoundary = tryLookbehindRegex();
|
|
655
|
+
function tryLookbehindRegex() {
|
|
656
|
+
try {
|
|
657
|
+
return new RegExp(
|
|
658
|
+
"[^\\dA-Za-z]|(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])"
|
|
659
|
+
// lookahead for an uppercase letter followed by a lowercase letter
|
|
660
|
+
);
|
|
661
|
+
} catch {
|
|
662
|
+
return void 0;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
function splitWordsFallback(str) {
|
|
666
|
+
const modifiedStr = str.replace(lookbehindReplacement, (match, p1, p2) => p1 + "\0" + p2);
|
|
667
|
+
return modifiedStr.split(wordBoundaryFallback).filter(Boolean).map((word) => word.replace(/\u0000/g, ""));
|
|
655
668
|
}
|
|
656
669
|
|
|
657
670
|
// src/string/deburr.ts
|
|
@@ -788,18 +801,16 @@ function unescapeHtml(str) {
|
|
|
788
801
|
|
|
789
802
|
// src/validate/isEmpty.ts
|
|
790
803
|
function isEmpty(value) {
|
|
791
|
-
if (value === null || value === void 0)
|
|
804
|
+
if (value === null || value === void 0)
|
|
792
805
|
return true;
|
|
793
|
-
|
|
794
|
-
if (typeof value === "string" || Array.isArray(value)) {
|
|
806
|
+
if (typeof value === "string" || Array.isArray(value))
|
|
795
807
|
return value.length === 0;
|
|
796
|
-
|
|
797
|
-
if (value instanceof Map || value instanceof Set) {
|
|
808
|
+
if (value instanceof Map || value instanceof Set)
|
|
798
809
|
return value.size === 0;
|
|
799
|
-
|
|
800
|
-
|
|
810
|
+
if (ArrayBuffer.isView(value))
|
|
811
|
+
return value.byteLength === 0;
|
|
812
|
+
if (typeof value === "object")
|
|
801
813
|
return Object.keys(value).length === 0;
|
|
802
|
-
}
|
|
803
814
|
return false;
|
|
804
815
|
}
|
|
805
816
|
|
|
@@ -809,17 +820,22 @@ function isEqual(a, b) {
|
|
|
809
820
|
return true;
|
|
810
821
|
if (typeof a !== typeof b)
|
|
811
822
|
return false;
|
|
812
|
-
if (Array.isArray(a) && Array.isArray(b))
|
|
823
|
+
if (Array.isArray(a) && Array.isArray(b))
|
|
813
824
|
return isSameArray(a, b);
|
|
814
|
-
|
|
815
|
-
if (a instanceof Date && b instanceof Date) {
|
|
825
|
+
if (a instanceof Date && b instanceof Date)
|
|
816
826
|
return a.getTime() === b.getTime();
|
|
817
|
-
|
|
818
|
-
if (a instanceof RegExp && b instanceof RegExp) {
|
|
827
|
+
if (a instanceof RegExp && b instanceof RegExp)
|
|
819
828
|
return a.toString() === b.toString();
|
|
820
|
-
|
|
821
|
-
if (isPlainObject(a) && isPlainObject(b)) {
|
|
829
|
+
if (isPlainObject(a) && isPlainObject(b))
|
|
822
830
|
return isSameObject(a, b);
|
|
831
|
+
if (a instanceof ArrayBuffer && b instanceof ArrayBuffer)
|
|
832
|
+
return dataViewsAreEqual(new DataView(a), new DataView(b));
|
|
833
|
+
if (a instanceof DataView && b instanceof DataView)
|
|
834
|
+
return dataViewsAreEqual(a, b);
|
|
835
|
+
if (isTypedArray(a) && isTypedArray(b)) {
|
|
836
|
+
if (a.byteLength !== b.byteLength)
|
|
837
|
+
return false;
|
|
838
|
+
return isSameArray(a, b);
|
|
823
839
|
}
|
|
824
840
|
return false;
|
|
825
841
|
}
|
|
@@ -837,12 +853,20 @@ function isSameObject(a, b) {
|
|
|
837
853
|
function isSameArray(a, b) {
|
|
838
854
|
if (a.length !== b.length)
|
|
839
855
|
return false;
|
|
840
|
-
|
|
841
|
-
|
|
856
|
+
return a.every((element, index) => isEqual(element, b[index]));
|
|
857
|
+
}
|
|
858
|
+
function dataViewsAreEqual(a, b) {
|
|
859
|
+
if (a.byteLength !== b.byteLength)
|
|
860
|
+
return false;
|
|
861
|
+
for (let offset = 0; offset < a.byteLength; offset++) {
|
|
862
|
+
if (a.getUint8(offset) !== b.getUint8(offset))
|
|
842
863
|
return false;
|
|
843
864
|
}
|
|
844
865
|
return true;
|
|
845
866
|
}
|
|
867
|
+
function isTypedArray(value) {
|
|
868
|
+
return ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
869
|
+
}
|
|
846
870
|
|
|
847
871
|
// src/validate/isUrl.ts
|
|
848
872
|
function isUrl(str) {
|