-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
26 lines (23 loc) · 1012 Bytes
/
index.js
File metadata and controls
26 lines (23 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'use strict'
const get = require('vget')
const is = require('is-instance-of')
const iterify = require('iterify')
const some = require('@lamansky/some')
const typedArrays = require('typed-arrays').names()
const xfn = require('xfn')
const notFound = Symbol('notFound')
module.exports = xfn({
pluralArg: 1,
pluralProp: 'any',
}, function has (obj, valuesToCheck, options = {}) {
valuesToCheck = iterify(valuesToCheck)
const useMethod = method => some(valuesToCheck, val => obj[method](val))
const {arrays = [], loose, sets = [], weakSets = []} = options
if (is(obj, ['WeakSet', weakSets])) return useMethod('has')
if (!loose) { // Use built-in methods if possible
if (is(obj, ['Array', arrays, typedArrays])) return useMethod('includes')
if (is(obj, ['Set', sets])) return useMethod('has')
}
// It’s less overhead if `preferStrict` and `reverse` are `false`
return get.any(obj, valuesToCheck, {...options, elseReturn: notFound, preferStrict: false, reverse: false}) !== notFound
})