es-toolkit 1.21.0-dev.685 → 1.21.0-dev.687

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,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 };
@@ -5,27 +5,32 @@ function includes(source, target, fromIndex, guard) {
5
5
  if (source == null) {
6
6
  return false;
7
7
  }
8
- let safeIndex = fromIndex && !guard ? toInteger(fromIndex) : 0;
8
+ if (guard || !fromIndex) {
9
+ fromIndex = 0;
10
+ }
11
+ else {
12
+ fromIndex = toInteger(fromIndex);
13
+ }
9
14
  if (isString(source)) {
10
- if (safeIndex > source.length || target instanceof RegExp) {
15
+ if (fromIndex > source.length || target instanceof RegExp) {
11
16
  return false;
12
17
  }
13
- if (safeIndex < 0) {
14
- safeIndex = Math.max(0, source.length + safeIndex);
18
+ if (fromIndex < 0) {
19
+ fromIndex = Math.max(0, source.length + fromIndex);
15
20
  }
16
- return source.includes(target, safeIndex);
21
+ return source.includes(target, fromIndex);
17
22
  }
18
23
  if (Array.isArray(source)) {
19
- return source.includes(target, safeIndex);
24
+ return source.includes(target, fromIndex);
20
25
  }
21
26
  const keys = [];
22
27
  for (const key in source) {
23
28
  keys.push(key);
24
29
  }
25
- if (safeIndex < 0) {
26
- safeIndex = Math.max(0, keys.length + safeIndex);
30
+ if (fromIndex < 0) {
31
+ fromIndex = Math.max(0, keys.length + fromIndex);
27
32
  }
28
- for (let i = safeIndex; i < keys.length; i++) {
33
+ for (let i = fromIndex; i < keys.length; i++) {
29
34
  const value = Reflect.get(source, keys[i]);
30
35
  if (value === target || (Number.isNaN(value) && Number.isNaN(target))) {
31
36
  return true;
@@ -106,6 +106,7 @@ export { findLastIndex } from './array/findLastIndex.mjs';
106
106
  export { flatten } from './array/flatten.mjs';
107
107
  export { flattenDeep } from './array/flattenDeep.mjs';
108
108
  export { flattenDepth } from './array/flattenDepth.mjs';
109
+ export { includes } from './array/includes.mjs';
109
110
  export { indexOf } from './array/indexOf.mjs';
110
111
  export { join } from './array/join.mjs';
111
112
  export { orderBy } from './array/orderBy.mjs';
@@ -139,7 +140,6 @@ export { mergeWith } from './object/mergeWith.mjs';
139
140
  export { fromPairs } from './object/fromPairs.mjs';
140
141
  export { unset } from './object/unset.mjs';
141
142
  export { cloneDeep } from './object/cloneDeep.mjs';
142
- export { includes } from './object/includes.mjs';
143
143
  export { isPlainObject } from './predicate/isPlainObject.mjs';
144
144
  export { isArray } from './predicate/isArray.mjs';
145
145
  export { isArguments } from './predicate/isArguments.mjs';
@@ -106,6 +106,7 @@ export { findLastIndex } from './array/findLastIndex.js';
106
106
  export { flatten } from './array/flatten.js';
107
107
  export { flattenDeep } from './array/flattenDeep.js';
108
108
  export { flattenDepth } from './array/flattenDepth.js';
109
+ export { includes } from './array/includes.js';
109
110
  export { indexOf } from './array/indexOf.js';
110
111
  export { join } from './array/join.js';
111
112
  export { orderBy } from './array/orderBy.js';
@@ -139,7 +140,6 @@ export { mergeWith } from './object/mergeWith.js';
139
140
  export { fromPairs } from './object/fromPairs.js';
140
141
  export { unset } from './object/unset.js';
141
142
  export { cloneDeep } from './object/cloneDeep.js';
142
- export { includes } from './object/includes.js';
143
143
  export { isPlainObject } from './predicate/isPlainObject.js';
144
144
  export { isArray } from './predicate/isArray.js';
145
145
  export { isArguments } from './predicate/isArguments.js';
@@ -571,6 +571,77 @@ function flattenDepth(value, depth = 1) {
571
571
  return flatten(value, depth);
572
572
  }
573
573
 
574
+ function isString(value) {
575
+ return typeof value === 'string' || value instanceof String;
576
+ }
577
+
578
+ function isSymbol(value) {
579
+ return typeof value === 'symbol' || value instanceof Symbol;
580
+ }
581
+
582
+ function toNumber(value) {
583
+ if (isSymbol(value)) {
584
+ return NaN;
585
+ }
586
+ return Number(value);
587
+ }
588
+
589
+ function toFinite(value) {
590
+ if (!value) {
591
+ return value === 0 ? value : 0;
592
+ }
593
+ value = toNumber(value);
594
+ if (value === Infinity || value === -Infinity) {
595
+ const sign = value < 0 ? -1 : 1;
596
+ return sign * Number.MAX_VALUE;
597
+ }
598
+ return value === value ? value : 0;
599
+ }
600
+
601
+ function toInteger(value) {
602
+ const finite = toFinite(value);
603
+ const remainder = finite % 1;
604
+ return remainder ? finite - remainder : finite;
605
+ }
606
+
607
+ function includes(source, target, fromIndex, guard) {
608
+ if (source == null) {
609
+ return false;
610
+ }
611
+ if (guard || !fromIndex) {
612
+ fromIndex = 0;
613
+ }
614
+ else {
615
+ fromIndex = toInteger(fromIndex);
616
+ }
617
+ if (isString(source)) {
618
+ if (fromIndex > source.length || target instanceof RegExp) {
619
+ return false;
620
+ }
621
+ if (fromIndex < 0) {
622
+ fromIndex = Math.max(0, source.length + fromIndex);
623
+ }
624
+ return source.includes(target, fromIndex);
625
+ }
626
+ if (Array.isArray(source)) {
627
+ return source.includes(target, fromIndex);
628
+ }
629
+ const keys = [];
630
+ for (const key in source) {
631
+ keys.push(key);
632
+ }
633
+ if (fromIndex < 0) {
634
+ fromIndex = Math.max(0, keys.length + fromIndex);
635
+ }
636
+ for (let i = fromIndex; i < keys.length; i++) {
637
+ const value = Reflect.get(source, keys[i]);
638
+ if (value === target || (Number.isNaN(value) && Number.isNaN(target))) {
639
+ return true;
640
+ }
641
+ }
642
+ return false;
643
+ }
644
+
574
645
  function indexOf(array, searchElement, fromIndex) {
575
646
  if (array == null) {
576
647
  return -1;
@@ -629,10 +700,6 @@ const compareValues = (a, b, order) => {
629
700
  return 0;
630
701
  };
631
702
 
632
- function isSymbol(value) {
633
- return typeof value === 'symbol' || value instanceof Symbol;
634
- }
635
-
636
703
  const regexIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
637
704
  const regexIsPlainProp = /^\w*$/;
638
705
  function isKey(value, object) {
@@ -1323,68 +1390,6 @@ function fromPairs(pairs) {
1323
1390
  return result;
1324
1391
  }
1325
1392
 
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
- let safeIndex = fromIndex && !guard ? toInteger(fromIndex) : 0;
1360
- if (isString(source)) {
1361
- if (safeIndex > source.length || target instanceof RegExp) {
1362
- return false;
1363
- }
1364
- if (safeIndex < 0) {
1365
- safeIndex = Math.max(0, source.length + safeIndex);
1366
- }
1367
- return source.includes(target, safeIndex);
1368
- }
1369
- if (Array.isArray(source)) {
1370
- return source.includes(target, safeIndex);
1371
- }
1372
- const keys = [];
1373
- for (const key in source) {
1374
- keys.push(key);
1375
- }
1376
- if (safeIndex < 0) {
1377
- safeIndex = Math.max(0, keys.length + safeIndex);
1378
- }
1379
- for (let i = safeIndex; i < keys.length; i++) {
1380
- const value = Reflect.get(source, keys[i]);
1381
- if (value === target || (Number.isNaN(value) && Number.isNaN(target))) {
1382
- return true;
1383
- }
1384
- }
1385
- return false;
1386
- }
1387
-
1388
1393
  function isObject(value) {
1389
1394
  return value !== null && (typeof value === 'object' || typeof value === 'function');
1390
1395
  }
@@ -107,6 +107,7 @@ export { findLastIndex } from './array/findLastIndex.mjs';
107
107
  export { flatten } from './array/flatten.mjs';
108
108
  export { flattenDeep } from './array/flattenDeep.mjs';
109
109
  export { flattenDepth } from './array/flattenDepth.mjs';
110
+ export { includes } from './array/includes.mjs';
110
111
  export { indexOf } from './array/indexOf.mjs';
111
112
  export { join } from './array/join.mjs';
112
113
  export { orderBy } from './array/orderBy.mjs';
@@ -140,7 +141,6 @@ export { mergeWith } from './object/mergeWith.mjs';
140
141
  export { fromPairs } from './object/fromPairs.mjs';
141
142
  export { unset } from './object/unset.mjs';
142
143
  export { cloneDeep } from './object/cloneDeep.mjs';
143
- export { includes } from './object/includes.mjs';
144
144
  export { isPlainObject } from './predicate/isPlainObject.mjs';
145
145
  export { isArray } from './predicate/isArray.mjs';
146
146
  export { isArguments } from './predicate/isArguments.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.21.0-dev.685+4068e43b",
4
+ "version": "1.21.0-dev.687+5c39817c",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {
@@ -1,20 +0,0 @@
1
- /**
2
- * Checks if value is in source.
3
- * If source is a string, it's checked for a substring of value, otherwise SameValueZero is used for equality comparisons.
4
- * If fromIndex is negative, it's used as the offset from the end of source.
5
- *
6
- * @param {unknown[] | object | string | null | undefined} source - The source to search in.
7
- * @param {unknown} [target] - The value to search for.
8
- * @param {unknown} [fromIndex] - The index to search from.
9
- * @param {unknown} [guard] - Enables use as an iteratee for methods like `_.every`.
10
- * @returns {boolean} `true` if the object includes the target value, `false` otherwise.
11
- *
12
- * @example
13
- * includes({ a: 1, b: 'a', c: NaN }, 1); // true
14
- * includes({ a: 1, b: 'a', c: NaN }, 'a'); // true
15
- * includes({ a: 1, b: 'a', c: NaN }, NaN); // true
16
- * includes({ [Symbol('sym1')]: 1 }, 1); // false
17
- */
18
- declare function includes(source: readonly unknown[] | object | string | null | undefined, target?: unknown, fromIndex?: unknown, guard?: unknown): boolean;
19
-
20
- export { includes };
@@ -1,20 +0,0 @@
1
- /**
2
- * Checks if value is in source.
3
- * If source is a string, it's checked for a substring of value, otherwise SameValueZero is used for equality comparisons.
4
- * If fromIndex is negative, it's used as the offset from the end of source.
5
- *
6
- * @param {unknown[] | object | string | null | undefined} source - The source to search in.
7
- * @param {unknown} [target] - The value to search for.
8
- * @param {unknown} [fromIndex] - The index to search from.
9
- * @param {unknown} [guard] - Enables use as an iteratee for methods like `_.every`.
10
- * @returns {boolean} `true` if the object includes the target value, `false` otherwise.
11
- *
12
- * @example
13
- * includes({ a: 1, b: 'a', c: NaN }, 1); // true
14
- * includes({ a: 1, b: 'a', c: NaN }, 'a'); // true
15
- * includes({ a: 1, b: 'a', c: NaN }, NaN); // true
16
- * includes({ [Symbol('sym1')]: 1 }, 1); // false
17
- */
18
- declare function includes(source: readonly unknown[] | object | string | null | undefined, target?: unknown, fromIndex?: unknown, guard?: unknown): boolean;
19
-
20
- export { includes };