"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/lodash._createcache/index.js" (7 Feb 2017, 2429 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /**
    2  * lodash 3.1.2 (Custom Build) <https://lodash.com/>
    3  * Build: `lodash modern modularize exports="npm" -o ./`
    4  * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
    5  * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
    6  * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
    7  * Available under MIT license <https://lodash.com/license>
    8  */
    9 var getNative = require('lodash._getnative');
   10 
   11 /** Native method references. */
   12 var Set = getNative(global, 'Set');
   13 
   14 /* Native method references for those with the same name as other `lodash` methods. */
   15 var nativeCreate = getNative(Object, 'create');
   16 
   17 /**
   18  *
   19  * Creates a cache object to store unique values.
   20  *
   21  * @private
   22  * @param {Array} [values] The values to cache.
   23  */
   24 function SetCache(values) {
   25   var length = values ? values.length : 0;
   26 
   27   this.data = { 'hash': nativeCreate(null), 'set': new Set };
   28   while (length--) {
   29     this.push(values[length]);
   30   }
   31 }
   32 
   33 /**
   34  * Adds `value` to the cache.
   35  *
   36  * @private
   37  * @name push
   38  * @memberOf SetCache
   39  * @param {*} value The value to cache.
   40  */
   41 function cachePush(value) {
   42   var data = this.data;
   43   if (typeof value == 'string' || isObject(value)) {
   44     data.set.add(value);
   45   } else {
   46     data.hash[value] = true;
   47   }
   48 }
   49 
   50 /**
   51  * Creates a `Set` cache object to optimize linear searches of large arrays.
   52  *
   53  * @private
   54  * @param {Array} [values] The values to cache.
   55  * @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
   56  */
   57 function createCache(values) {
   58   return (nativeCreate && Set) ? new SetCache(values) : null;
   59 }
   60 
   61 /**
   62  * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
   63  * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
   64  *
   65  * @static
   66  * @memberOf _
   67  * @category Lang
   68  * @param {*} value The value to check.
   69  * @returns {boolean} Returns `true` if `value` is an object, else `false`.
   70  * @example
   71  *
   72  * _.isObject({});
   73  * // => true
   74  *
   75  * _.isObject([1, 2, 3]);
   76  * // => true
   77  *
   78  * _.isObject(1);
   79  * // => false
   80  */
   81 function isObject(value) {
   82   // Avoid a V8 JIT bug in Chrome 19-20.
   83   // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
   84   var type = typeof value;
   85   return !!value && (type == 'object' || type == 'function');
   86 }
   87 
   88 // Add functions to the `Set` cache.
   89 SetCache.prototype.push = cachePush;
   90 
   91 module.exports = createCache;