UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

25 lines (24 loc) 1.19 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.includes = void 0; const baseIndexOf_1 = __importDefault(require("./.internal/baseIndexOf")); const isArrayLike_1 = __importDefault(require("./isArrayLike")); const isString_1 = __importDefault(require("./isString")); const toInteger_1 = __importDefault(require("./toInteger")); const values_1 = __importDefault(require("./values")); function includes(collection, value, fromIndex, guard) { collection = (0, isArrayLike_1.default)(collection) ? collection : (0, values_1.default)(collection); fromIndex = (fromIndex && !guard) ? (0, toInteger_1.default)(fromIndex) : 0; const length = collection.length; if (fromIndex < 0) { fromIndex = Math.max(length + fromIndex, 0); } return (0, isString_1.default)(collection) ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1) : (!!length && (0, baseIndexOf_1.default)(collection, value, fromIndex) > -1); } exports.includes = includes; exports.default = includes;