es-toolkit 1.29.0 → 1.30.0-dev.963
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/CHANGELOG.md +9 -0
- package/dist/_chunk/{rangeRight-w3WrXN.js → range-HnEIT7.js} +0 -17
- package/dist/_chunk/{zipWith-Bb2eZI.js → zipWith-nbzldx.js} +11 -10
- package/dist/array/index.d.mts +1 -0
- package/dist/array/index.d.ts +1 -0
- package/dist/array/index.js +12 -2
- package/dist/array/index.mjs +1 -0
- package/dist/array/pull.d.mts +19 -0
- package/dist/array/pull.d.ts +19 -0
- package/dist/array/pull.mjs +11 -0
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/isIndex.mjs +2 -2
- package/dist/compat/_internal/isPrototype.mjs +1 -1
- package/dist/compat/array/differenceWith.d.mts +91 -0
- package/dist/compat/array/differenceWith.d.ts +91 -0
- package/dist/compat/array/differenceWith.mjs +19 -0
- package/dist/compat/array/map.d.mts +182 -0
- package/dist/compat/array/map.d.ts +182 -0
- package/dist/compat/array/map.mjs +21 -0
- package/dist/compat/array/nth.d.mts +14 -0
- package/dist/compat/array/nth.d.ts +14 -0
- package/dist/compat/array/nth.mjs +15 -0
- package/dist/compat/array/pull.d.mts +19 -0
- package/dist/compat/array/pull.d.ts +19 -0
- package/dist/compat/array/pull.mjs +8 -0
- package/dist/compat/array/takeRightWhile.d.mts +84 -0
- package/dist/compat/array/takeRightWhile.d.ts +84 -0
- package/dist/compat/array/takeRightWhile.mjs +15 -0
- package/dist/compat/function/after.d.mts +31 -0
- package/dist/compat/function/after.d.ts +31 -0
- package/dist/compat/function/after.mjs +15 -0
- package/dist/compat/function/delay.d.mts +29 -0
- package/dist/compat/function/delay.d.ts +29 -0
- package/dist/compat/function/delay.mjs +10 -0
- package/dist/compat/function/nthArg.d.mts +22 -0
- package/dist/compat/function/nthArg.d.ts +22 -0
- package/dist/compat/function/nthArg.mjs +9 -0
- package/dist/compat/index.d.mts +30 -12
- package/dist/compat/index.d.ts +30 -12
- package/dist/compat/index.js +369 -49
- package/dist/compat/index.mjs +31 -12
- package/dist/compat/math/range.d.mts +47 -0
- package/dist/compat/math/range.d.ts +47 -0
- package/dist/compat/math/range.mjs +26 -0
- package/dist/compat/math/rangeRight.d.mts +47 -0
- package/dist/compat/math/rangeRight.d.ts +47 -0
- package/dist/compat/math/rangeRight.mjs +26 -0
- package/dist/compat/math/sumBy.d.mts +2 -2
- package/dist/compat/math/sumBy.d.ts +2 -2
- package/dist/compat/object/findKey.d.mts +58 -0
- package/dist/compat/object/findKey.d.ts +58 -0
- package/dist/compat/object/findKey.mjs +30 -0
- package/dist/compat/object/keys.d.mts +22 -0
- package/dist/compat/object/keys.d.ts +22 -0
- package/dist/compat/object/keys.mjs +32 -0
- package/dist/compat/object/propertyOf.d.mts +22 -0
- package/dist/compat/object/propertyOf.d.ts +22 -0
- package/dist/compat/object/propertyOf.mjs +9 -0
- package/dist/compat/predicate/isArrayLike.d.mts +1 -1
- package/dist/compat/predicate/isArrayLike.d.ts +1 -1
- package/dist/compat/predicate/isArrayLikeObject.d.mts +1 -1
- package/dist/compat/predicate/isArrayLikeObject.d.ts +1 -1
- package/dist/compat/predicate/isElement.d.mts +1 -1
- package/dist/compat/predicate/isElement.d.ts +1 -1
- package/dist/compat/predicate/isFinite.d.mts +1 -1
- package/dist/compat/predicate/isFinite.d.ts +1 -1
- package/dist/compat/predicate/isNaN.d.mts +1 -1
- package/dist/compat/predicate/isNaN.d.ts +1 -1
- package/dist/compat/predicate/isObject.d.mts +1 -1
- package/dist/compat/predicate/isObject.d.ts +1 -1
- package/dist/compat/predicate/isObjectLike.d.mts +1 -1
- package/dist/compat/predicate/isObjectLike.d.ts +1 -1
- package/dist/compat/string/deburr.d.mts +22 -0
- package/dist/compat/string/deburr.d.ts +22 -0
- package/dist/compat/string/deburr.mjs +8 -0
- package/dist/compat/string/escapeRegExp.d.mts +14 -0
- package/dist/compat/string/escapeRegExp.d.ts +14 -0
- package/dist/compat/string/escapeRegExp.mjs +8 -0
- package/dist/compat/string/lowerFirst.d.mts +14 -0
- package/dist/compat/string/lowerFirst.d.ts +14 -0
- package/dist/compat/string/lowerFirst.mjs +8 -0
- package/dist/compat/string/toLower.d.mts +20 -0
- package/dist/compat/string/toLower.d.ts +20 -0
- package/dist/compat/string/toLower.mjs +7 -0
- package/dist/compat/string/unescape.d.mts +16 -0
- package/dist/compat/string/unescape.d.ts +16 -0
- package/dist/compat/string/unescape.mjs +8 -0
- package/dist/compat/string/upperFirst.d.mts +14 -0
- package/dist/compat/string/upperFirst.d.ts +14 -0
- package/dist/compat/string/upperFirst.mjs +8 -0
- package/dist/compat/util/invoke.d.mts +23 -0
- package/dist/compat/util/invoke.d.ts +23 -0
- package/dist/compat/util/invoke.mjs +48 -0
- package/dist/compat/util/lt.d.mts +15 -0
- package/dist/compat/util/lt.d.ts +15 -0
- package/dist/compat/util/lt.mjs +10 -0
- package/dist/compat/util/lte.d.mts +15 -0
- package/dist/compat/util/lte.d.ts +15 -0
- package/dist/compat/util/lte.mjs +10 -0
- package/dist/compat/util/method.d.mts +22 -0
- package/dist/compat/util/method.d.ts +22 -0
- package/dist/compat/util/method.mjs +9 -0
- package/dist/compat/util/now.d.mts +18 -0
- package/dist/compat/util/now.d.ts +18 -0
- package/dist/compat/util/now.mjs +5 -0
- package/dist/compat/util/stubArray.d.mts +10 -0
- package/dist/compat/util/stubArray.d.ts +10 -0
- package/dist/compat/util/stubArray.mjs +5 -0
- package/dist/compat/util/stubFalse.d.mts +10 -0
- package/dist/compat/util/stubFalse.d.ts +10 -0
- package/dist/compat/util/stubFalse.mjs +5 -0
- package/dist/compat/util/stubObject.d.mts +10 -0
- package/dist/compat/util/stubObject.d.ts +10 -0
- package/dist/compat/util/stubObject.mjs +5 -0
- package/dist/compat/util/stubString.d.mts +10 -0
- package/dist/compat/util/stubString.d.ts +10 -0
- package/dist/compat/util/stubString.mjs +5 -0
- package/dist/compat/util/stubTrue.d.mts +10 -0
- package/dist/compat/util/stubTrue.d.ts +10 -0
- package/dist/compat/util/stubTrue.mjs +5 -0
- package/dist/compat/util/toArray.mjs +0 -3
- package/dist/compat/util/toPlainObject.d.mts +16 -0
- package/dist/compat/util/toPlainObject.d.ts +16 -0
- package/dist/compat/util/toPlainObject.mjs +24 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +13 -12
- package/dist/index.mjs +1 -0
- package/dist/math/index.js +26 -10
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isBuffer } from '../../predicate/isBuffer.mjs';
|
|
2
|
+
import { isPrototype } from '../_internal/isPrototype.mjs';
|
|
3
|
+
import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|
4
|
+
import { isTypedArray } from '../predicate/isTypedArray.mjs';
|
|
5
|
+
import { times } from '../util/times.mjs';
|
|
6
|
+
|
|
7
|
+
function keys(object) {
|
|
8
|
+
if (isArrayLike(object)) {
|
|
9
|
+
return arrayLikeKeys(object);
|
|
10
|
+
}
|
|
11
|
+
const result = Object.keys(Object(object));
|
|
12
|
+
if (!isPrototype(object)) {
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
return result.filter(key => key !== 'constructor');
|
|
16
|
+
}
|
|
17
|
+
function arrayLikeKeys(object) {
|
|
18
|
+
const indices = times(object.length, index => `${index}`);
|
|
19
|
+
const filteredKeys = new Set(indices);
|
|
20
|
+
if (isBuffer(object)) {
|
|
21
|
+
filteredKeys.add('offset');
|
|
22
|
+
filteredKeys.add('parent');
|
|
23
|
+
}
|
|
24
|
+
if (isTypedArray(object)) {
|
|
25
|
+
filteredKeys.add('buffer');
|
|
26
|
+
filteredKeys.add('byteLength');
|
|
27
|
+
filteredKeys.add('byteOffset');
|
|
28
|
+
}
|
|
29
|
+
return [...indices, ...Object.keys(object).filter(key => !filteredKeys.has(key))];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { keys };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that returns the value at a given path of an object.
|
|
3
|
+
*
|
|
4
|
+
* Unlike `property`, which creates a function bound to a specific path and allows you to query different objects,
|
|
5
|
+
* `propertyOf` creates a function bound to a specific object and allows you to query different paths within that object.
|
|
6
|
+
*
|
|
7
|
+
* @param {unknown} object - The object to query.
|
|
8
|
+
* @returns {(path: PropertyKey | PropertyKey[]) => unknown} - Returns a new function that takes a path and retrieves the value from the object at the specified path.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const getValue = propertyOf({ a: { b: { c: 3 } } });
|
|
12
|
+
* const result = getValue('a.b.c');
|
|
13
|
+
* console.log(result); // => 3
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const getValue = propertyOf({ a: { b: { c: 3 } } });
|
|
17
|
+
* const result = getValue(['a', 'b', 'c']);
|
|
18
|
+
* console.log(result); // => 3
|
|
19
|
+
*/
|
|
20
|
+
declare function propertyOf(object: unknown): (path: PropertyKey | readonly PropertyKey[]) => unknown;
|
|
21
|
+
|
|
22
|
+
export { propertyOf };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that returns the value at a given path of an object.
|
|
3
|
+
*
|
|
4
|
+
* Unlike `property`, which creates a function bound to a specific path and allows you to query different objects,
|
|
5
|
+
* `propertyOf` creates a function bound to a specific object and allows you to query different paths within that object.
|
|
6
|
+
*
|
|
7
|
+
* @param {unknown} object - The object to query.
|
|
8
|
+
* @returns {(path: PropertyKey | PropertyKey[]) => unknown} - Returns a new function that takes a path and retrieves the value from the object at the specified path.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const getValue = propertyOf({ a: { b: { c: 3 } } });
|
|
12
|
+
* const result = getValue('a.b.c');
|
|
13
|
+
* console.log(result); // => 3
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const getValue = propertyOf({ a: { b: { c: 3 } } });
|
|
17
|
+
* const result = getValue(['a', 'b', 'c']);
|
|
18
|
+
* console.log(result); // => 3
|
|
19
|
+
*/
|
|
20
|
+
declare function propertyOf(object: unknown): (path: PropertyKey | readonly PropertyKey[]) => unknown;
|
|
21
|
+
|
|
22
|
+
export { propertyOf };
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
* isArrayLike(null); // false
|
|
13
13
|
* isArrayLike(undefined); // false
|
|
14
14
|
*/
|
|
15
|
-
declare function isArrayLike(value
|
|
15
|
+
declare function isArrayLike(value?: unknown): value is ArrayLike<unknown>;
|
|
16
16
|
|
|
17
17
|
export { isArrayLike };
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
* isArrayLike(null); // false
|
|
13
13
|
* isArrayLike(undefined); // false
|
|
14
14
|
*/
|
|
15
|
-
declare function isArrayLike(value
|
|
15
|
+
declare function isArrayLike(value?: unknown): value is ArrayLike<unknown>;
|
|
16
16
|
|
|
17
17
|
export { isArrayLike };
|
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
* isArrayLikeObject('abc'); // false
|
|
11
11
|
* isArrayLikeObject(()=>{}); // false
|
|
12
12
|
*/
|
|
13
|
-
declare function isArrayLikeObject(value
|
|
13
|
+
declare function isArrayLikeObject(value?: unknown): value is ArrayLike<unknown> & object;
|
|
14
14
|
|
|
15
15
|
export { isArrayLikeObject };
|
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
* isArrayLikeObject('abc'); // false
|
|
11
11
|
* isArrayLikeObject(()=>{}); // false
|
|
12
12
|
*/
|
|
13
|
-
declare function isArrayLikeObject(value
|
|
13
|
+
declare function isArrayLikeObject(value?: unknown): value is ArrayLike<unknown> & object;
|
|
14
14
|
|
|
15
15
|
export { isArrayLikeObject };
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
* console.log(isObjectLike(value4)); // false
|
|
23
23
|
* console.log(isObjectLike(value5)); // false
|
|
24
24
|
*/
|
|
25
|
-
declare function isObjectLike(value
|
|
25
|
+
declare function isObjectLike(value?: unknown): value is object;
|
|
26
26
|
|
|
27
27
|
export { isObjectLike };
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
* console.log(isObjectLike(value4)); // false
|
|
23
23
|
* console.log(isObjectLike(value5)); // false
|
|
24
24
|
*/
|
|
25
|
-
declare function isObjectLike(value
|
|
25
|
+
declare function isObjectLike(value?: unknown): value is object;
|
|
26
26
|
|
|
27
27
|
export { isObjectLike };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string by replacing special characters and diacritical marks with their ASCII equivalents.
|
|
3
|
+
* For example, "Crème brûlée" becomes "Creme brulee".
|
|
4
|
+
*
|
|
5
|
+
* @param {string} str - The input string to be deburred.
|
|
6
|
+
* @returns {string} - The deburred string with special characters replaced by their ASCII equivalents.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Basic usage:
|
|
10
|
+
* deburr('Æthelred') // returns 'Aethelred'
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Handling diacritical marks:
|
|
14
|
+
* deburr('München') // returns 'Munchen'
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Special characters:
|
|
18
|
+
* deburr('Crème brûlée') // returns 'Creme brulee'
|
|
19
|
+
*/
|
|
20
|
+
declare function deburr(str?: string): string;
|
|
21
|
+
|
|
22
|
+
export { deburr };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string by replacing special characters and diacritical marks with their ASCII equivalents.
|
|
3
|
+
* For example, "Crème brûlée" becomes "Creme brulee".
|
|
4
|
+
*
|
|
5
|
+
* @param {string} str - The input string to be deburred.
|
|
6
|
+
* @returns {string} - The deburred string with special characters replaced by their ASCII equivalents.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Basic usage:
|
|
10
|
+
* deburr('Æthelred') // returns 'Aethelred'
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Handling diacritical marks:
|
|
14
|
+
* deburr('München') // returns 'Munchen'
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Special characters:
|
|
18
|
+
* deburr('Crème brûlée') // returns 'Creme brulee'
|
|
19
|
+
*/
|
|
20
|
+
declare function deburr(str?: string): string;
|
|
21
|
+
|
|
22
|
+
export { deburr };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escapes the RegExp special characters "^", "$", "\\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in `str`.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str The string to escape.
|
|
5
|
+
* @returns {string} Returns the escaped string.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { escapeRegExp } from 'es-toolkit/string';
|
|
9
|
+
*
|
|
10
|
+
* escapeRegExp('[es-toolkit](https://es-toolkit.slash.page/)'); // returns '\[es-toolkit\]\(https://es-toolkit\.slash\.page/\)'
|
|
11
|
+
*/
|
|
12
|
+
declare function escapeRegExp(str?: string): string;
|
|
13
|
+
|
|
14
|
+
export { escapeRegExp };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escapes the RegExp special characters "^", "$", "\\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in `str`.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str The string to escape.
|
|
5
|
+
* @returns {string} Returns the escaped string.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { escapeRegExp } from 'es-toolkit/string';
|
|
9
|
+
*
|
|
10
|
+
* escapeRegExp('[es-toolkit](https://es-toolkit.slash.page/)'); // returns '\[es-toolkit\]\(https://es-toolkit\.slash\.page/\)'
|
|
11
|
+
*/
|
|
12
|
+
declare function escapeRegExp(str?: string): string;
|
|
13
|
+
|
|
14
|
+
export { escapeRegExp };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the first character of string to lower case.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str - The string that is to be changed
|
|
5
|
+
* @returns {string} - The converted string.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const convertedStr1 = lowerCase('fred') // returns 'fred'
|
|
9
|
+
* const convertedStr2 = lowerCase('Fred') // returns 'fred'
|
|
10
|
+
* const convertedStr3 = lowerCase('FRED') // returns 'fRED'
|
|
11
|
+
*/
|
|
12
|
+
declare function lowerFirst(str?: string): string;
|
|
13
|
+
|
|
14
|
+
export { lowerFirst };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the first character of string to lower case.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str - The string that is to be changed
|
|
5
|
+
* @returns {string} - The converted string.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const convertedStr1 = lowerCase('fred') // returns 'fred'
|
|
9
|
+
* const convertedStr2 = lowerCase('Fred') // returns 'fred'
|
|
10
|
+
* const convertedStr3 = lowerCase('FRED') // returns 'fRED'
|
|
11
|
+
*/
|
|
12
|
+
declare function lowerFirst(str?: string): string;
|
|
13
|
+
|
|
14
|
+
export { lowerFirst };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the given value to a string and transforms it to lower case.
|
|
3
|
+
* The function can handle various input types by first converting them to strings.
|
|
4
|
+
*
|
|
5
|
+
* @param {unknown} [value=''] The value to convert.
|
|
6
|
+
* @returns {string} Returns the lower cased string.
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* toLower('--FOO-BAR--');
|
|
10
|
+
* // => '--foo-bar--'
|
|
11
|
+
*
|
|
12
|
+
* toLower(null);
|
|
13
|
+
* // => ''
|
|
14
|
+
*
|
|
15
|
+
* toLower([1, 2, 3]);
|
|
16
|
+
* // => '1,2,3'
|
|
17
|
+
*/
|
|
18
|
+
declare function toLower(value?: unknown): string;
|
|
19
|
+
|
|
20
|
+
export { toLower };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the given value to a string and transforms it to lower case.
|
|
3
|
+
* The function can handle various input types by first converting them to strings.
|
|
4
|
+
*
|
|
5
|
+
* @param {unknown} [value=''] The value to convert.
|
|
6
|
+
* @returns {string} Returns the lower cased string.
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* toLower('--FOO-BAR--');
|
|
10
|
+
* // => '--foo-bar--'
|
|
11
|
+
*
|
|
12
|
+
* toLower(null);
|
|
13
|
+
* // => ''
|
|
14
|
+
*
|
|
15
|
+
* toLower([1, 2, 3]);
|
|
16
|
+
* // => '1,2,3'
|
|
17
|
+
*/
|
|
18
|
+
declare function toLower(value?: unknown): string;
|
|
19
|
+
|
|
20
|
+
export { toLower };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `str` to their corresponding characters.
|
|
3
|
+
* It is the inverse of `escape`.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} str The string to unescape.
|
|
6
|
+
* @returns {string} Returns the unescaped string.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* unescape('This is a <div> element.'); // returns 'This is a <div> element.'
|
|
10
|
+
* unescape('This is a "quote"'); // returns 'This is a "quote"'
|
|
11
|
+
* unescape('This is a 'quote''); // returns 'This is a 'quote''
|
|
12
|
+
* unescape('This is a & symbol'); // returns 'This is a & symbol'
|
|
13
|
+
*/
|
|
14
|
+
declare function unescape(str?: string): string;
|
|
15
|
+
|
|
16
|
+
export { unescape };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `str` to their corresponding characters.
|
|
3
|
+
* It is the inverse of `escape`.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} str The string to unescape.
|
|
6
|
+
* @returns {string} Returns the unescaped string.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* unescape('This is a <div> element.'); // returns 'This is a <div> element.'
|
|
10
|
+
* unescape('This is a "quote"'); // returns 'This is a "quote"'
|
|
11
|
+
* unescape('This is a 'quote''); // returns 'This is a 'quote''
|
|
12
|
+
* unescape('This is a & symbol'); // returns 'This is a & symbol'
|
|
13
|
+
*/
|
|
14
|
+
declare function unescape(str?: string): string;
|
|
15
|
+
|
|
16
|
+
export { unescape };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the first character of string to upper case.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str - The string that is to be changed
|
|
5
|
+
* @returns {string} - The converted string.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const convertedStr1 = upperFirst('fred') // returns 'Fred'
|
|
9
|
+
* const convertedStr2 = upperFirst('Fred') // returns 'Fred'
|
|
10
|
+
* const convertedStr3 = upperFirst('FRED') // returns 'FRED'
|
|
11
|
+
*/
|
|
12
|
+
declare function upperFirst(str?: string): string;
|
|
13
|
+
|
|
14
|
+
export { upperFirst };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the first character of string to upper case.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} str - The string that is to be changed
|
|
5
|
+
* @returns {string} - The converted string.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const convertedStr1 = upperFirst('fred') // returns 'Fred'
|
|
9
|
+
* const convertedStr2 = upperFirst('Fred') // returns 'Fred'
|
|
10
|
+
* const convertedStr3 = upperFirst('FRED') // returns 'FRED'
|
|
11
|
+
*/
|
|
12
|
+
declare function upperFirst(str?: string): string;
|
|
13
|
+
|
|
14
|
+
export { upperFirst };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invokes the method at `path` of `object` with the given arguments.
|
|
3
|
+
*
|
|
4
|
+
* @param {unknown} object - The object to query.
|
|
5
|
+
* @param {PropertyKey | PropertyKey[]} path - The path of the method to invoke.
|
|
6
|
+
* @param {any[]} args - The arguments to invoke the method with.
|
|
7
|
+
* @returns {any} - Returns the result of the invoked method.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const object = {
|
|
11
|
+
* a: {
|
|
12
|
+
* b: function (x, y) {
|
|
13
|
+
* return x + y;
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* };
|
|
17
|
+
*
|
|
18
|
+
* invoke(object, 'a.b', [1, 2]); // => 3
|
|
19
|
+
* invoke(object, ['a', 'b'], [1, 2]); // => 3
|
|
20
|
+
*/
|
|
21
|
+
declare function invoke(object: unknown, path: PropertyKey | PropertyKey[], args?: any[]): any;
|
|
22
|
+
|
|
23
|
+
export { invoke };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invokes the method at `path` of `object` with the given arguments.
|
|
3
|
+
*
|
|
4
|
+
* @param {unknown} object - The object to query.
|
|
5
|
+
* @param {PropertyKey | PropertyKey[]} path - The path of the method to invoke.
|
|
6
|
+
* @param {any[]} args - The arguments to invoke the method with.
|
|
7
|
+
* @returns {any} - Returns the result of the invoked method.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const object = {
|
|
11
|
+
* a: {
|
|
12
|
+
* b: function (x, y) {
|
|
13
|
+
* return x + y;
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* };
|
|
17
|
+
*
|
|
18
|
+
* invoke(object, 'a.b', [1, 2]); // => 3
|
|
19
|
+
* invoke(object, ['a', 'b'], [1, 2]); // => 3
|
|
20
|
+
*/
|
|
21
|
+
declare function invoke(object: unknown, path: PropertyKey | PropertyKey[], args?: any[]): any;
|
|
22
|
+
|
|
23
|
+
export { invoke };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { toPath } from './toPath.mjs';
|
|
2
|
+
import { toKey } from '../_internal/toKey.mjs';
|
|
3
|
+
import { last } from '../array/last.mjs';
|
|
4
|
+
import { get } from '../object/get.mjs';
|
|
5
|
+
|
|
6
|
+
function invoke(object, path, args = []) {
|
|
7
|
+
if (object == null) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
switch (typeof path) {
|
|
11
|
+
case 'string': {
|
|
12
|
+
if (typeof object === 'object' && Object.hasOwn(object, path)) {
|
|
13
|
+
return invokeImpl(object, [path], args);
|
|
14
|
+
}
|
|
15
|
+
return invokeImpl(object, toPath(path), args);
|
|
16
|
+
}
|
|
17
|
+
case 'number':
|
|
18
|
+
case 'symbol': {
|
|
19
|
+
return invokeImpl(object, [path], args);
|
|
20
|
+
}
|
|
21
|
+
default: {
|
|
22
|
+
if (Array.isArray(path)) {
|
|
23
|
+
return invokeImpl(object, path, args);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return invokeImpl(object, [path], args);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function invokeImpl(object, path, args) {
|
|
32
|
+
const parent = get(object, path.slice(0, -1), object);
|
|
33
|
+
if (parent == null) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
let lastKey = last(path);
|
|
37
|
+
let lastValue = lastKey?.valueOf();
|
|
38
|
+
if (typeof lastValue === 'number') {
|
|
39
|
+
lastKey = toKey(lastValue);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
lastKey = String(lastKey);
|
|
43
|
+
}
|
|
44
|
+
const func = get(parent, lastKey);
|
|
45
|
+
return func?.apply(parent, args);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { invoke };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if value is less than other.
|
|
3
|
+
*
|
|
4
|
+
* @param {unknown} value The value to compare.
|
|
5
|
+
* @param {unknown} other The other value to compare.
|
|
6
|
+
* @returns {boolean} Returns `true` if value is less than other, else `false`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* lt(1, 3); // true
|
|
10
|
+
* lt(3, 3); // false
|
|
11
|
+
* lt(3, 1); // false
|
|
12
|
+
*/
|
|
13
|
+
declare function lt(value: unknown, other: unknown): boolean;
|
|
14
|
+
|
|
15
|
+
export { lt };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if value is less than other.
|
|
3
|
+
*
|
|
4
|
+
* @param {unknown} value The value to compare.
|
|
5
|
+
* @param {unknown} other The other value to compare.
|
|
6
|
+
* @returns {boolean} Returns `true` if value is less than other, else `false`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* lt(1, 3); // true
|
|
10
|
+
* lt(3, 3); // false
|
|
11
|
+
* lt(3, 1); // false
|
|
12
|
+
*/
|
|
13
|
+
declare function lt(value: unknown, other: unknown): boolean;
|
|
14
|
+
|
|
15
|
+
export { lt };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if value is less than or equal to other.
|
|
3
|
+
*
|
|
4
|
+
* @param {unknown} value The value to compare.
|
|
5
|
+
* @param {unknown} other The other value to compare.
|
|
6
|
+
* @returns {boolean} Returns `true` if value is less than or equal to other, else `false`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* lte(1, 3); // => true
|
|
10
|
+
* lte(3, 3); // => true
|
|
11
|
+
* lte(3, 1); // => false
|
|
12
|
+
*/
|
|
13
|
+
declare function lte(value: unknown, other: unknown): boolean;
|
|
14
|
+
|
|
15
|
+
export { lte };
|