"Fossies" - the Fresh Open Source Software Archive

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