es-toolkit 1.21.0-dev.684 → 1.21.0-dev.686

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.
@@ -139,6 +139,7 @@ export { mergeWith } from './object/mergeWith.mjs';
139
139
  export { fromPairs } from './object/fromPairs.mjs';
140
140
  export { unset } from './object/unset.mjs';
141
141
  export { cloneDeep } from './object/cloneDeep.mjs';
142
+ export { includes } from './object/includes.mjs';
142
143
  export { isPlainObject } from './predicate/isPlainObject.mjs';
143
144
  export { isArray } from './predicate/isArray.mjs';
144
145
  export { isArguments } from './predicate/isArguments.mjs';
@@ -139,6 +139,7 @@ export { mergeWith } from './object/mergeWith.js';
139
139
  export { fromPairs } from './object/fromPairs.js';
140
140
  export { unset } from './object/unset.js';
141
141
  export { cloneDeep } from './object/cloneDeep.js';
142
+ export { includes } from './object/includes.js';
142
143
  export { isPlainObject } from './predicate/isPlainObject.js';
143
144
  export { isArray } from './predicate/isArray.js';
144
145
  export { isArguments } from './predicate/isArguments.js';
@@ -1323,6 +1323,73 @@ function fromPairs(pairs) {
1323
1323
  return result;
1324
1324
  }
1325
1325
 
1326
+ function isString(value) {
1327
+ return typeof value === 'string' || value instanceof String;
1328
+ }
1329
+
1330
+ function toNumber(value) {
1331
+ if (isSymbol(value)) {
1332
+ return NaN;
1333
+ }
1334
+ return Number(value);
1335
+ }
1336
+
1337
+ function toFinite(value) {
1338
+ if (!value) {
1339
+ return value === 0 ? value : 0;
1340
+ }
1341
+ value = toNumber(value);
1342
+ if (value === Infinity || value === -Infinity) {
1343
+ const sign = value < 0 ? -1 : 1;
1344
+ return sign * Number.MAX_VALUE;
1345
+ }
1346
+ return value === value ? value : 0;
1347
+ }
1348
+
1349
+ function toInteger(value) {
1350
+ const finite = toFinite(value);
1351
+ const remainder = finite % 1;
1352
+ return remainder ? finite - remainder : finite;
1353
+ }
1354
+
1355
+ function includes(source, target, fromIndex, guard) {
1356
+ if (source == null) {
1357
+ return false;
1358
+ }
1359
+ if (guard || !fromIndex) {
1360
+ fromIndex = 0;
1361
+ }
1362
+ else {
1363
+ fromIndex = toInteger(fromIndex);
1364
+ }
1365
+ if (isString(source)) {
1366
+ if (fromIndex > source.length || target instanceof RegExp) {
1367
+ return false;
1368
+ }
1369
+ if (fromIndex < 0) {
1370
+ fromIndex = Math.max(0, source.length + fromIndex);
1371
+ }
1372
+ return source.includes(target, fromIndex);
1373
+ }
1374
+ if (Array.isArray(source)) {
1375
+ return source.includes(target, fromIndex);
1376
+ }
1377
+ const keys = [];
1378
+ for (const key in source) {
1379
+ keys.push(key);
1380
+ }
1381
+ if (fromIndex < 0) {
1382
+ fromIndex = Math.max(0, keys.length + fromIndex);
1383
+ }
1384
+ for (let i = fromIndex; i < keys.length; i++) {
1385
+ const value = Reflect.get(source, keys[i]);
1386
+ if (value === target || (Number.isNaN(value) && Number.isNaN(target))) {
1387
+ return true;
1388
+ }
1389
+ }
1390
+ return false;
1391
+ }
1392
+
1326
1393
  function isObject(value) {
1327
1394
  return value !== null && (typeof value === 'object' || typeof value === 'function');
1328
1395
  }
@@ -1343,10 +1410,6 @@ function isRegExp(value) {
1343
1410
  return isWeakSet$1.isRegExp(value);
1344
1411
  }
1345
1412
 
1346
- function isString(value) {
1347
- return typeof value === 'string' || value instanceof String;
1348
- }
1349
-
1350
1413
  function isWeakMap(value) {
1351
1414
  return isWeakSet$1.isWeakMap(value);
1352
1415
  }
@@ -1713,31 +1776,6 @@ function random(...args) {
1713
1776
  }
1714
1777
  }
1715
1778
 
1716
- function toNumber(value) {
1717
- if (isSymbol(value)) {
1718
- return NaN;
1719
- }
1720
- return Number(value);
1721
- }
1722
-
1723
- function toFinite(value) {
1724
- if (!value) {
1725
- return value === 0 ? value : 0;
1726
- }
1727
- value = toNumber(value);
1728
- if (value === Infinity || value === -Infinity) {
1729
- const sign = value < 0 ? -1 : 1;
1730
- return sign * Number.MAX_VALUE;
1731
- }
1732
- return value === value ? value : 0;
1733
- }
1734
-
1735
- function toInteger(value) {
1736
- const finite = toFinite(value);
1737
- const remainder = finite % 1;
1738
- return remainder ? finite - remainder : finite;
1739
- }
1740
-
1741
1779
  exports.at = zipWith.at;
