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

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.3 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const isString = require('../predicate/isString.js');
6const isEqualsSameValueZero = require('../../_internal/isEqualsSameValueZero.js');
7const toInteger = require('../util/toInteger.js');
8
9function includes(source, target, fromIndex, guard) {
10 if (source == null) {
11 return false;
12 }
13 if (guard || !fromIndex) {
14 fromIndex = 0;
15 }
16 else {
17 fromIndex = toInteger.toInteger(fromIndex);
18 }
19 if (isString.isString(source)) {
20 if (fromIndex > source.length || target instanceof RegExp) {
21 return false;
22 }
23 if (fromIndex < 0) {
24 fromIndex = Math.max(0, source.length + fromIndex);
25 }
26 return source.includes(target, fromIndex);
27 }
28 if (Array.isArray(source)) {
29 return source.includes(target, fromIndex);
30 }
31 const keys = Object.keys(source);
32 if (fromIndex < 0) {
33 fromIndex = Math.max(0, keys.length + fromIndex);
34 }
35 for (let i = fromIndex; i < keys.length; i++) {
36 const value = Reflect.get(source, keys[i]);
37 if (isEqualsSameValueZero.isEqualsSameValueZero(value, target)) {
38 return true;
39 }
40 }
41 return false;
42}
43
44exports.includes = includes;
Note: See TracBrowser for help on using the repository browser.