moderndash 3.9.2 → 3.11.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.cjs +20 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -19
- package/dist/index.d.ts +50 -19
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -128,6 +128,7 @@ declare function dropWhile<TElem>(array: readonly TElem[], predicate: (value: TE
|
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
130
|
* Creates an object with grouped items in the array.
|
|
131
|
+
* @deprecated Use the javascript "Object.groupBy()" version instead.
|
|
131
132
|
*
|
|
132
133
|
* @example
|
|
133
134
|
* group([6.1, 4.2, 6.3], Math.floor)
|
|
@@ -827,19 +828,7 @@ declare function round(number: number, precision?: number): number;
|
|
|
827
828
|
declare function sum(numbers: number[]): number;
|
|
828
829
|
declare function sum<TNum extends readonly number[]>(numbers: TNum): Call<Tuples.Sum, TNum>;
|
|
829
830
|
|
|
830
|
-
|
|
831
|
-
* The type of a plain object.
|
|
832
|
-
*
|
|
833
|
-
* This is a more strict type than the `object` type which also includes functions and arrays.
|
|
834
|
-
*
|
|
835
|
-
* You can validate if a value is a plain object with {@link isPlainObject}.
|
|
836
|
-
* @example
|
|
837
|
-
* let obj: PlainObject = { a: 1, b: 2 };
|
|
838
|
-
*
|
|
839
|
-
* obj = [1, 2, 3];
|
|
840
|
-
* // => Type 'number[]' is not assignable to type 'PlainObject'.
|
|
841
|
-
*/
|
|
842
|
-
type PlainObject = Record<PropertyKey, unknown>;
|
|
831
|
+
type GenericObject = Record<PropertyKey, any>;
|
|
843
832
|
|
|
844
833
|
type StringIfNever<Type> = [Type] extends [never] ? string : Type;
|
|
845
834
|
type Paths$1<TObj> = StringIfNever<Call<Objects.AllPaths, TObj>>;
|
|
@@ -855,7 +844,21 @@ type Paths$1<TObj> = StringIfNever<Call<Objects.AllPaths, TObj>>;
|
|
|
855
844
|
* @template TObj The type of the object to flatten.
|
|
856
845
|
* @returns A new object with flattened keys.
|
|
857
846
|
*/
|
|
858
|
-
declare function flatKeys<TObj extends
|
|
847
|
+
declare function flatKeys<TObj extends GenericObject>(obj: TObj): Record<Paths$1<TObj>, unknown>;
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* The type of a plain object.
|
|
851
|
+
*
|
|
852
|
+
* This is a more strict type than the `object` type which also includes functions and arrays.
|
|
853
|
+
*
|
|
854
|
+
* You can validate if a value is a plain object with {@link isPlainObject}.
|
|
855
|
+
* @example
|
|
856
|
+
* let obj: PlainObject = { a: 1, b: 2 };
|
|
857
|
+
*
|
|
858
|
+
* obj = [1, 2, 3];
|
|
859
|
+
* // => Type 'number[]' is not assignable to type 'PlainObject'.
|
|
860
|
+
*/
|
|
861
|
+
type PlainObject = Record<PropertyKey, unknown>;
|
|
859
862
|
|
|
860
863
|
/**
|
|
861
864
|
* This function combines two or more objects into a single new object. Arrays and other types are overwritten.
|
|
@@ -877,7 +880,7 @@ declare function flatKeys<TObj extends PlainObject>(obj: TObj): Record<Paths$1<T
|
|
|
877
880
|
* @template TSources The type of the source objects
|
|
878
881
|
* @returns A new merged object
|
|
879
882
|
*/
|
|
880
|
-
declare function merge<TTarget extends
|
|
883
|
+
declare function merge<TTarget extends GenericObject, TSources extends ArrayMinLength<GenericObject, 1>>(target: TTarget, ...sources: TSources): MergeDeepObjects<[TTarget, ...TSources]>;
|
|
881
884
|
type OptionalPropertyNames<T> = {
|
|
882
885
|
[K in keyof T]-?: (PlainObject extends {
|
|
883
886
|
[P in K]: T[K];
|
|
@@ -905,7 +908,7 @@ type MergeDeepObjects<A extends readonly [...unknown[]]> = A extends [infer L, .
|
|
|
905
908
|
* @template TObj The type of the object
|
|
906
909
|
* @returns - An object without the specified keys
|
|
907
910
|
*/
|
|
908
|
-
declare function omit<TObj extends
|
|
911
|
+
declare function omit<TObj extends GenericObject, Key extends keyof TObj>(object: TObj, keysToOmit: Key[]): Omit<TObj, Key>;
|
|
909
912
|
|
|
910
913
|
/**
|
|
911
914
|
* Creates an object composed of the picked `object` properties.
|
|
@@ -920,7 +923,7 @@ declare function omit<TObj extends PlainObject, Key extends keyof TObj>(object:
|
|
|
920
923
|
* @template TObj The type of the object.
|
|
921
924
|
* @returns Returns the new object.
|
|
922
925
|
*/
|
|
923
|
-
declare function pick<TObj extends
|
|
926
|
+
declare function pick<TObj extends GenericObject, Key extends keyof TObj>(object: TObj, keysToPick: Key[]): Pick<TObj, Key>;
|
|
924
927
|
|
|
925
928
|
type Paths<TObj> = Call<Objects.AllPaths, TObj> | string & {};
|
|
926
929
|
type UpdateObj<TObj extends PlainObject, TPath extends string, TVal> = Call<Objects.Update<TPath, TVal>, TObj>;
|
|
@@ -952,7 +955,7 @@ type UpdateObj<TObj extends PlainObject, TPath extends string, TVal> = Call<Obje
|
|
|
952
955
|
* @template TVal The type of the value to set.
|
|
953
956
|
* @returns The modified object.
|
|
954
957
|
*/
|
|
955
|
-
declare function set<TObj extends
|
|
958
|
+
declare function set<TObj extends GenericObject, TPath extends Paths<TObj>, TVal>(obj: TObj, path: TPath, value: TVal): UpdateObj<TObj, TPath, TVal>;
|
|
956
959
|
|
|
957
960
|
/**
|
|
958
961
|
* A class managing an async function queue with limited concurrency (e.g., 10 functions with 3 running at a time).
|
|
@@ -1350,6 +1353,34 @@ declare function trimStart(str: string, chars: string): string;
|
|
|
1350
1353
|
*/
|
|
1351
1354
|
declare function unescapeHtml(str: string): string;
|
|
1352
1355
|
|
|
1356
|
+
/**
|
|
1357
|
+
* Truncates a string if it's longer than the given maximum length.
|
|
1358
|
+
* The last characters of the truncated string are replaced with the ellipsis
|
|
1359
|
+
* string which defaults to "...".
|
|
1360
|
+
*
|
|
1361
|
+
* @example
|
|
1362
|
+
* truncate("Hello, world!", { length: 5 })
|
|
1363
|
+
* // => "Hello..."
|
|
1364
|
+
*
|
|
1365
|
+
* truncate("Hello, world!", { length: 5, ellipsis: " [...]" })
|
|
1366
|
+
* // => "Hello [...]"
|
|
1367
|
+
*
|
|
1368
|
+
* truncate("Hello, world!", { length: 5, separator: " " })
|
|
1369
|
+
* // => "Hello, ..."
|
|
1370
|
+
*
|
|
1371
|
+
* @param str The string to truncate
|
|
1372
|
+
* @param options The options object
|
|
1373
|
+
* @param options.length The maximum string length (default: 30)
|
|
1374
|
+
* @param options.ellipsis The string to indicate text is omitted (default: "...")
|
|
1375
|
+
* @param options.separator The separator pattern to truncate to (default: none)
|
|
1376
|
+
* @returns The truncated string
|
|
1377
|
+
*/
|
|
1378
|
+
declare function truncate(str: string, options?: {
|
|
1379
|
+
length?: number;
|
|
1380
|
+
ellipsis?: string;
|
|
1381
|
+
separator?: string;
|
|
1382
|
+
}): string;
|
|
1383
|
+
|
|
1353
1384
|
/**
|
|
1354
1385
|
* Checks if a value is empty.
|
|
1355
1386
|
*
|
|
@@ -1428,4 +1459,4 @@ declare function isPlainObject(value: unknown): value is PlainObject;
|
|
|
1428
1459
|
*/
|
|
1429
1460
|
declare function isUrl(str: string): boolean;
|
|
1430
1461
|
|
|
1431
|
-
export { type ArrayMinLength, type GenericFunction, type Jsonifiable, type 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, move, omit, pascalCase, pick, races, randomElem, randomFloat, randomInt, randomString, range, replaceLast, retry, round, set, shuffle, sleep, snakeCase, sort, splitWords, sum, takeRightWhile, takeWhile, throttle, timeout, times, titleCase, toDecorator, trim, trimEnd, trimStart, tryCatch, unescapeHtml, unique };
|
|
1462
|
+
export { type ArrayMinLength, type GenericFunction, type GenericObject, type Jsonifiable, type 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, move, omit, pascalCase, pick, races, randomElem, randomFloat, randomInt, randomString, range, replaceLast, retry, round, set, shuffle, sleep, snakeCase, sort, splitWords, sum, takeRightWhile, takeWhile, throttle, timeout, times, titleCase, toDecorator, trim, trimEnd, trimStart, truncate, tryCatch, unescapeHtml, unique };
|
package/dist/index.d.ts
CHANGED
|
@@ -128,6 +128,7 @@ declare function dropWhile<TElem>(array: readonly TElem[], predicate: (value: TE
|
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
130
|
* Creates an object with grouped items in the array.
|
|
131
|
+
* @deprecated Use the javascript "Object.groupBy()" version instead.
|
|
131
132
|
*
|
|
132
133
|
* @example
|
|
133
134
|
* group([6.1, 4.2, 6.3], Math.floor)
|
|
@@ -827,19 +828,7 @@ declare function round(number: number, precision?: number): number;
|
|
|
827
828
|
declare function sum(numbers: number[]): number;
|
|
828
829
|
declare function sum<TNum extends readonly number[]>(numbers: TNum): Call<Tuples.Sum, TNum>;
|
|
829
830
|
|
|
830
|
-
|
|
831
|
-
* The type of a plain object.
|
|
832
|
-
*
|
|
833
|
-
* This is a more strict type than the `object` type which also includes functions and arrays.
|
|
834
|
-
*
|
|
835
|
-
* You can validate if a value is a plain object with {@link isPlainObject}.
|
|
836
|
-
* @example
|
|
837
|
-
* let obj: PlainObject = { a: 1, b: 2 };
|
|
838
|
-
*
|
|
839
|
-
* obj = [1, 2, 3];
|
|
840
|
-
* // => Type 'number[]' is not assignable to type 'PlainObject'.
|
|
841
|
-
*/
|
|
842
|
-
type PlainObject = Record<PropertyKey, unknown>;
|
|
831
|
+
type GenericObject = Record<PropertyKey, any>;
|
|
843
832
|
|
|
844
833
|
type StringIfNever<Type> = [Type] extends [never] ? string : Type;
|
|
845
834
|
type Paths$1<TObj> = StringIfNever<Call<Objects.AllPaths, TObj>>;
|
|
@@ -855,7 +844,21 @@ type Paths$1<TObj> = StringIfNever<Call<Objects.AllPaths, TObj>>;
|
|
|
855
844
|
* @template TObj The type of the object to flatten.
|
|
856
845
|
* @returns A new object with flattened keys.
|
|
857
846
|
*/
|
|
858
|
-
declare function flatKeys<TObj extends
|
|
847
|
+
declare function flatKeys<TObj extends GenericObject>(obj: TObj): Record<Paths$1<TObj>, unknown>;
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* The type of a plain object.
|
|
851
|
+
*
|
|
852
|
+
* This is a more strict type than the `object` type which also includes functions and arrays.
|
|
853
|
+
*
|
|
854
|
+
* You can validate if a value is a plain object with {@link isPlainObject}.
|
|
855
|
+
* @example
|
|
856
|
+
* let obj: PlainObject = { a: 1, b: 2 };
|
|
857
|
+
*
|
|
858
|
+
* obj = [1, 2, 3];
|
|
859
|
+
* // => Type 'number[]' is not assignable to type 'PlainObject'.
|
|
860
|
+
*/
|
|
861
|
+
type PlainObject = Record<PropertyKey, unknown>;
|
|
859
862
|
|
|
860
863
|
/**
|
|
861
864
|
* This function combines two or more objects into a single new object. Arrays and other types are overwritten.
|
|
@@ -877,7 +880,7 @@ declare function flatKeys<TObj extends PlainObject>(obj: TObj): Record<Paths$1<T
|
|
|
877
880
|
* @template TSources The type of the source objects
|
|
878
881
|
* @returns A new merged object
|
|
879
882
|
*/
|
|
880
|
-
declare function merge<TTarget extends
|
|
883
|
+
declare function merge<TTarget extends GenericObject, TSources extends ArrayMinLength<GenericObject, 1>>(target: TTarget, ...sources: TSources): MergeDeepObjects<[TTarget, ...TSources]>;
|
|
881
884
|
type OptionalPropertyNames<T> = {
|
|
882
885
|
[K in keyof T]-?: (PlainObject extends {
|
|
883
886
|
[P in K]: T[K];
|
|
@@ -905,7 +908,7 @@ type MergeDeepObjects<A extends readonly [...unknown[]]> = A extends [infer L, .
|
|
|
905
908
|
* @template TObj The type of the object
|
|
906
909
|
* @returns - An object without the specified keys
|
|
907
910
|
*/
|
|
908
|
-
declare function omit<TObj extends
|
|
911
|
+
declare function omit<TObj extends GenericObject, Key extends keyof TObj>(object: TObj, keysToOmit: Key[]): Omit<TObj, Key>;
|
|
909
912
|
|
|
910
913
|
/**
|
|
911
914
|
* Creates an object composed of the picked `object` properties.
|
|
@@ -920,7 +923,7 @@ declare function omit<TObj extends PlainObject, Key extends keyof TObj>(object:
|
|
|
920
923
|
* @template TObj The type of the object.
|
|
921
924
|
* @returns Returns the new object.
|
|
922
925
|
*/
|
|
923
|
-
declare function pick<TObj extends
|
|
926
|
+
declare function pick<TObj extends GenericObject, Key extends keyof TObj>(object: TObj, keysToPick: Key[]): Pick<TObj, Key>;
|
|
924
927
|
|
|
925
928
|
type Paths<TObj> = Call<Objects.AllPaths, TObj> | string & {};
|
|
926
929
|
type UpdateObj<TObj extends PlainObject, TPath extends string, TVal> = Call<Objects.Update<TPath, TVal>, TObj>;
|
|
@@ -952,7 +955,7 @@ type UpdateObj<TObj extends PlainObject, TPath extends string, TVal> = Call<Obje
|
|
|
952
955
|
* @template TVal The type of the value to set.
|
|
953
956
|
* @returns The modified object.
|
|
954
957
|
*/
|
|
955
|
-
declare function set<TObj extends
|
|
958
|
+
declare function set<TObj extends GenericObject, TPath extends Paths<TObj>, TVal>(obj: TObj, path: TPath, value: TVal): UpdateObj<TObj, TPath, TVal>;
|
|
956
959
|
|
|
957
960
|
/**
|
|
958
961
|
* A class managing an async function queue with limited concurrency (e.g., 10 functions with 3 running at a time).
|
|
@@ -1350,6 +1353,34 @@ declare function trimStart(str: string, chars: string): string;
|
|
|
1350
1353
|
*/
|
|
1351
1354
|
declare function unescapeHtml(str: string): string;
|
|
1352
1355
|
|
|
1356
|
+
/**
|
|
1357
|
+
* Truncates a string if it's longer than the given maximum length.
|
|
1358
|
+
* The last characters of the truncated string are replaced with the ellipsis
|
|
1359
|
+
* string which defaults to "...".
|
|
1360
|
+
*
|
|
1361
|
+
* @example
|
|
1362
|
+
* truncate("Hello, world!", { length: 5 })
|
|
1363
|
+
* // => "Hello..."
|
|
1364
|
+
*
|
|
1365
|
+
* truncate("Hello, world!", { length: 5, ellipsis: " [...]" })
|
|
1366
|
+
* // => "Hello [...]"
|
|
1367
|
+
*
|
|
1368
|
+
* truncate("Hello, world!", { length: 5, separator: " " })
|
|
1369
|
+
* // => "Hello, ..."
|
|
1370
|
+
*
|
|
1371
|
+
* @param str The string to truncate
|
|
1372
|
+
* @param options The options object
|
|
1373
|
+
* @param options.length The maximum string length (default: 30)
|
|
1374
|
+
* @param options.ellipsis The string to indicate text is omitted (default: "...")
|
|
1375
|
+
* @param options.separator The separator pattern to truncate to (default: none)
|
|
1376
|
+
* @returns The truncated string
|
|
1377
|
+
*/
|
|
1378
|
+
declare function truncate(str: string, options?: {
|
|
1379
|
+
length?: number;
|
|
1380
|
+
ellipsis?: string;
|
|
1381
|
+
separator?: string;
|
|
1382
|
+
}): string;
|
|
1383
|
+
|
|
1353
1384
|
/**
|
|
1354
1385
|
* Checks if a value is empty.
|
|
1355
1386
|
*
|
|
@@ -1428,4 +1459,4 @@ declare function isPlainObject(value: unknown): value is PlainObject;
|
|
|
1428
1459
|
*/
|
|
1429
1460
|
declare function isUrl(str: string): boolean;
|
|
1430
1461
|
|
|
1431
|
-
export { type ArrayMinLength, type GenericFunction, type Jsonifiable, type 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, move, omit, pascalCase, pick, races, randomElem, randomFloat, randomInt, randomString, range, replaceLast, retry, round, set, shuffle, sleep, snakeCase, sort, splitWords, sum, takeRightWhile, takeWhile, throttle, timeout, times, titleCase, toDecorator, trim, trimEnd, trimStart, tryCatch, unescapeHtml, unique };
|
|
1462
|
+
export { type ArrayMinLength, type GenericFunction, type GenericObject, type Jsonifiable, type 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, move, omit, pascalCase, pick, races, randomElem, randomFloat, randomInt, randomString, range, replaceLast, retry, round, set, shuffle, sleep, snakeCase, sort, splitWords, sum, takeRightWhile, takeWhile, throttle, timeout, times, titleCase, toDecorator, trim, trimEnd, trimStart, truncate, tryCatch, unescapeHtml, unique };
|
package/dist/index.js
CHANGED
|
@@ -835,6 +835,24 @@ function unescapeHtml(str) {
|
|
|
835
835
|
return str.replace(htmlEntitiesRegex, (entity) => entityMap.get(entity));
|
|
836
836
|
}
|
|
837
837
|
|
|
838
|
+
// src/string/truncate.ts
|
|
839
|
+
function truncate(str, options) {
|
|
840
|
+
const { length = 30, ellipsis = "...", separator } = options ?? {};
|
|
841
|
+
if (str.length <= length)
|
|
842
|
+
return str;
|
|
843
|
+
const end = length - ellipsis.length;
|
|
844
|
+
if (end < 1)
|
|
845
|
+
return ellipsis;
|
|
846
|
+
let truncated = str.slice(0, end);
|
|
847
|
+
if (separator) {
|
|
848
|
+
const sepIndex = truncated.lastIndexOf(separator);
|
|
849
|
+
if (sepIndex > -1) {
|
|
850
|
+
truncated = truncated.slice(0, sepIndex);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
return truncated + ellipsis;
|
|
854
|
+
}
|
|
855
|
+
|
|
838
856
|
// src/validate/isEmpty.ts
|
|
839
857
|
function isEmpty(value) {
|
|
840
858
|
if (value === null || value === void 0)
|
|
@@ -976,6 +994,7 @@ export {
|
|
|
976
994
|
trim,
|
|
977
995
|
trimEnd,
|
|
978
996
|
trimStart,
|
|
997
|
+
truncate,
|
|
979
998
|
tryCatch,
|
|
980
999
|
unescapeHtml,
|
|
981
1000
|
unique
|