1/** 2 * lodash (Custom Build) <https://lodash.com/> 3 * Build: `lodash modularize exports="npm" -o ./` 4 * Copyright jQuery Foundation and other contributors <https://jquery.org/> 5 * Released under MIT license <https://lodash.com/license> 6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> 7 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors 8 */ 9 10/** Used as references for various `Number` constants. */ 11var INFINITY = 1 / 0; 12 13/** `Object#toString` result references. */ 14var funcTag = '[object Function]', 15 genTag = '[object GeneratorFunction]'; 16 17/** 18 * Used to match `RegExp` 19 * [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). 20 */ 21var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; 22 23/** Used to detect host constructors (Safari). */ 24var reIsHostCtor = /^\[object .+?Constructor\]$/; 25 26/** Used to determine if values are of the language type `Object`. */ 27var objectTypes = { 28 'function': true, 29 'object': true 30}; 31 32/** Detect free variable `exports`. */ 33var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType) 34 ? exports 35 : undefined; 36 37/** Detect free variable `module`. */ 38var freeModule = (objectTypes[typeof module] && module && !module.nodeType) 39 ? module 40 : undefined; 41 42/** Detect free variable `global` from Node.js. */ 43var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global); 44 45/** Detect free variable `self`. */ 46var freeSelf = checkGlobal(objectTypes[typeof self] && self); 47 48/** Detect free variable `window`. */ 49var freeWindow = checkGlobal(objectTypes[typeof window] && window); 50 51/** Detect `this` as the global object. */ 52var thisGlobal = checkGlobal(objectTypes[typeof this] && this); 53 54/** 55 * Used as a reference to the global object. 56 * 57 * The `this` value is used if it's the global object to avoid Greasemonkey's 58 * restricted `window` object, otherwise the `window` object is used. 59 */ 60var root = freeGlobal || 61 ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) || 62 freeSelf || thisGlobal || Function('return this')(); 63 64/** 65 * Checks if `value` is a global object. 66 * 67 * @private 68 * @param {*} value The value to check. 69 * @returns {null|Object} Returns `value` if it's a global object, else `null`. 70 */ 71function checkGlobal(value) { 72 return (value && value.Object === Object) ? value : null; 73} 74 75/** 76 * Checks if `value` is a host object in IE < 9. 77 * 78 * @private 79 * @param {*} value The value to check. 80 * @returns {boolean} Returns `true` if `value` is a host object, else `false`. 81 */ 82function isHostObject(value) { 83 // Many host objects are `Object` objects that can coerce to strings 84 // despite having improperly defined `toString` methods. 85 var result = false; 86 if (value != null && typeof value.toString != 'function') { 87 try { 88 result = !!(value + ''); 89 } catch (e) {} 90 } 91 return result; 92} 93 94/** 95 * Converts `set` to an array of its values. 96 * 97 * @private 98 * @param {Object} set The set to convert. 99 * @returns {Array} Returns the values. 100 */ 101function setToArray(set) { 102 var index = -1, 103 result = Array(set.size); 104 105 set.forEach(function(value) { 106 result[++index] = value; 107 }); 108 return result; 109} 110 111/** Used for built-in method references. */ 112var objectProto = Object.prototype; 113 114/** Used to resolve the decompiled source of functions. */ 115var funcToString = Function.prototype.toString; 116 117/** Used to check objects for own properties. */ 118var hasOwnProperty = objectProto.hasOwnProperty; 119 120/** 121 * Used to resolve the 122 * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) 123 * of values. 124 */ 125var objectToString = objectProto.toString; 126 127/** Used to detect if a method is native. */ 128var reIsNative = RegExp('^' + 129 funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&') 130 .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' 131); 132 133/* Built-in method references that are verified to be native. */ 134var Set = getNative(root, 'Set'); 135 136/** 137 * Creates a set of `values`. 138 * 139 * @private 140 * @param {Array} values The values to add to the set. 141 * @returns {Object} Returns the new set. 142 */ 143var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) { 144 return new Set(values); 145}; 146 147/** 148 * Gets the native function at `key` of `object`. 149 * 150 * @private 151 * @param {Object} object The object to query. 152 * @param {string} key The key of the method to get. 153 * @returns {*} Returns the function if it's native, else `undefined`. 154 */ 155function getNative(object, key) { 156 var value = object[key]; 157 return isNative(value) ? value : undefined; 158} 159 160/** 161 * Converts `func` to its source code. 162 * 163 * @private 164 * @param {Function} func The function to process. 165 * @returns {string} Returns the source code. 166 */ 167function toSource(func) { 168 if (func != null) { 169 try { 170 return funcToString.call(func); 171 } catch (e) {} 172 try { 173 return (func + ''); 174 } catch (e) {} 175 } 176 return ''; 177} 178 179/** 180 * Checks if `value` is classified as a `Function` object. 181 * 182 * @static 183 * @memberOf _ 184 * @since 0.1.0 185 * @category Lang 186 * @param {*} value The value to check. 187 * @returns {boolean} Returns `true` if `value` is correctly classified, 188 * else `false`. 189 * @example 190 * 191 * _.isFunction(_); 192 * // => true 193 * 194 * _.isFunction(/abc/); 195 * // => false 196 */ 197function isFunction(value) { 198 // The use of `Object#toString` avoids issues with the `typeof` operator 199 // in Safari 8 which returns 'object' for typed array and weak map constructors, 200 // and PhantomJS 1.9 which returns 'function' for `NodeList` instances. 201 var tag = isObject(value) ? objectToString.call(value) : ''; 202 return tag == funcTag || tag == genTag; 203} 204 205/** 206 * Checks if `value` is the 207 * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types) 208 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) 209 * 210 * @static 211 * @memberOf _ 212 * @since 0.1.0 213 * @category Lang 214 * @param {*} value The value to check. 215 * @returns {boolean} Returns `true` if `value` is an object, else `false`. 216 * @example 217 * 218 * _.isObject({}); 219 * // => true 220 * 221 * _.isObject([1, 2, 3]); 222 * // => true 223 * 224 * _.isObject(_.noop); 225 * // => true 226 * 227 * _.isObject(null); 228 * // => false 229 */ 230function isObject(value) { 231 var type = typeof value; 232 return !!value && (type == 'object' || type == 'function'); 233} 234 235/** 236 * Checks if `value` is a native function. 237 * 238 * @static 239 * @memberOf _ 240 * @since 3.0.0 241 * @category Lang 242 * @param {*} value The value to check. 243 * @returns {boolean} Returns `true` if `value` is a native function, 244 * else `false`. 245 * @example 246 * 247 * _.isNative(Array.prototype.push); 248 * // => true 249 * 250 * _.isNative(_); 251 * // => false 252 */ 253function isNative(value) { 254 if (!isObject(value)) { 255 return false; 256 } 257 var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor; 258 return pattern.test(toSource(value)); 259} 260 261/** 262 * A no-operation function that returns `undefined` regardless of the 263 * arguments it receives. 264 * 265 * @static 266 * @memberOf _ 267 * @since 2.3.0 268 * @category Util 269 * @example 270 * 271 * var object = { 'user': 'fred' }; 272 * 273 * _.noop(object) === undefined; 274 * // => true 275 */ 276function noop() { 277 // No operation performed. 278} 279 280module.exports = createSet; 281