"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/lodash.union/index.js" (8 Mar 2017, 6298 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 (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 var baseFlatten = require('lodash._baseflatten'),
   10     baseUniq = require('lodash._baseuniq'),
   11     rest = require('lodash.rest');
   12 
   13 /** Used as references for various `Number` constants. */
   14 var MAX_SAFE_INTEGER = 9007199254740991;
   15 
   16 /** `Object#toString` result references. */
   17 var funcTag = '[object Function]',
   18     genTag = '[object GeneratorFunction]';
   19 
   20 /** Used for built-in method references. */
   21 var objectProto = Object.prototype;
   22 
   23 /**
   24  * Used to resolve the
   25  * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
   26  * of values.
   27  */
   28 var objectToString = objectProto.toString;
   29 
   30 /**
   31  * The base implementation of `_.property` without support for deep paths.
   32  *
   33  * @private
   34  * @param {string} key The key of the property to get.
   35  * @returns {Function} Returns the new accessor function.
   36  */
   37 function baseProperty(key) {
   38   return function(object) {
   39     return object == null ? undefined : object[key];
   40   };
   41 }
   42 
   43 /**
   44  * Gets the "length" property value of `object`.
   45  *
   46  * **Note:** This function is used to avoid a
   47  * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
   48  * Safari on at least iOS 8.1-8.3 ARM64.
   49  *
   50  * @private
   51  * @param {Object} object The object to query.
   52  * @returns {*} Returns the "length" value.
   53  */
   54 var getLength = baseProperty('length');
   55 
   56 /**
   57  * Creates an array of unique values, in order, from all given arrays using
   58  * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
   59  * for equality comparisons.
   60  *
   61  * @static
   62  * @memberOf _
   63  * @since 0.1.0
   64  * @category Array
   65  * @param {...Array} [arrays] The arrays to inspect.
   66  * @returns {Array} Returns the new array of combined values.
   67  * @example
   68  *
   69  * _.union([2, 1], [4, 2], [1, 2]);
   70  * // => [2, 1, 4]
   71  */
   72 var union = rest(function(arrays) {
   73   return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
   74 });
   75 
   76 /**
   77  * Checks if `value` is array-like. A value is considered array-like if it's
   78  * not a function and has a `value.length` that's an integer greater than or
   79  * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
   80  *
   81  * @static
   82  * @memberOf _
   83  * @since 4.0.0
   84  * @category Lang
   85  * @param {*} value The value to check.
   86  * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
   87  * @example
   88  *
   89  * _.isArrayLike([1, 2, 3]);
   90  * // => true
   91  *
   92  * _.isArrayLike(document.body.children);
   93  * // => true
   94  *
   95  * _.isArrayLike('abc');
   96  * // => true
   97  *
   98  * _.isArrayLike(_.noop);
   99  * // => false
  100  */
  101 function isArrayLike(value) {
  102   return value != null && isLength(getLength(value)) && !isFunction(value);
  103 }
  104 
  105 /**
  106  * This method is like `_.isArrayLike` except that it also checks if `value`
  107  * is an object.
  108  *
  109  * @static
  110  * @memberOf _
  111  * @since 4.0.0
  112  * @category Lang
  113  * @param {*} value The value to check.
  114  * @returns {boolean} Returns `true` if `value` is an array-like object,
  115  *  else `false`.
  116  * @example
  117  *
  118  * _.isArrayLikeObject([1, 2, 3]);
  119  * // => true
  120  *
  121  * _.isArrayLikeObject(document.body.children);
  122  * // => true
  123  *
  124  * _.isArrayLikeObject('abc');
  125  * // => false
  126  *
  127  * _.isArrayLikeObject(_.noop);
  128  * // => false
  129  */
  130 function isArrayLikeObject(value) {
  131   return isObjectLike(value) && isArrayLike(value);
  132 }
  133 
  134 /**
  135  * Checks if `value` is classified as a `Function` object.
  136  *
  137  * @static
  138  * @memberOf _
  139  * @since 0.1.0
  140  * @category Lang
  141  * @param {*} value The value to check.
  142  * @returns {boolean} Returns `true` if `value` is correctly classified,
  143  *  else `false`.
  144  * @example
  145  *
  146  * _.isFunction(_);
  147  * // => true
  148  *
  149  * _.isFunction(/abc/);
  150  * // => false
  151  */
  152 function isFunction(value) {
  153   // The use of `Object#toString` avoids issues with the `typeof` operator
  154   // in Safari 8 which returns 'object' for typed array and weak map constructors,
  155   // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
  156   var tag = isObject(value) ? objectToString.call(value) : '';
  157   return tag == funcTag || tag == genTag;
  158 }
  159 
  160 /**
  161  * Checks if `value` is a valid array-like length.
  162  *
  163  * **Note:** This function is loosely based on
  164  * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  165  *
  166  * @static
  167  * @memberOf _
  168  * @since 4.0.0
  169  * @category Lang
  170  * @param {*} value The value to check.
  171  * @returns {boolean} Returns `true` if `value` is a valid length,
  172  *  else `false`.
  173  * @example
  174  *
  175  * _.isLength(3);
  176  * // => true
  177  *
  178  * _.isLength(Number.MIN_VALUE);
  179  * // => false
  180  *
  181  * _.isLength(Infinity);
  182  * // => false
  183  *
  184  * _.isLength('3');
  185  * // => false
  186  */
  187 function isLength(value) {
  188   return typeof value == 'number' &&
  189     value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  190 }
  191 
  192 /**
  193  * Checks if `value` is the
  194  * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
  195  * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  196  *
  197  * @static
  198  * @memberOf _
  199  * @since 0.1.0
  200  * @category Lang
  201  * @param {*} value The value to check.
  202  * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  203  * @example
  204  *
  205  * _.isObject({});
  206  * // => true
  207  *
  208  * _.isObject([1, 2, 3]);
  209  * // => true
  210  *
  211  * _.isObject(_.noop);
  212  * // => true
  213  *
  214  * _.isObject(null);
  215  * // => false
  216  */
  217 function isObject(value) {
  218   var type = typeof value;
  219   return !!value && (type == 'object' || type == 'function');
  220 }
  221 
  222 /**
  223  * Checks if `value` is object-like. A value is object-like if it's not `null`
  224  * and has a `typeof` result of "object".
  225  *
  226  * @static
  227  * @memberOf _
  228  * @since 4.0.0
  229  * @category Lang
  230  * @param {*} value The value to check.
  231  * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  232  * @example
  233  *
  234  * _.isObjectLike({});
  235  * // => true
  236  *
  237  * _.isObjectLike([1, 2, 3]);
  238  * // => true
  239  *
  240  * _.isObjectLike(_.noop);
  241  * // => false
  242  *
  243  * _.isObjectLike(null);
  244  * // => false
  245  */
  246 function isObjectLike(value) {
  247   return !!value && typeof value == 'object';
  248 }
  249 
  250 module.exports = union;