es-toolkit 1.17.0-dev.549 → 1.17.0-dev.551
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/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/array/castArray.d.mts +29 -0
- package/dist/compat/array/castArray.d.ts +29 -0
- package/dist/compat/array/castArray.mjs +8 -0
- package/dist/compat/index.d.mts +1 -0
- package/dist/compat/index.d.ts +1 -0
- package/dist/compat/index.js +8 -0
- package/dist/compat/index.mjs +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Casts value as an array if it's not one.
|
|
3
|
+
*
|
|
4
|
+
* @template T The type of elements in the array.
|
|
5
|
+
* @param {T | readonly T[]} value The value to be cast to an array.
|
|
6
|
+
* @returns {T[]} An array containing the input value if it wasn't an array, or the original array if it was.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const arr1 = castArray(1);
|
|
10
|
+
* // Returns: [1]
|
|
11
|
+
*
|
|
12
|
+
* const arr2 = castArray([1]);
|
|
13
|
+
* // Returns: [1]
|
|
14
|
+
*
|
|
15
|
+
* const arr3 = castArray({'a': 1});
|
|
16
|
+
* // Returns: [{'a': 1}]
|
|
17
|
+
*
|
|
18
|
+
* const arr4 = castArray(null);
|
|
19
|
+
* // Returns: [null]
|
|
20
|
+
*
|
|
21
|
+
* const arr5 = castArray(undefined);
|
|
22
|
+
* // Returns: [undefined]
|
|
23
|
+
*
|
|
24
|
+
* const arr6 = castArray();
|
|
25
|
+
* // Returns: []
|
|
26
|
+
*/
|
|
27
|
+
declare function castArray<T>(value?: T | readonly T[]): T[];
|
|
28
|
+
|
|
29
|
+
export { castArray };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Casts value as an array if it's not one.
|
|
3
|
+
*
|
|
4
|
+
* @template T The type of elements in the array.
|
|
5
|
+
* @param {T | readonly T[]} value The value to be cast to an array.
|
|
6
|
+
* @returns {T[]} An array containing the input value if it wasn't an array, or the original array if it was.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const arr1 = castArray(1);
|
|
10
|
+
* // Returns: [1]
|
|
11
|
+
*
|
|
12
|
+
* const arr2 = castArray([1]);
|
|
13
|
+
* // Returns: [1]
|
|
14
|
+
*
|
|
15
|
+
* const arr3 = castArray({'a': 1});
|
|
16
|
+
* // Returns: [{'a': 1}]
|
|
17
|
+
*
|
|
18
|
+
* const arr4 = castArray(null);
|
|
19
|
+
* // Returns: [null]
|
|
20
|
+
*
|
|
21
|
+
* const arr5 = castArray(undefined);
|
|
22
|
+
* // Returns: [undefined]
|
|
23
|
+
*
|
|
24
|
+
* const arr6 = castArray();
|
|
25
|
+
* // Returns: []
|
|
26
|
+
*/
|
|
27
|
+
declare function castArray<T>(value?: T | readonly T[]): T[];
|
|
28
|
+
|
|
29
|
+
export { castArray };
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -105,6 +105,7 @@ export { escape } from '../string/escape.mjs';
|
|
|
105
105
|
export { escapeRegExp } from '../string/escapeRegExp.mjs';
|
|
106
106
|
export { unescape } from '../string/unescape.mjs';
|
|
107
107
|
export { pad } from '../string/pad.mjs';
|
|
108
|
+
export { castArray } from './array/castArray.mjs';
|
|
108
109
|
export { chunk } from './array/chunk.mjs';
|
|
109
110
|
export { concat } from './array/concat.mjs';
|
|
110
111
|
export { difference } from './array/difference.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -105,6 +105,7 @@ export { escape } from '../string/escape.js';
|
|
|
105
105
|
export { escapeRegExp } from '../string/escapeRegExp.js';
|
|
106
106
|
export { unescape } from '../string/unescape.js';
|
|
107
107
|
export { pad } from '../string/pad.js';
|
|
108
|
+
export { castArray } from './array/castArray.js';
|
|
108
109
|
export { chunk } from './array/chunk.js';
|
|
109
110
|
export { concat } from './array/concat.js';
|
|
110
111
|
export { difference } from './array/difference.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -12,6 +12,13 @@ const isWeakSet$1 = require('../_chunk/isWeakSet-CogETi.js');
|
|
|
12
12
|
const isTypedArray$1 = require('../_chunk/isTypedArray-Dsrnb1.js');
|
|
13
13
|
const string_index = require('../string/index.js');
|
|
14
14
|
|
|
15
|
+
function castArray(value) {
|
|
16
|
+
if (arguments.length === 0) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
return Array.isArray(value) ? value : [value];
|
|
20
|
+
}
|
|
21
|
+
|
|
15
22
|
function chunk(arr, size = 1) {
|
|
16
23
|
size = Math.max(Math.floor(size), 0);
|
|
17
24
|
if (size === 0) {
|
|
@@ -1094,6 +1101,7 @@ exports.ary = ary;
|
|
|
1094
1101
|
exports.attempt = attempt;
|
|
1095
1102
|
exports.bind = bind;
|
|
1096
1103
|
exports.bindKey = bindKey;
|
|
1104
|
+
exports.castArray = castArray;
|
|
1097
1105
|
exports.chunk = chunk;
|
|
1098
1106
|
exports.concat = concat;
|
|
1099
1107
|
exports.conforms = conforms;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -106,6 +106,7 @@ export { escape } from '../string/escape.mjs';
|
|
|
106
106
|
export { escapeRegExp } from '../string/escapeRegExp.mjs';
|
|
107
107
|
export { unescape } from '../string/unescape.mjs';
|
|
108
108
|
export { pad } from '../string/pad.mjs';
|
|
109
|
+
export { castArray } from './array/castArray.mjs';
|
|
109
110
|
export { chunk } from './array/chunk.mjs';
|
|
110
111
|
export { concat } from './array/concat.mjs';
|
|
111
112
|
export { difference } from './array/difference.mjs';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
3
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
4
|
-
"version": "1.17.0-dev.
|
|
4
|
+
"version": "1.17.0-dev.551+887aa4d4",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|