1742
1780
  exports.compact = zipWith.compact;
1743
1781
  exports.countBy = zipWith.countBy;
@@ -1869,6 +1907,7 @@ exports.fromPairs = fromPairs;
1869
1907
  exports.get = get;
1870
1908
  exports.has = has;
1871
1909
  exports.inRange = inRange;
1910
+ exports.includes = includes;
1872
1911
  exports.indexOf = indexOf;
1873
1912
  exports.isArguments = isArguments;
1874
1913
  exports.isArray = isArray;
@@ -140,6 +140,7 @@ export { mergeWith } from './object/mergeWith.mjs';
140
140
  export { fromPairs } from './object/fromPairs.mjs';
141
141
  export { unset } from './object/unset.mjs';
142
142
  export { cloneDeep } from './object/cloneDeep.mjs';
143
+ export { includes } from './object/includes.mjs';
143
144
  export { isPlainObject } from './predicate/isPlainObject.mjs';
144
145
  export { isArray } from './predicate/isArray.mjs';
145
146
  export { isArguments } from './predicate/isArguments.mjs';
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Checks if an item is included in an array.
3
+ *
4
+ * @param {T[]} arr - The array to search in.
5
+ * @param {T} item - The item to search for.
6
+ * @param {number} [fromIndex=0] - The index to start searching from. If negative, it is treated as an offset from the end of the array.
7
+ * @returns {boolean} `true` if the item is found in the array, `false` otherwise.
8
+ *
9
+ * @example
10
+ * includes([1, 2, 3], 2); // true
11
+ * includes([1, 2, 3], 4); // false
12
+ * includes([1, 2, 3], 3, -1); // true
13
+ */
14
+ declare function includes<T>(arr: readonly T[], item: T, fromIndex?: number): boolean;
15
+ /**
16
+ * Checks if a value is included in an object.
17
+ *
18
+ * @param {T} obj - The object to search in.
19
+ * @param {T[keyof T]} value - The value to search for.
20
+ * @param {number} [fromIndex=0] - The index to start searching from. If negative, it is treated as an offset from the end of the array.
21
+ * @returns {boolean} `true` if the value is found in the object, `false` otherwise.
22
+ *
23
+ * @example
24
+ * includes({ a: 1, b: 'a', c: NaN }, 1); // true
25
+ * includes({ a: 1, b: 'a', c: NaN }, 'a'); // true
26
+ * includes({ a: 1, b: 'a', c: NaN }, NaN); // true
27
+ * includes({ [Symbol('sym1')]: 1 }, 1); // false
28
+ */
29
+ declare function includes<T extends Record<string, any>>(obj: T, value: T[keyof T], fromIndex?: number): boolean;
30
+ /**
31
+ * Checks if a substring is included in a string.
32
+ *
33
+ * @param {string} str - The string to search in.
34
+ * @param {string} substr - The substring to search for.
35
+ * @param {number} [fromIndex=0] - The index to start searching from. If negative, it is treated as an offset from the end of the string.
36
+ * @returns {boolean} `true` if the substring is found in the string, `false` otherwise.
37
+ *
38
+ * @example
39
+ * includes('hello world', 'world'); // true
40
+ * includes('hello world', 'test'); // false
41
+ * includes('hello world', 'o', 5); // true
42
+ */
43
+ declare function includes(str: string, substr: string, fromIndex?: number): boolean;
44
+ /**
45
+ * Checks if a specified value exists within a given source, which can be an array, an object, or a string.
46
+ *
47
+ * The comparison uses SameValueZero to check for inclusion.
48
+ *
49
+ * @param {T[] | Record<string, any> | string} source - The source to search in. It can be an array, an object, or a string.
50
+ * @param {T} [target] - The value to search for in the source.
51
+ * @param {number} [fromIndex=0] - The index to start searching from. If negative, it is treated as an offset from the end of the source.
52
+ * @returns {boolean} `true` if the value is found in the source, `false` otherwise.
53
+ *
54
+ * @example
55
+ * includes([1, 2, 3], 2); // true
56
+ * includes({ a: 1, b: 'a', c: NaN }, 'a'); // true
57
+ * includes('hello world', 'world'); // true
58
+ * includes('hello world', 'test'); // false
59
+ */
60
+ declare function includes<T>(source: readonly T[] | Record<string, any> | string, target?: T, fromIndex?: number): boolean;
61
+
62
+ export { includes };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Checks if an item is included in an array.
3
+ *
4
+ * @param {T[]} arr - The array to search in.
5
+ * @param {T} item - The item to search for.
6
+ * @param {number} [fromIndex=0] - The index to start searching from. If negative, it is treated as an offset from the end of the array.
7
+ * @returns {boolean} `true` if the item is found in the array, `false` otherwise.
8
+ *
9
+ * @example
10
+ * includes([1, 2, 3], 2); // true
11
+ * includes([1, 2, 3], 4); // false
12
+ * includes([1, 2, 3], 3, -1); // true
13
+ */
14
+ declare function includes<T>(arr: readonly T[], item: T, fromIndex?: number): boolean;
15
+ /**
16
+ * Checks if a value is included in an object.
17
+ *
18
+ * @param {T} obj - The object to search in.
19
+ * @param {T[keyof T]} value - The value to search for.
20
+ * @param {number} [fromIndex=0] - The index to start searching from. If negative, it is treated as an offset from the end of the array.
21
+ * @returns {boolean} `true` if the value is found in the object, `false` otherwise.
22
+ *
23
+ * @example
24
+ * includes({ a: 1, b: 'a', c: NaN }, 1); // true
25
+ * includes({ a: 1, b: 'a', c: NaN }, 'a'); // true
26
+ * includes({ a: 1, b: 'a', c: NaN }, NaN); // true
27
+ * includes({ [Symbol('sym1')]: 1 }, 1); // false
28
+ */
29
+ declare function includes<T extends Record<string, any>>(obj: T, value: T[keyof T], fromIndex?: number): boolean;
30
+ /**
31
+ * Checks if a substring is included in a string.
32
+ *
33
+ * @param {string} str - The string to search in.
34
+ * @param {string} substr - The substring to search for.
35
+ * @param {number} [fromIndex=0] - The index to start searching from. If negative, it is treated as an offset from the end of the string.
36
+ * @returns {boolean} `true` if the substring is found in the string, `false` otherwise.
37
+ *
38
+ * @example
39
+ * includes('hello world', 'world'); // true
40
+ * includes('hello world', 'test'); // false
41
+ * includes('hello world', 'o', 5); // true
42
+ */
43
+ declare function includes(str: string, substr: string, fromIndex?: number): boolean;
44
+ /**
45
+ * Checks if a specified value exists within a given source, which can be an array, an object, or a string.
46
+ *
47
+ * The comparison uses SameValueZero to check for inclusion.
48
+ *
49
+ * @param {T[] | Record<string, any> | string} source - The source to search in. It can be an array, an object, or a string.
50
+ * @param {T} [target] - The value to search for in the source.
51
+ * @param {number} [fromIndex=0] - The index to start searching from. If negative, it is treated as an offset from the end of the source.
52
+ * @returns {boolean} `true` if the value is found in the source, `false` otherwise.
53
+ *
54
+ * @example
55
+ * includes([1, 2, 3], 2); // true
56
+ * includes({ a: 1, b: 'a', c: NaN }, 'a'); // true
57
+ * includes('hello world', 'world'); // true
58
+ * includes('hello world', 'test'); // false
59
+ */
60
+ declare function includes<T>(source: readonly T[] | Record<string, any> | string, target?: T, fromIndex?: number): boolean;
61
+
62
+ export { includes };
@@ -0,0 +1,42 @@
1
+ import { isString } from '../predicate/isString.mjs';
2
+ import { toInteger } from '../util/toInteger.mjs';
3
+
4
+ function includes(source, target, fromIndex, guard) {
5
+ if (source == null) {
6
+ return false;
7
+ }
8
+ if (guard || !fromIndex) {
9
+ fromIndex = 0;
10
+ }
11
+ else {
12
+ fromIndex = toInteger(fromIndex);
13
+ }
14
+ if (isString(source)) {
15
+ if (fromIndex > source.length || target instanceof RegExp) {
16
+ return false;
17
+ }
18
+ if (fromIndex < 0) {
19
+ fromIndex = Math.max(0, source.length + fromIndex);
20
+ }
21
+ return source.includes(target, fromIndex);
22
+ }
23
+ if (Array.isArray(source)) {
24
+ return source.includes(target, fromIndex);
25
+ }
26
+ const keys = [];
27
+ for (const key in source) {
28
+ keys.push(key);
29
+ }
30
+ if (fromIndex < 0) {
31
+ fromIndex = Math.max(0, keys.length + fromIndex);
32
+ }
33
+ for (let i = fromIndex; i < keys.length; i++) {
34
+ const value = Reflect.get(source, keys[i]);
35
+ if (value === target || (Number.isNaN(value) && Number.isNaN(target))) {
36
+ return true;
37
+ }
38
+ }
39
+ return false;
40
+ }
41
+
42
+ export { includes };
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.21.0-dev.684+6e3226e2",
4
+ "version": "1.21.0-dev.686+dd30980a",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {