"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/lodash._baseflatten/index.js" (8 Mar 2017, 8796 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 
   10 /** Used as references for various `Number` constants. */
   11 var MAX_SAFE_INTEGER = 9007199254740991;
   12 
   13 /** `Object#toString` result references. */
   14 var argsTag = '[object Arguments]',
   15     funcTag = '[object Function]',
   16     genTag = '[object GeneratorFunction]';
   17 
   18 /**
   19  * Appends the elements of `values` to `array`.
   20  *
   21  * @private
   22  * @param {Array} array The array to modify.
   23  * @param {Array} values The values to append.
   24  * @returns {Array} Returns `array`.
   25  */
   26 function arrayPush(array, values) {
   27   var index = -1,
   28       length = values.length,
   29       offset = array.length;
   30 
   31   while (++index < length) {
   32     array[offset + index] = values[index];
   33   }
   34   return array;
   35 }
   36 
   37 /** Used for built-in method references. */
   38 var objectProto = Object.prototype;
   39 
   40 /** Used to check objects for own properties. */
   41 var hasOwnProperty = objectProto.hasOwnProperty;
   42 
   43 /**
   44  * Used to resolve the
   45  * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
   46  * of values.
   47  */
   48 var objectToString = objectProto.toString;
   49 
   50 /** Built-in value references. */
   51 var propertyIsEnumerable = objectProto.propertyIsEnumerable;
   52 
   53 /**
   54  * The base implementation of `_.flatten` with support for restricting flattening.
   55  *
   56  * @private
   57  * @param {Array} array The array to flatten.
   58  * @param {number} depth The maximum recursion depth.
   59  * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
   60  * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
   61  * @param {Array} [result=[]] The initial result value.
   62  * @returns {Array} Returns the new flattened array.
   63  */
   64 function baseFlatten(array, depth, predicate, isStrict, result) {
   65   var index = -1,
   66       length = array.length;
   67 
   68   predicate || (predicate = isFlattenable);
   69   result || (result = []);
   70 
   71   while (++index < length) {
   72     var value = array[index];
   73     if (depth > 0 && predicate(value)) {
   74       if (depth > 1) {
   75         // Recursively flatten arrays (susceptible to call stack limits).
   76         baseFlatten(value, depth - 1, predicate, isStrict, result);
   77       } else {
   78         arrayPush(result, value);
   79       }
   80     } else if (!isStrict) {
   81       result[result.length] = value;
   82     }
   83   }
   84   return result;
   85 }
   86 
   87 /**
   88  * The base implementation of `_.property` without support for deep paths.
   89  *
   90  * @private
   91  * @param {string} key The key of the property to get.
   92  * @returns {Function} Returns the new accessor function.
   93  */
   94 function baseProperty(key) {
   95   return function(object) {
   96     return object == null ? undefined : object[key];
   97   };
   98 }
   99 
  100 /**
  101  * Gets the "length" property value of `object`.
  102  *
  103  * **Note:** This function is used to avoid a
  104  * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
  105  * Safari on at least iOS 8.1-8.3 ARM64.
  106  *
  107  * @private
  108  * @param {Object} object The object to query.
  109  * @returns {*} Returns the "length" value.
  110  */
  111 var getLength = baseProperty('length');
  112 
  113 /**
  114  * Checks if `value` is a flattenable `arguments` object or array.
  115  *
  116  * @private
  117  * @param {*} value The value to check.
  118  * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  119  */
  120 function isFlattenable(value) {
  121   return isArray(value) || isArguments(value);
  122 }
  123 
  124 /**
  125  * Checks if `value` is likely an `arguments` object.
  126  *
  127  * @static
  128  * @memberOf _
  129  * @since 0.1.0
  130  * @category Lang
  131  * @param {*} value The value to check.
  132  * @returns {boolean} Returns `true` if `value` is correctly classified,
  133  *  else `false`.
  134  * @example
  135  *
  136  * _.isArguments(function() { return arguments; }());
  137  * // => true
  138  *
  139  * _.isArguments([1, 2, 3]);
  140  * // => false
  141  */
  142 function isArguments(value) {
  143   // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
  144   return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  145     (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  146 }
  147 
  148 /**
  149  * Checks if `value` is classified as an `Array` object.
  150  *
  151  * @static
  152  * @memberOf _
  153  * @since 0.1.0
  154  * @type {Function}
  155  * @category Lang
  156  * @param {*} value The value to check.
  157  * @returns {boolean} Returns `true` if `value` is correctly classified,
  158  *  else `false`.
  159  * @example
  160  *
  161  * _.isArray([1, 2, 3]);
  162  * // => true
  163  *
  164  * _.isArray(document.body.children);
  165  * // => false
  166  *
  167  * _.isArray('abc');
  168  * // => false
  169  *
  170  * _.isArray(_.noop);
  171  * // => false
  172  */
  173 var isArray = Array.isArray;
  174 
  175 /**
  176  * Checks if `value` is array-like. A value is considered array-like if it's
  177  * not a function and has a `value.length` that's an integer greater than or
  178  * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  179  *
  180  * @static
  181  * @memberOf _
  182  * @since 4.0.0
  183  * @category Lang
  184  * @param {*} value The value to check.
  185  * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  186  * @example
  187  *
  188  * _.isArrayLike([1, 2, 3]);
  189  * // => true
  190  *
  191  * _.isArrayLike(document.body.children);
  192  * // => true
  193  *
  194  * _.isArrayLike('abc');
  195  * // => true
  196  *
  197  * _.isArrayLike(_.noop);
  198  * // => false
  199  */
  200 function isArrayLike(value) {
  201   return value != null && isLength(getLength(value)) && !isFunction(value);
  202 }
  203 
  204 /**
  205  * This method is like `_.isArrayLike` except that it also checks if `value`
  206  * is an object.
  207  *
  208  * @static
  209  * @memberOf _
  210  * @since 4.0.0
  211  * @category Lang
  212  * @param {*} value The value to check.
  213  * @returns {boolean} Returns `true` if `value` is an array-like object,
  214  *  else `false`.
  215  * @example
  216  *
  217  * _.isArrayLikeObject([1, 2, 3]);
  218  * // => true
  219  *
  220  * _.isArrayLikeObject(document.body.children);
  221  * // => true
  222  *
  223  * _.isArrayLikeObject('abc');
  224  * // => false
  225  *
  226  * _.isArrayLikeObject(_.noop);
  227  * // => false
  228  */
  229 function isArrayLikeObject(value) {
  230   return isObjectLike(value) && isArrayLike(value);
  231 }
  232 
  233 /**
  234  * Checks if `value` is classified as a `Function` object.
  235  *
  236  * @static
  237  * @memberOf _
  238  * @since 0.1.0
  239  * @category Lang
  240  * @param {*} value The value to check.
  241  * @returns {boolean} Returns `true` if `value` is correctly classified,
  242  *  else `false`.
  243  * @example
  244  *
  245  * _.isFunction(_);
  246  * // => true
  247  *
  248  * _.isFunction(/abc/);
  249  * // => false
  250  */
  251 function isFunction(value) {
  252   // The use of `Object#toString` avoids issues with the `typeof` operator
  253   // in Safari 8 which returns 'object' for typed array and weak map constructors,
  254   // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
  255   var tag = isObject(value) ? objectToString.call(value) : '';
  256   return tag == funcTag || tag == genTag;
  257 }
  258 
  259 /**
  260  * Checks if `value` is a valid array-like length.
  261  *
  262  * **Note:** This function is loosely based on
  263  * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  264  *
  265  * @static
  266  * @memberOf _
  267  * @since 4.0.0
  268  * @category Lang
  269  * @param {*} value The value to check.
  270  * @returns {boolean} Returns `true` if `value` is a valid length,
  271  *  else `false`.
  272  * @example
  273  *
  274  * _.isLength(3);
  275  * // => true
  276  *
  277  * _.isLength(Number.MIN_VALUE);
  278  * // => false
  279  *
  280  * _.isLength(Infinity);
  281  * // => false
  282  *
  283  * _.isLength('3');
  284  * // => false
  285  */
  286 function isLength(value) {
  287   return typeof value == 'number' &&
  288     value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  289 }
  290 
  291 /**
  292  * Checks if `value` is the
  293  * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
  294  * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  295  *
  296  * @static
  297  * @memberOf _
  298  * @since 0.1.0
  299  * @category Lang
  300  * @param {*} value The value to check.
  301  * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  302  * @example
  303  *
  304  * _.isObject({});
  305  * // => true
  306  *
  307  * _.isObject([1, 2, 3]);
  308  * // => true
  309  *
  310  * _.isObject(_.noop);
  311  * // => true
  312  *
  313  * _.isObject(null);
  314  * // => false
  315  */
  316 function isObject(value) {
  317   var type = typeof value;
  318   return !!value && (type == 'object' || type == 'function');
  319 }
  320 
  321 /**
  322  * Checks if `value` is object-like. A value is object-like if it's not `null`
  323  * and has a `typeof` result of "object".
  324  *
  325  * @static
  326  * @memberOf _
  327  * @since 4.0.0
  328  * @category Lang
  329  * @param {*} value The value to check.
  330  * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  331  * @example
  332  *
  333  * _.isObjectLike({});
  334  * // => true
  335  *
  336  * _.isObjectLike([1, 2, 3]);
  337  * // => true
  338  *
  339  * _.isObjectLike(_.noop);
  340  * // => false
  341  *
  342  * _.isObjectLike(null);
  343  * // => false
  344  */
  345 function isObjectLike(value) {
  346   return !!value && typeof value == 'object';
  347 }
  348 
  349 module.exports = baseFlatten;