UNPKG

lenye_base

Version:

基础方法

44 lines (35 loc) 1.02 kB
'use strict'; require('./get_tag.js'); var is_function = require('./is_function.js'); function search(needle, haystack, argStrict) { var strict = !!argStrict; var key = ''; var _needle = needle; if (is_function(_needle) && _needle.exec) { // Duck-type for RegExp if (!strict) { // Let's consider case sensitive searches as strict var flags = 'i' + (_needle.global ? 'g' : '') + (_needle.multiline ? 'm' : '') + ( // sticky is FF only _needle.sticky ? 'y' : ''); _needle = new RegExp(_needle.source, flags); } for (key in haystack) { if (haystack.hasOwnProperty(key)) { if (_needle.test(haystack[key])) { return key; } } } return false; } for (key in haystack) { if (haystack.hasOwnProperty(key)) { // eslint-disable-next-line eqeqeq if (strict && haystack[key] === needle || !strict && haystack[key] == needle) { return key; } } } return false; } module.exports = search;