es-toolkit 1.23.0-dev.748 → 1.23.0-dev.750

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.
@@ -0,0 +1,3 @@
1
+ const MAX_ARRAY_LENGTH = 4_294_967_295;
2
+
3
+ export { MAX_ARRAY_LENGTH };
@@ -206,6 +206,7 @@ export { eq } from './util/eq.mjs';
206
206
  export { times } from './util/times.mjs';
207
207
  export { toFinite } from './util/toFinite.mjs';
208
208
  export { toInteger } from './util/toInteger.mjs';
209
+ export { toLength } from './util/toLength.mjs';
209
210
  export { toNumber } from './util/toNumber.mjs';
210
211
  export { toPath } from './util/toPath.mjs';
211
212
  export { toString } from './util/toString.mjs';
@@ -206,6 +206,7 @@ export { eq } from './util/eq.js';
206
206
  export { times } from './util/times.js';
207
207
  export { toFinite } from './util/toFinite.js';
208
208
  export { toInteger } from './util/toInteger.js';
209
+ export { toLength } from './util/toLength.js';
209
210
  export { toNumber } from './util/toNumber.js';
210
211
  export { toPath } from './util/toPath.js';
211
212
  export { toString } from './util/toString.js';
@@ -8,7 +8,7 @@ const flowRight$1 = require('../_chunk/flowRight-Cf9ldK.js');
8
8
  const noop = require('../_chunk/noop-2IwLUk.js');
9
9
  const sumBy = require('../_chunk/sumBy-BkErWJ.js');
10
10
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
11
- const toMerged = require('../_chunk/toMerged-CkfNn9.js');
11
+ const toMerged = require('../_chunk/toMerged-DDLv0D.js');
12
12
  const isPlainObject$1 = require('../_chunk/isPlainObject-DgrsU7.js');
13
13
  const isWeakSet$1 = require('../_chunk/isWeakSet-Bd6nry.js');
14
14
  const upperFirst = require('../_chunk/upperFirst-BUECmK.js');
@@ -2006,6 +2006,16 @@ function times(n, iteratee) {
2006
2006
  return result;
2007
2007
  }
2008
2008
 
2009
+ const MAX_ARRAY_LENGTH = 4_294_967_295;
2010
+
2011
+ function toLength(value) {
2012
+ if (value == null) {
2013
+ return 0;
2014
+ }
2015
+ const length = Math.floor(Number(value));
2016
+ return clamp(length, 0, MAX_ARRAY_LENGTH);
2017
+ }
2018
+
2009
2019
  function defaultTo(value, defaultValue) {
2010
2020
  if (value == null || Number.isNaN(value)) {
2011
2021
  return defaultValue;
@@ -2217,6 +2227,7 @@ exports.times = times;
2217
2227
  exports.toDefaulted = toDefaulted;
2218
2228
  exports.toFinite = toFinite;
2219
2229
  exports.toInteger = toInteger;
2230
+ exports.toLength = toLength;
2220
2231
  exports.toNumber = toNumber;
2221
2232
  exports.toPath = toPath;
2222
2233
  exports.toString = toString;
@@ -206,6 +206,7 @@ export { constant } from './util/constant.mjs';
206
206
  export { times } from './util/times.mjs';
207
207
  export { toFinite } from './util/toFinite.mjs';
208
208
  export { toInteger } from './util/toInteger.mjs';
209
+ export { toLength } from './util/toLength.mjs';
209
210
  export { toNumber } from './util/toNumber.mjs';
210
211
  export { toPath } from './util/toPath.mjs';
211
212
  export { toString } from './util/toString.mjs';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Converts value to an integer suitable for use as the length of an array-like object.
3
+ *
4
+ * @param {unknown} value - The value to convert to an array length.
5
+ * @returns {number} Returns the converted integer.
6
+ *
7
+ * @example
8
+ * toLength(3.2) // => 3
9
+ * toLength(-1) // => 0
10
+ * toLength(1.9) // => 1
11
+ * toLength('42') // => 42
12
+ * toLength(null) // => 0
13
+ */
14
+ declare function toLength(value?: unknown): number;
15
+
16
+ export { toLength };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Converts value to an integer suitable for use as the length of an array-like object.
3
+ *
4
+ * @param {unknown} value - The value to convert to an array length.
5
+ * @returns {number} Returns the converted integer.
6
+ *
7
+ * @example
8
+ * toLength(3.2) // => 3
9
+ * toLength(-1) // => 0
10
+ * toLength(1.9) // => 1
11
+ * toLength('42') // => 42
12
+ * toLength(null) // => 0
13
+ */
14
+ declare function toLength(value?: unknown): number;
15
+
16
+ export { toLength };
@@ -0,0 +1,12 @@
1
+ import { MAX_ARRAY_LENGTH } from '../_internal/MAX_ARRAY_LENGTH.mjs';
2
+ import { clamp } from '../math/clamp.mjs';
3
+
4
+ function toLength(value) {
5
+ if (value == null) {
6
+ return 0;
7
+ }
8
+ const length = Math.floor(Number(value));
9
+ return clamp(length, 0, MAX_ARRAY_LENGTH);
10
+ }
11
+
12
+ export { toLength };
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ const noop = require('./_chunk/noop-2IwLUk.js');
11
11
  const sumBy = require('./_chunk/sumBy-BkErWJ.js');
12
12
  const randomInt = require('./_chunk/randomInt-CF7bZK.js');
13
13
  const math_index = require('./math/index.js');
14
- const toMerged = require('./_chunk/toMerged-CkfNn9.js');
14
+ const toMerged = require('./_chunk/toMerged-DDLv0D.js');
15
15
  const object_index = require('./object/index.js');
16
16
  const isWeakSet = require('./_chunk/isWeakSet-Bd6nry.js');
17
17
  const predicate_index = require('./predicate/index.js');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const toMerged = require('../_chunk/toMerged-CkfNn9.js');
5
+ const toMerged = require('../_chunk/toMerged-DDLv0D.js');
6
6
 
7
7
  function mergeWith(target, source, merge) {
8
8
  const sourceKeys = Object.keys(source);
@@ -1,8 +1,9 @@
1
1
  function pickBy(obj, shouldPick) {
2
2
  const result = {};
3
- const objEntries = Object.entries(obj);
4
- for (let i = 0; i < objEntries.length; i++) {
5
- const [key, value] = objEntries[i];
3
+ const keys = Object.keys(obj);
4
+ for (let i = 0; i < keys.length; i++) {
5
+ const key = keys[i];
6
+ const value = obj[key];
6
7
  if (shouldPick(value, key)) {
7
8
  result[key] = value;
8
9
  }
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.23.0-dev.748+45f6db83",
4
+ "version": "1.23.0-dev.750+a6e14159",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {