|
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
|
| Rev | Line | |
|---|
| [a762898] | 1 | import { isString } from '../predicate/isString.mjs';
|
|---|
| 2 | import { isEqualsSameValueZero } from '../../_internal/isEqualsSameValueZero.mjs';
|
|---|
| 3 | import { toInteger } from '../util/toInteger.mjs';
|
|---|
| 4 |
|
|---|
| 5 | function 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 |
|
|---|
| 40 | export { includes };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.