source: node_modules/es-toolkit/dist/compat/array/includes.mjs

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import { isString } from '../predicate/isString.mjs';
2import { isEqualsSameValueZero } from '../../_internal/isEqualsSameValueZero.mjs';
3import { toInteger } from '../util/toInteger.mjs';
4
5function includes(source, target, fromIndex, guard) {
6 if (source == null) {
7 return false;
8 }
9 if (guard || !fromIndex) {
10 fromIndex = 0;
11 }
12 else {
13 fromIndex = toInteger(fromIndex);
14 }
15 if (isString(source)) {
16 if (fromIndex > source.length || target instanceof RegExp) {
17 return false;
18 }
19 if (fromIndex < 0) {
20 fromIndex = Math.max(0, source.length + fromIndex);
21 }
22 return source.includes(target, fromIndex);
23 }
24 if (Array.isArray(source)) {
25 return source.includes(target, fromIndex);
26 }
27 const keys = Object.keys(source);
28 if (fromIndex < 0) {
29 fromIndex = Math.max(0, keys.length + fromIndex);
30 }
31 for (let i = fromIndex; i < keys.length; i++) {
32 const value = Reflect.get(source, keys[i]);
33 if (isEqualsSameValueZero(value, target)) {
34 return true;
35 }
36 }
37 return false;
38}
39
40export { includes };
Note: See TracBrowser for help on using the repository browser.