foop
Version:
interfaces that describe their intentions.
1,822 lines (1,646 loc) • 322 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.ChainAble = factory());
}(this, (function () { 'use strict';
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
/* ___filename___: src/deps/util/assign.js */
/**
* @memberOf util
* @since 4.0.0
*
* {@link https://github.com/mobxjs/mobx/blob/master/src/utils/utils.ts#L86 mobx-object-assign}
* {@link https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign mozilla-object-assign}
* {@link https://esdiscuss.org/topic/object-assign-with-several-source-objects esdiscuss-object-assign}
* {@link https://github.com/facebook/react/blob/4b2eac3de7e1dbf5c2dd742fd9989974a83972cb/scripts/babel/transform-object-assign-require.js react-object-assign}
* {@link https://github.com/lodash/lodash/blob/master/.internal/assignValue.js lodash-assign}
* {@link https://github.com/ramda/ramda/blob/master/src/internal/_objectAssign.js ramda-assign}
* @see {@link react-object-assign}
* @see {@link ramda-assign}
* @see {@link lodash-assign}
* @see {@link mobx-object-assign}
* @see {@link esdiscuss-object-assign}
* @see {@link mozilla-object-assign}
*
* @type {Function}
*/
var assign = Object.assign;
// const ENV_COMPAT = require('../env/compat')
// @TODO if (ENV_COMPAT) polyfill
// --- check
// function shouldUseNative() {
// try {
// if (!Object.assign) {
// return false
// }
//
// // Detect buggy property enumeration order in older V8 versions.
//
// // https://bugs.chromium.org/p/v8/issues/detail?id=4118
// var test1 = new String('abc') // eslint-disable-line no-new-wrappers
// test1[5] = 'de'
// if (Object.getOwnPropertyNames(test1)[0] === '5') {
// return false
// }
//
// // https://bugs.chromium.org/p/v8/issues/detail?id=3056
// var test2 = {}
// for (var i = 0; i < 10; i++) {
// test2['_' + String.fromCharCode(i)] = i
// }
// var order2 = Object.getOwnPropertyNames(test2).map(function(n) {
// return test2[n]
// })
// if (order2.join('') !== '0123456789') {
// return false
// }
//
// // https://bugs.chromium.org/p/v8/issues/detail?id=3056
// var test3 = {}
// 'abcdefghijklmnopqrst'.split('').forEach(function(letter) {
// test3[letter] = letter
// })
// if (
// Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst'
// ) {
// return false
// }
//
// return true
// }
// catch (err) {
// // We don't expect any of the above to throw, but better to be safe.
// return false
// }
// }
// --- handle
// function ObjectAssign(target, source) {
// var from
// var to = toObject(target)
// var symbols
//
// for (var s = 1; s < arguments.length; s++) {
// from = Object(arguments[s])
//
// for (var key in from) {
// if (hasOwnProperty.call(from, key)) {
// to[key] = from[key]
// }
// }
//
// if (getOwnPropertySymbols) {
// symbols = getOwnPropertySymbols(from)
// for (var i = 0; i < symbols.length; i++) {
// if (propIsEnumerable.call(from, symbols[i])) {
// to[symbols[i]] = from[symbols[i]]
// }
// }
// }
// }
//
// return to
// }
/* ___filename___: src/deps/is/undefined.js */
/**
* @desc Checks if `value` is `undefined`.
* @category Lang
*
* @param {*} x value
* @return {boolean} isUndefined
*
* @since 4.0.0-alpha.1
* @memberOf is
* @func isUndefined
*
* @see is/nullOrUndefined
* {@link https://github.com/infernojs/inferno/blob/master/packages/inferno-shared/src/index.ts#L57 inferno-isundefined}
* {@link https://nodejs.org/api/util.html#util_util_isundefined_object node_util_isundefined}
* @see {@link node_util_isundefined}
* @see {@link inferno-isundefined}
*
* @example
*
* isUndefined(undefined)
* //=> true
* isUndefined(void 0)
* //=> true
*
* isUndefined(null)
* //=> false
* isUndefined(NaN)
* //=> false
* isUndefined({})
* //=> false
* isUndefined('')
* //=> false
* isUndefined(1)
* //=> false
* isUndefined(false)
* //=> false
*
*/
var _undefined = x => x === undefined;
/* ___filename___: src/deps/meta/SHORTHANDS_KEY.js */
/* istanbul ignore next: wip build */
var SHORTHANDS_KEY = process.env.NODE_ENV === 'production'
? 'shorthands'
: 'shorthands';
/* ___filename___: src/deps/env/dev.js */
/* istanbul ignore next: @build */
/**
* @desc for exporting SMALLER builds
* @memberOf env
* @since 3.0.0
* @category Build
* @type {boolean}
*/
var dev = process.env.NODE_ENV !== 'production';
/* ___filename___: src/deps/env/debug.js */
/**
* @desc for exporting `debugger` versions, for easy debugging & verbose logs
* @memberOf env
* @since 4.0.0
* @category Build
* @type {boolean}
*/
var debug = process.env.NODE_ENV === 'debug'; // || process.env.DEBUG = true
/* ___filename___: src/deps/symbols/iterator.js */
var iterator = Symbol.iterator;
// typeof Symbol !== 'undefined'
// ? Symbol.iterator
// : '@@iterator'
/* ___filename___: src/deps/symbols/instance.js */
var instance = Symbol.hasInstance;
/* ___filename___: src/deps/symbols/primitive.js */
var primitive = Symbol.toPrimitive;
/* ___filename___: src/deps/is/null.js */
/**
* @param {*} x value
* @return {boolean} isNull
*
* @since 3.0.0
* @memberOf is
*
* @func
* @name isNull
*
* {@link https://nodejs.org/api/util.html#util_util_isnull_object node-util-isnull}
* @see {@link node-util-isnull}
*
* @example
*
* isNull(null)
* //=> true
*
* isNull(undefined)
* //=> false
* isNull(void 0)
* //=> false
* isNull({})
* //=> false
* isNull('')
* //=> false
* isNull(1)
* //=> false
*
*/
var _null = x => x === null;
/* ___filename___: src/deps/is/null.js */
/* ___filename___: src/deps/is/undefined.js */
/* ___filename___: src/deps/is/nullOrUndefined.js */
/**
* @desc Checks if `value` is `null` or `undefined`.
* @since 4.0.0-alpha.1
* @memberOf is
*
* @param {*} x value
* @return {boolean} isNullOrUndefined
*
* @name isNullOrUndefined
* @alias isNill
* @alias isNil
*
* @func
* @category Lang
*
* {@link https://github.com/gcanti/tcomb/blob/master/lib/isNil.js tcomb-isnill}
* {@link http://ramdajs.com/docs/#isNil ramda-isnill}
* {@link https://github.com/infernojs/inferno/blob/master/packages/inferno-shared/src/index.ts#L23 inferno-isnullorundefined}
* {@link https://nodejs.org/api/util.html#util_util_isnullorundefined_object node-util-isnullorundefined}
* @see {@link inferno-isnullorundefined}
* @see {@link ramda-isnil}
* @see {@link tcomb-isnil}
* @see {@link node-util-isnullorundefined}
* @see is/null
* @see is/undefined
*
* @example
*
* isNullOrUndefined(null)
* //=> true
* isNullOrUndefined(undefined)
* //=> true
* isNullOrUndefined(void 0)
* //=> true
*
* isNullOrUndefined(NaN)
* //=> false
* isNullOrUndefined({})
* //=> false
* isNullOrUndefined('')
* //=> false
* isNullOrUndefined(1)
* //=> false
* isNullOrUndefined(false)
* //=> false
*
*/
var nullOrUndefined = function isNullOrUndef(x) {
return _undefined(x) || _null(x)
};
/* ___filename___: src/deps/is/nullOrUndefined.js */
/* ___filename___: src/deps/is/prototypeOf.js */
const isPrototypeOf = Object.prototype.isPrototypeOf;
/**
* check if arg 1 is prototype of arg 2
*
* @TODO curry2
* @memberOf is
* @name isPrototypeOf
* @since 3.0.0
*
* @param {Object | *} haystack check needle against
* @param {Object | *} needle is prototype of haystack
* @return {boolean} needle isPrototypeOf haystack
*
* {@link https://tc39.github.io/ecma262/#sec-object.prototype.isprototypeof emca-is-prototype-of}
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf mozilla-obj-isprototypeof}
* @see {@link mozilla-obj-isprototypeof}
* @see {@link emca-is-prototype-of}
*
* @example
*
* class Eh extends Function {}
* class Canada extends Eh {}
* isPrototypeOf(Eh, Function) //=> true
* isPrototypeOf(Canada, Function) //=> true
* isPrototypeOf(Eh, Date) //=> false
*
* isPrototypeOf({}, Object) //=> true
* isPrototypeOf({}, Array) //=> false
*
*/
var prototypeOf = (haystack, needle) =>
!nullOrUndefined(haystack) && isPrototypeOf.call(haystack, needle);
/* ___filename___: src/deps/fp/isPlaceholder.js */
var isPlaceholder = function _isPlaceholder(x) {
return x === '_'
};
/* ___filename___: src/deps/fp/arity.js */
/* eslint complexity: "OFF" */
/* eslint consistent-return: "OFF" */
/* eslint max-len: "OFF" */
/* eslint no-unused-vars: "OFF" */
/* istanbul ignore next: metadata, one is covered, all are covered */
/* prettier-ignore */
/**
* @desc just for `.length` of a function, to know how many args
* @memberOf fp
*
* @since 5.0.0
* @param {number} n number of arguments
* @param {Function} fn function to wrap
* @return {Function} function with params
*
* @tests fp/arity
*
* {@link https://github.com/blakeembrey/nary nary}
* {@link https://www.npmjs.com/package/util-arity util-arity}
* {@link https://docs.microsoft.com/en-us/scripting/javascript/reference/length-property-function-javascript microsoft-func-length}
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/arity mozilla-func-arity}
* @see {@link mozilla-func-arity}
* @see {@link microsoft-func-length}
* @see {@link util-arity}
* @see {@link nary}
*
* @NOTE keeping this means uglify `keep_func_args: false`
*
* @example
*
* const wan = one => console.log(one)
* arity(1, wan)
* => function(one => wan(one))
*
* const five = ($1, $2, $3, $4, $5) => console.log.apply(console, arguments)
* arity(5, five).length
* //=> 5
*
*/
var arity = function _arity(n, fn) {
// if (n === 0 || n > 5)
if (n === 1) return function($0) { return fn.apply(this, arguments) }
else if (n === 2) return function($0, $1) { return fn.apply(this, arguments) }
else if (n === 3) return function($0, $1, $2) { return fn.apply(this, arguments) }
else if (n === 4) return function($0, $1, $2, $3) { return fn.apply(this, arguments) }
else if (n === 5) return function($0, $1, $2, $3, $4) { return fn.apply(this, arguments) }
else return function() { return fn.apply(this, arguments) }
// @NOTE ignoring
// else if (n === 6) return function(a0, a1, a2, a3, a4, a5) { return fn.apply(this, arguments) }
// else if (n === 7) return function(a0, a1, a2, a3, a4, a5, a6) { return fn.apply(this, arguments) }
// else if (n === 8) return function(a0, a1, a2, a3, a4, a5, a6, a7) { return fn.apply(this, arguments) }
// else if (n === 9) return function(a0, a1, a2, a3, a4, a5, a6, a7, a8) { return fn.apply(this, arguments) }
// else if (n === 10) return function(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { return fn.apply(this, arguments) }
};
/* ___filename___: src/deps/fp/isPlaceholder.js */
/* ___filename___: src/deps/fp/arity.js */
/* ___filename___: src/deps/fp/curry.js */
/**
* Returns a curried equivalent of the provided function, with the specified
* arity. The curried function has two unusual capabilities. First, its
* arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the
* following are equivalent:
*
* - `g(1)(2)(3)`
* - `g(1)(2, 3)`
* - `g(1, 2)(3)`
* - `g(1, 2, 3)`
*
* Secondly, the special placeholder value [`R.__`](#__) may be used to specify
* "gaps", allowing partial application of any combination of arguments,
* regardless of their positions. If `g` is as above and `_` is [`R.__`](#__),
* the following are equivalent:
*
* - `g(1, 2, 3)`
* - `g(_, 2, 3)(1)`
* - `g(_, _, 3)(1)(2)`
* - `g(_, _, 3)(1, 2)`
* - `g(_, 2)(1)(3)`
* - `g(_, 2)(1, 3)`
* - `g(_, 2)(_, 3)(1)`
*
* @alias curryN
* @alias partial
* @since 5.0.0-beta.1
*
* @param {number} length The arity of the curried function.
* @param {Array} received An array of arguments received thus far.
* @param {Function} fn The function to curry.
* @return {Function} A new, curried function.
*
* @func
* @memberOf fp
* @ramda v0.5.0
* @category Function
* @sig Number -> (* -> a) -> (* -> a)
*
* {@link https://github.com/andrewplummer/Sugar/blob/master/lib/function.js#L382 sugar-partial}
* {@link http://documentcloud.github.io/underscore-contrib/#curry underscore-contrib-curry}
* {@link https://github.com/lodash/lodash/blob/master/.internal/composeArgs.js lodash-compose-args}
* {@link https://github.com/jashkenas/underscore/blob/master/underscore.js#L773 underscore-partial}
* {@link https://github.com/ramda/ramda/blob/master/src/uncurryN.js ramda-uncurry}
* {@link https://github.com/ramda/ramda/blob/master/src/curryN.js ramda-curry}
* {@link https://github.com/lodash/lodash/blob/master/curry.js lodash-curry}
* @see {@link ramda-curry}
* @see {@link lodash-curry}
* @see {@link ramda-uncurry}
* @see {@link underscore-partial}
* @see {@link sugar-partial}
*
* @types fp/curry
* @tests fp/curry
*
* @example
*
* var sumArgs = (...args) => R.sum(args);
*
* var curriedAddFourNumbers = R.curryN(4, sumArgs);
* var f = curriedAddFourNumbers(1, 2);
* var g = f(3);
* g(4); //=> 10
*
*/
function _curryN(length, received, fn) {
return function() {
const combined = [];
let argsIdx = 0;
let left = length;
let combinedIdx = 0;
while (combinedIdx < received.length || argsIdx < arguments.length) {
let result;
if (
combinedIdx < received.length &&
(!isPlaceholder(received[combinedIdx]) || argsIdx >= arguments.length)
) {
result = received[combinedIdx];
}
else {
result = arguments[argsIdx++];
// argsIdx += 1
}
combined[combinedIdx++] = result;
if (!isPlaceholder(result)) {
left -= 1;
}
// combinedIdx += 1
}
return left <= 0
? fn.apply(this, combined)
: arity(left, _curryN(length, combined, fn))
}
}
/**
* Returns a curried equivalent of the provided function, with the specified
* arity. The curried function has two unusual capabilities. First, its
* arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the
* following are equivalent:
*
* - `g(1)(2)(3)`
* - `g(1)(2, 3)`
* - `g(1, 2)(3)`
* - `g(1, 2, 3)`
*
* Secondly, the special placeholder value [`R.__`](#__) may be used to specify
* "gaps", allowing partial application of any combination of arguments,
* regardless of their positions. If `g` is as above and `_` is [`R.__`](#__),
* the following are equivalent:
*
* - `g(1, 2, 3)`
* - `g(_, 2, 3)(1)`
* - `g(_, _, 3)(1)(2)`
* - `g(_, _, 3)(1, 2)`
* - `g(_, 2)(1)(3)`
* - `g(_, 2)(1, 3)`
* - `g(_, 2)(_, 3)(1)`
*
* @func
* @memberOf fp
* @since v0.5.0
* @category Function
* @sig Number -> (* -> a) -> (* -> a)
*
* @param {number} length The arity for the returned function.
* @param {Function} fn The function to curry.
* @return {Function} A new, curried function.
*
* @see ramda
*
* @example
*
* var sumArgs = (...args) => R.sum(args);
*
* var curriedAddFourNumbers = R.curryN(4, sumArgs);
* var f = curriedAddFourNumbers(1, 2);
* var g = f(3);
* g(4); //=> 10
*
*/
var curry = function curryN(length, fn) {
return arity(length, _curryN(length, [], fn))
};
/* ___filename___: src/deps/cast/toObj.js */
/**
* cast to object, instead of throwing (like in the spec), returns {} if nill
* @since 5.0.0-beta.6
* @memberOf cast
*
* @name toObj
* @alias toObject
*
* @param {*} x cast to object
* @return {Object} Object(x) || {}
*
* {@link http://ecma-international.org/ecma-262/7.0/#sec-toobject emca-toobject}
* {@link https://github.com/jashkenas/underscore/blob/master/underscore.js#L637 underscore-to-object}
* @see {@link underscore-to-object}
* @see {@link emca-toobject}
*
* @example
*
* toObj(null) //=> {}
*
* @example
*
* var obj = {eh: true}
* var objected = toObj(obj)
* obj === objected //=> true
*
*/
var toObj = function toObj(x) {
// @NOTE this is spec, but IMO, better to return false, or empty obj
// if (x === null || x === undefined) {
// throw new TypeError('Null or undefined passed to ToObject')
// }
// if (isNil(x)) return {}
// else return Object(x)
return Object(x)
};
/* ___filename___: src/deps/cast/toObj.js */
/* ___filename___: src/deps/is/in.js */
/**
* @desc prop is in Object(obj)
* @since 5.0.0
* @memberOf is
*
* @param {Object} obj object to check property of
* @param {Primitive} prop property in obj
* @return {boolean} property
*
* @func
* @type {Function}
* @name isIn
*
* @example
*
* isIn({eh: true}, 'eh') //=> true
* isIn({eh: true}, 'oh') //=> false
*
*/
var _in = (obj, prop) => (prop in toObj(obj));
// @TODO
// function isIn(set) {
// return function(d) {
// return !set ? false
// : set.indexOf ? ~set.indexOf(d)
// : d in set
// }
// }
/* ___filename___: src/deps/is/in.js */
/* ___filename___: src/deps/is/hasIn.js */
/**
* @TODO can depreciate now that there is safety in `isIn`
*
* @desc isIn, but first checks it is not null
* @since 5.0.0
* @memberOf is
*
* @param {Object} obj object to check
* @param {any} prop property to check in object
* @return {boolean}
*
* {@link https://github.com/jashkenas/underscore/blob/master/underscore.js#L1367 underscore-has}
* @see {@link underscore-has}
*
* @extends isNull
* @extends isIn
*
* @example
*
* hasIn({}, 'eh') //=> false
* hasIn(null, 'eh') //=> false
* hasIn({eh: true}, 'eh') //=> true
*
*/
function hasIn(obj, prop) {
return !_null(obj) && _in(obj, prop)
}
var hasIn_1 = hasIn;
/* ___filename___: src/deps/is/function.js */
/**
* Checks if `value` is classified as a `Function` object.
* @memberOf is
* @since 3.0.0
*
* @param {*} x The value to check.
* @return {boolean} x isFunction
*
* @category Lang
* @func isFunction
*
* @NOTE || x instanceof Function
*
* @polyfill safari=9
* The use of `Object#toString` avoids issues with the `typeof` operator
* in Safari 9 which returns 'object' for typed arrays and other constructors.
* there is no polyfill for this
* https://github.com/krambuhl/custom-event-polyfill/issues/2
* browser usage is < 0.3%, very edge case
*
* {@link https://github.com/gcanti/tcomb/blob/master/lib/isFunction.js tcomb-isfunction}
* {@link https://nodejs.org/api/util.html#util_util_isfunction_object node-util-is-function}
* {@link https://github.com/ramda/ramda/blob/master/src/internal/_isFunction.js ramda-is-function}
* {@link https://github.com/lodash/lodash/blob/master/functions.js#L22 lodash-is-function}
* {@link https://github.com/infernojs/inferno/blob/master/packages/inferno-shared/src/index.ts#L38 inferno-is-function}
* {@link https://github.com/js-data/js-data/blob/v2/src/utils.js#L77 js-data-is-function}
* {@link http://underscorejs.org/docs/underscore.html#section-141 underscore-is-function}
* @see {@link tcomb-is-function}
* @see {@link underscore-is-function}
* @see {@link js-data-is-function}
* @see {@link inferno-is-function}
* @see {@link lodash-is-function}
* @see {@link ramda-is-function}
* @see {@link node-util-is-function}
*
* @example
*
* isFunction(function() {})
* //=> true
* isFunction(() => {})
* //=> true
* isFunction(new Function())
* //=> true
*
* isFunction(1)
* //=> false
* isFunction('')
* //=> false
* isFunction(/abc/)
* //=> false
*
*/
var _function = function isFunction(x) {
return typeof x === 'function'
};
/* ___filename___: src/deps/fp/curry.js */
/* ___filename___: src/deps/is/hasIn.js */
/* ___filename___: src/deps/is/function.js */
/* ___filename___: src/deps/fp/invoke.js */
/* eslint consistent-return: "OFF" */
/**
* Creates a function that invokes the method at `path` of a given object.
* Any additional arguments are provided to the invoked method.
*
* @name invoke
* @alias method
* @alias callMethod
* @curried 3
*
* @NOTE basically this is `invoker` but not curried
*
* @since 5.0.0-beta.4
* @lodash 3.7.0
* @category Util
*
* @param {Array|string} path The path of the method to invoke.
* @param {Array} [args] The arguments to invoke the method with.
* @returns {Function} Returns the new invoker function.
*
* @see https://github.com/emberjs/ember.js/blob/master/packages/ember-utils/lib/invoke.js
* @see https://github.com/wycats/handlebars.js/blob/master/lib/handlebars/runtime.js#L38
* @see https://github.com/lodash/lodash/blob/master/method.js
*
* @example
*
* const objects = [
* { 'a': { 'b': () => 2 } },
* { 'a': { 'b': () => 1 } }
* ]
*
* map(objects, method('a.b'))
* //=> [2, 1]
*
* map(objects, method(['a', 'b']))
* //=> [2, 1]
*
*/
/**
* @desc call a method when it exists
* @since 5.0.0-beta.4
* @memberOf fp
* @symb 📞
*
* @param {*} x object
* @param {*} key property with method
* @param {*} args arguments
* @return {*}
*
* @TODO add `path` calling, fallback to noop
* @see is/hasIn
*
* {@link https://github.com/jashkenas/underscore/blob/master/underscore.js#L294 underscore-invoke}
* {@link https://github.com/lodash/lodash/blob/master/invoke.js lodash-invoke}
* @see {@link lodash-invoke}
* @see {@link underscore-invoke}
*
* @example
*
* var obj = {eh: console.log}
* invoke(obj, 'eh', 'eh!')
* //=> console.log('eh!')
*
* var getTag = invoke(Object.prototype.toString, 'call')
* getTag([])
* //=> '[object Array]'
*
*/
function invoke(x, key, args) {
if (hasIn_1(x, key) && _function(x[key])) return x[key](args)
// else return void 0
}
var invoke_1 = curry(3, invoke);
/* ___filename___: src/deps/native/objectToString.js */
var objectToString = Object.prototype.toString;
/* ___filename___: src/deps/fp/invoke.js */
/* ___filename___: src/deps/native/objectToString.js */
/* ___filename___: src/deps/is/toS.js */
/**
* The base implementation of `getTag` without fallbacks for buggy environments.
*
* @memberOf is
* @since 3.0.0
* @alias getTag
* @alias toStringTag
* @alias toS
*
* @param {*} obj The value to `Object.prototype.toString.call(obj)`.
* @return {string} Returns the `toStringTag`.
*
* @see https://github.com/lodash/lodash/blob/master/.internal/baseGetTag.js
* @see https://github.com/jonschlinkert/kind-of
* @see https://github.com/substack/js-traverse/blob/master/index.js#L285
* @see http://luxiyalu.com/object-prototype-tostring-call/
*
* @TODO obj[Symbol.toStringTag]
* @TODO run deopt check on this invoking see how many invocations... are needed to inline
*
* @example
*
* toS({})
* //=> '[object Object]'
*
* toS(function() {})
* //=> '[Object Function]'
*
* getTag([])
* //=> '[object Array]'
*
*/
// module.exports = obj => objectToString.call(obj)
var toS = invoke_1(objectToString, 'call');
/* ___filename___: src/deps/is/toS.js */
/* ___filename___: src/deps/is/map.js */
/**
* @desc Checks if `value` is classified as a `Map` object.
* @since 3.0.0
* @memberOf is
*
* @param {*} x value
* @return {boolean} isMap
*
* @func
* @name isMap
*
* {@link https://github.com/mobxjs/mobx/blob/master/src/utils/utils.ts#L210 mobx-is-map}
* {@link https://github.com/jonschlinkert/kind-of kind-of}
* @see {@link kind-of}
* @see {@link mobx-is-map}
*
* @example
*
* isMap(new Map())
* //=> true
* isMap(new Map.entries())
* //=> false
* isMap(new Set())
* //=> false
* isMap({})
* //=> false
* isMap('')
* //=> false
* isMap(1)
* //=> false
* isMap(new WeakMap)
* //=> false
*
* @example
*
* const e = {}
* eh[Symbol.toStringTag] = '[object Map]'
* isMap(eh)
*
* @example
*
* class Eh extends Map()
* isMap(new Eh())
* //=> true
*
*/
var map = function isMap(x) {
// return x instanceof Map ||
return toS(x) === '[object Map]'
};
/* ___filename___: src/deps/is/set.js */
/**
* Checks if `value` is classified as a `Set` object.
*
* @since 4.3.0
* @category Lang
* @param {*} x The value to check.
* @return {boolean} Returns `true` if `value` is a set, else `false`.
*
* @TODO map[Symbol.species] === Set
*
* @example
*
* isSet(new Set)
* //=> true
*
* isSet(new WeakSet)
* //=> false
*
*/
var set = function isSet(x) {
// return x instanceof Set || toS(x) === '[object Set]'
return toS(x) === '[object Set]'
};
// x instanceof Set ||
/* ___filename___: src/deps/is/stringPrimitive.js */
/**
* Checks if `value` is classified as a `String` **primitive**.
*
* @since 3.0.0
* @category Lang
* @memberOf is
* @param {*} x The value to check.
* @returns {boolean} Returns `true` if `value` is a string, else `false`.
*
* @see https://github.com/canjs/can-util/blob/master/js/is-string/is-string.js
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
* @see https://github.com/lodash/lodash/blob/master/isString.js
* @see is/string
*
* @example
*
* isString('abc')
* //=> true
*
* isString(new String('abc'))
* //=> false
*
* isString(1)
* //=> false
*/
var stringPrimitive = x => typeof x === 'string';
/* ___filename___: src/deps/is/stringPrimitive.js */
/* ___filename___: src/deps/is/string.js */
/**
* Checks if `value` is classified as a `String` primitive or object.
*
* @name isString
* @since 3.0.0
* @category Lang
*
* @memberOf is
* @extends isStringPrimitive
* @variation also allows String objects
*
* @param {*} x The value to check.
* @return {boolean} Returns `true` if `value` is a string, else `false`.
*
* {@link https://nodejs.org/api/util.html#util_util_isstring_object node-util-isstring}
* {@link https://github.com/jashkenas/underscore/blob/master/underscore.js#L1318 underscore-isstring}
* {@link https://github.com/infernojs/inferno/blob/master/packages/inferno-shared/src/index.ts#L42 inferno-isstring}
* {@link https://github.com/ramda/ramda/blob/master/src/internal/_isString.js ramda-is-string}
* {@link https://github.com/js-data/js-data/blob/v2/src/utils.js#L57 js-data-is-string}
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String mozilla-string}
* {@link https://github.com/lodash/lodash/blob/master/isString.js lodash-isString}
* @see {@link lodash-isString}
* @see {@link mozilla-string}
* @see {@link js-data-is-string}
* @see {@link ramda-is-string}
* @see {@link inferno-isstring}
* @see {@link underscore-isstring}
* @see {@link node-util-isstring}
* @see isStringPrimitive
*
* @example
*
* isString('abc')
* //=> true
*
* isString(new String('abc'))
* //=> true
*
* isString(1)
* //=> false
*
*/
var string = x => stringPrimitive(x) || toS(x) === '[object String]';
/* ___filename___: src/deps/is/false.js */
/**
* @param {*} x value
* @return {boolean} isFalse
*
* @since 4.0.0-alpha.1
* @memberOf is
* @func isFalse
*
* @example
*
* isFalse(false)
* //=> true
* isFalse(true)
* //=> false
* isFalse(0)
* //=> false
* isFalse('')
* //=> false
*
*/
var _false = function isFalse(x) {
return x === false
};
/* ___filename___: src/deps/native/objectHasOwnProperty.js */
/**
* Used to check objects for own properties.
* @type {Function}
* @throws
*/
var objectHasOwnProperty = Object.prototype.hasOwnProperty;
/* ___filename___: src/deps/native/objectHasOwnProperty.js */
/* ___filename___: src/deps/util/hasOwnProperty.js */
/**
* @desc hasOwnProperty, first checking !nill
* @since 3.0.0
* @memberOf util
* @alias has
*
* @param {Object | *} haystack object
* @param {string | *} needle property
* @return {boolean} haystack != null & haystack[needle]
*
* {@link https://github.com/ramda/ramda/blob/v0.24.1/src/internal/_has.js ramda-has}
* @see {@link ramda-has}
*
* @example
*
* hasOwnPropertyNotNill({eh: true}, 'eh') //=> true
* hasOwnPropertyNotNill({eh: true}, 'nope') //=> false
*
*/
const hasOwnPropertyNotNill = (haystack, needle) =>
!nullOrUndefined(haystack) && objectHasOwnProperty.call(haystack, needle);
var hasOwnProperty_1 = curry(2, hasOwnPropertyNotNill);
// function(obj, key) {
// return key in obj
// }
/* ___filename___: src/deps/util/hasOwnProperty.js */
/* ___filename___: src/deps/is/ownPropertyIs.js */
/**
* @desc if it has own property, call fnIs(value), else false
* @curried 3
* @name ownPropertyIs
* @alias ownPropertySatisfies
*
* @param {string|Array<string>} propertyPath (@TODO later, lensish)
* @param {Function} fnIs (obj[path]): boolean
* @param {Object} obj object to check
* @return {boolean} hasOwnProperty && fnIs
*
* @see util/hasOwnProperty
* @see fp/curry
* @see is/_core
*
* @TODO add just getting the value of the property, as a param option
* @TODO example
* @TODO use path here too when needed
*/
var ownPropertyIs = curry(3, function ownPropertyIs(propertyPath, fnIs, obj) {
return hasOwnProperty_1(obj, propertyPath)
? fnIs(obj[propertyPath])
: false
});
/* ___filename___: src/deps/util/noop.js */
/**
* @name noop
*
* @memberOf util
* @func
* @since 5.0.0
* @return {void}
*
* {@link https://github.com/sindresorhus/noop3 noop3}
* @see {@link noop3}
*
* @example
*
* noop
*
* @example
*
* noop()
*
*/
var noop = function noop() { /* noop */ };
/* ___filename___: src/deps/util/keys.js */
var keys = Object.keys;
// ENV_COMPAT: // https://github.com/ramda/ramda/blob/master/src/keys.js
/* ___filename___: src/deps/util/assign.js */
/* ___filename___: src/deps/util/define.js */
/**
* @desc default to configurable and enumerable, unless configured otherwise
* @since 4.0.0
* @memberOf util
*
* @param {Object} obj object to define on
* @param {Primitive} name property name to define
* @param {Object} descriptor object descriptor
* @return {void}
*
* @tutorial https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
*
* @example
*
* var desc = Object.getOwnPropertyDescriptor(obj, 'eh', {get: () => console.log('eh')})
*
*/
var define = function(obj, name, descriptor) {
Object.defineProperty(
obj,
name,
assign(
{
configurable: true,
enumerable: true,
},
descriptor
)
);
};
/* ___filename___: src/deps/meta/ignored.js */
var ignored = key =>
key === 'parent' || key === 'store' || key === 'meta' || key === 'className';
// key === 'decorated' ||
// key === 'transformers' ||
// key === 'inspect' ||
/* ___filename___: src/deps/util/from.js */
/**
* @memberOf util
* @tutorial https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from
* @see cast/toArray
*/
var from = Array.from;
/* ___filename___: src/deps/cast/keyValueToIterator.js */
/**
* @name keyValueToIterator
* @since 5.0.0-beta.6
*
* @param {Array<number | string>} keys array of keys
* @param {Array<*>} values array of values
* @param {number} size length/size
* @return {Iterator}
*
* @NOTE isSet(map) ? preAllocate(size) : map.keys() <- works, but too monomorphic
* @TODO could do prepack-style and have returned object reused?
*
* {@link https://tc39.github.io/ecma262/#sec-operations-on-iterator-objects emca-iterator-operations}
* {@link https://github.com/facebook/immutable-js/blob/master/src/Iterator.js#L19 immutable-js-iterator}
* @see {@link immutable-js-iterator}
* @see {@link emca-iterator-operations}
*
* @example
*
* keyValueToIterator([0, 1], ['one', 'two'], 2)
* //=> {value: [0, 'one'], done: false, i: 0}
* //=> {value: [1, 'two'], done: false, i: 1}
* //=> {value: undefined, done: true, i: 2}
*
*/
var keyValueToIterator = function keyValueToIterator(keys, values, size) {
return {
i: 0,
next() {
let i = this.i;
let key = i;
const val = values[i];
key = keys[i];
// done - no more values, or iteration reached size
if ((_undefined(key) && _undefined(val)) || size <= i) {
return {value: undefined, done: true}
}
this.i++;
// return
return {value: [key, val], done: false}
},
}
};
/* ___filename___: src/deps/native/LARGE_ARRAY_SIZE.js */
/**
* @desc Used as the size to enable large array optimizations.
* @name LARGE_ARRAY_SIZE
* @since 5.0.0-beta.6
* @type {number}
* @see array/preAllocate
*/
var LARGE_ARRAY_SIZE = 200;
/* ___filename___: src/deps/is/numberPrimitive.js */
/**
* @desc typeof x === number
* @since 3.0.0
* @memberOf is
*
* @param {*} x value to check
* @return {boolean} isNumberPrimitive
*
* @func
* @name isNumberPrimitive
* @see is/real
*
* @example
*
* isNumberPrimitive(1) //=> true
* isNumberPrimitive(Number(1)) //=> true
* isNumberPrimitive(NaN) //=> true
* isNumberPrimitive(new Number(1)) //=> false
*
* isNumberPrimitive(null) //=> false
* isNumberPrimitive(undefined) //=> false
* isNumberPrimitive(void 0) //=> false
* isNumberPrimitive({}) //=> false
* isNumberPrimitive('') //=> false
* isNumberPrimitive(false) //=> false
*
*/
var numberPrimitive = x => typeof x === 'number';
/* ___filename___: src/deps/is/array.js */
/**
* @name isArray
* @memberOf is
* @since 3.0.0
*
* {@link https://tc39.github.io/ecma262/#sec-isarray emca-isarray}
* {@link https://github.com/gcanti/tcomb/blob/master/lib/isArray.js tcomb-isarray}
* {@link https://nodejs.org/api/util.html#util_util_isarray_object node-util-isarray}
* {@link https://github.com/infernojs/inferno/blob/master/packages/inferno-shared/src/index.ts#L16 inferno-is-array}
* {@link https://github.com/jashkenas/underscore/blob/master/underscore.js#L1308 underscore-is-array}
* {@link https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray mozilla-isarray}
* {@link https://github.com/facebook/immutable-js/blob/master/src/utils/isArrayLike.js immutables-is-array-like}
*
* @param {Array | *} arg
* @return {boolean} isArray(arg)
*
* @func
* @type {Function}
*
* @see is/arrayLike
* @see {@link emca-isarray}
* @see {@link mozilla-isarray}
* @see {@link underscore-is-array}
* @see {@link tcomb-isarray}
* @see {@link immutables-is-array-like}
* @see {@link inferno-is-array}
* @see {@link node-util-isarray}
*
*/
var array = Array.isArray;
// function isArray(xs) {
// return Object.prototype.toString.call(xs) === '[object Array]'
// }
/* ___filename___: src/deps/native/MAX_ARRAY_LENGTH.js */
/**
* @desc Used as references for the maximum length and index of an array.
* @name MAX_ARRAY_LENGTH
* @type {number}
*/
var MAX_ARRAY_LENGTH = 4294967295;
/* ___filename___: src/deps/is/numberPrimitive.js */
/* ___filename___: src/deps/is/number.js */
/**
* @since 3.0.0
* @memberOf is
*
* @param {*} x value
* @return {boolean} isNumber
*
* @func
* @name isNumber
* @extends numberPrimitive
* @variation also returns true for new Number object
*
* {@link https://github.com/infernojs/inferno/blob/master/packages/inferno-shared/src/index.ts#L23 inferno-isnumber}
* {@link http://stackoverflow.com/questions/18082/validate-decimal-numbers-in-javascript-isnumeric stack-overflow-isnumber}
* {@link https://github.com/gcanti/tcomb/blob/master/lib/isNumber.js tcomb-isnumber}
* @see {@link stack-overflow-isnumber}
* @see {@link tcomb-isnumber}
* @see {@link inferno-isnumber}
* @see is/real
*
* @alternate !isNaN(parseFloat(n)) && isFinite(n)
*
* @example
*
* isNumber(1)
* //=> true
* isNumber(new Number(1))
* //=> true
* isNumber(Number(1))
* //=> true
* isNumber(NaN)
* //=> true
*
* isNumber(null)
* //=> false
* isNumber(undefined)
* //=> false
* isNumber(void 0)
* //=> false
* isNumber({})
* //=> false
* isNumber('')
* //=> false
* isNumber(false)
* //=> false
*
*/
var number = x => numberPrimitive(x) || toS(x) === '[object Number]';
/* ___filename___: src/deps/is/number.js */
/* ___filename___: src/deps/is/NaN.js */
/**
* Checks if `value` is `NaN`
* @category Lang
* @memberOf is
* @since 5.0.0-beta.5
*
* @param {*} x The value to check.
* @return {boolean} x isNaN
*
* @name isNaN
* @alias isNotNumber
* @alias isNotEhNumber
*
* {@link https://tc39.github.io/ecma262/#sec-isnan-number emca-isnan}
* {@link https://github.com/lodash/lodash/tree/npm-packages/lodash.isnan lodash-isnan}
* {@link https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/isNaN mozilla-isnan}
* {@link https://github.com/jashkenas/underscore/blob/master/underscore.js#L1347 underscore-is-nan}
* @see {@link emca-isnan}
* @see {@link mozilla-isnan}
* @see {@link underscore-is-nan}
* @see {@link lodash-isnan}
* @see is/number
* @see is/real
*
* @example
*
* isNaN(Number(null)) //=> true
* isNaN(NaN) //=> true
*
* isNaN(0) //=> false
* isNaN(Number(100)) //=> false
*
*/
var _NaN = function isNaN(x) {
return number(x) && Number.isNaN(x)
};
/* ___filename___: src/deps/cast/toNumber.js */
// const isBoolean = require('../is/boolean')
// const isObj = require('../is/objNotNull')
// const isArray = require('../is/array')
// const isNumberish = require('../is/numberish')
// const SymbolPrimitive = require('../symbols/primitive')
// const hasOwnProperty = require('../util/hasOwnProperty')
/**
* @since 5.0.0-beta.6
* @memberOf cast
*
* @name toNumber
* @alias toNum
* @aka ToNumber
*
* @param {*} x number to cast to primitive number
* @return {number} +x
*
* {@link http://2ality.com/2012/04/number-encoding.html number-encoding-js}
* {@link http://speakingjs.com/es5/ch11.html speaking-js-numbers}
* {@link https://coderwall.com/p/5tlhmw/converting-strings-to-number-in-javascript-pitfalls coderwal-to-number}
* {@link http://ecma-international.org/ecma-262/7.0/#sec-tonumber emca-to-number}
* @see {@link emca-to-number}
* @see {@link coderwal-to-number}
* @see {@link speaking-js-numbers}
* @see {@link number-encoding-js}
*
* @TODO make this `toNumberPrimitive` while others could convert as codes
*
*
* @example
*
* toNumber('')
* //=> 0
* toNumber(' ')
* //=> 0
* toNumber('eh')
* //=> NaN
* toNumber('1')
* //=> 1
* toNumber(null)
* //=> 0
* toNumber(true)
* //=> 1
* toNumber(false)
* //=> 0
* toNumber('00')
* //=> 0
* toNumber(undefined)
* //=> NaN
* toNumber({})
* //=> NaN
* toNumber([])
* //=> 0
* toNumber([100, 200])
* //=> NaN
*
* @example
*
* var eh = {Symbol.toPrimitive: hint => hint === 'number' ? 100 : 'eh'}
* toNumber(eh)
* //=> 100
*
*/
function toNumber(x) {
// @NOTE
// if (isNumberish(x) || isBoolean(x)) {
// return +x
// }
// else if (isObj(x)) {
// if (hasOwnProperty(x, SymbolPrimitive)) return x[SymbolPrimitive]('number')
// else if (isArray(x)) return +x
// // this keeps it consistent with array?
// else return 0
// }
return +x
// @TODO
// +x || 0
//
// , coerceNaN = true
// const number = +x
// return isNotEhNumber(x) ? 0 : x
}
var toNumber_1 = toNumber;
/* ___filename___: src/deps/is/NaN.js */
/* ___filename___: src/deps/cast/toNumber.js */
/* ___filename___: src/deps/cast/toInteger.js */
/**
* @name toInteger
* @alias toInt
*
* @since 5.0.0-beta.6
* @memberOf cast
*
* @param {*} x anything
* @return {number} Number(x) if x is not nan
*
* {@link https://github.com/andrewplummer/Sugar/blob/master/lib/common.js#L322 sugar-topositiveinteger}
* {@link https://github.com/lodash/lodash/blob/master/toInteger.js lodash-tointeger}
* {@link https://github.com/chriso/validator.js/blob/master/src/lib/toInteger.js validator-tointeger}
* {@link https://tc39.github.io/ecma262/#sec-tointeger emca-tointeger}
* @see {@link emca-tointeger}
* @see {@link validator-tointeger}
* @see {@link lodash-tointeger}
* @see {@link sugar-topositiveinteger}
* @see cast/number
* @see is/NaN
*
* @example
*
* toInteger(10) // => 10
* toInteger(NaN) // => +0
* toInteger(+Infinity) // => +Infinity
* toInteger('100') // => +100
*
* @example
*
* toInteger(3.2)
* //=> 3
*
* toInteger(Number.MIN_VALUE)
* //=> 0
*
* toInteger(Infinity)
* //=> 1.7976931348623157e+308
*
* toInteger('3.2')
* //=> 3
*
*/
function toInteger(x) {
const number = toNumber_1(x);
if (_NaN(number)) {
return +0
}
else if (number === 0 || number === -Infinity || number === +Infinity) {
return number
}
else {
return Math.sign(number) * Math.floor(Math.abs(number))
}
}
var toInteger_1 = toInteger;
/* ___filename___: src/deps/native/MAX_ARRAY_LENGTH.js */
/* ___filename___: src/deps/cast/toInteger.js */
/* ___filename___: src/deps/cast/toLength.js */
/**
* Converts `value` to an integer suitable for use as the length of an
* array-like object.
*
* **Note:** This method is based on emca-toLength
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
*
* @since 5.0.0-beta.7
* @memberOf cast
*
* @param {*} value The value to convert.
* @return {number} Returns the converted integer.
*
* @fork 4.0.0
* @category Lang
*
* {@link http://ecma-international.org/ecma-262/7.0/#sec-tolength emca-tolength}
* {@link https://github.com/lodash/lodash/blob/master/toLength.js lodash-tolength}
* {@link https://github.com/jashkenas/underscore/blob/master/underscore.js#L159 underscore-tolength}
* @see {@link underscore-tolength}
* @see {@link lodash-tolength}
* @see {@link emca-tolength}
*
* @example
*
* toLength(3.2)
* // => 3
*
* toLength(Number.MIN_VALUE)
* // => 0
*
* toLength(Infinity)
* // => 4294967295
*
* toLength('3.2')
* // => 3
*
*/
function toLength(value) {
value = toInteger_1(value);
if (value < 0) {
return 0
}
// @TODO why nor return 0?
// @TODO if env perf > size?... still, this should
// `goto` the last else, easy math
// else if (value === 0) {
// return value
// }
else if (value > MAX_ARRAY_LENGTH) {
return MAX_ARRAY_LENGTH
}
else {
return value
}
}
var toLength_1 = toLength;
/* ___filename___: src/deps/cast/toLength.js */
/* ___filename___: src/deps/util/size.js */
/* eslint guard-for-in: "OFF" */
/* eslint no-unused-expressions: "OFF" */
/**
* @desc returns .length, .size, or a number with the length from `for in` hasOwn
* @name size
* @memberOf util
* @since 5.0.0-beta.6
*
* @param {Object|Array|Map|*} x value to check length | size
* @return {number} size
*
* {@link http://whereswalden.com/2010/04/06/more-changes-coming-to-spidermonkey-the-magical-__count__-property-of-objects-is-being-removed/ spidermonkey__count__}
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size mozilla-map-size}
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/size mozilla-set-size}
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length mozilla-function-length}
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length mozilla-array-length}
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/length mozilla-arguments-length}
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length mozilla-string-length}
* {@link https://github.com/jashkenas/underscore/blob/master/underscore.js#L476 underscore-size}
* {@link https://github.com/lodash/lodash/blob/master/size.js lodash-size}
* {@link https://stackoverflow.com/questions/31014793/is-lodash-size-faster-than-js-length-property stack-overflow-size}
* @see {@link spidermonkey__count__}
* @see {@link underscore-size}
* @see {@link stack-overflow-size}
* @see {@link lodash-size}
* @see {@link mozilla-string-length}
* @see {@link mozilla-array-length}
* @see {@link mozilla-arguments-length}
* @see {@link mozilla-function-length}
* @see {@link mozilla-set-size}
* @see {@link mozilla-map-size}
*
* @example
* size(new Set([0, 1])) //=> 2
* size(new Map(Object.entries({eh: true}))) //=> 1
* size({eh: 0}) //=> 1
* size({}) //=> 0
* size([]) //=> 0
* size([0, 1, 2]) //=> 3
* size(($1, $2) => {}) //=> 2
* size(() => {}) //=> 0
* size(null) //=> 0
*/
var size = function size(x) {
// --- safety all around
// decision tree, but sadly, bigger size :,-(
if (nullOrUndefined(x)) {
return 0
}
// @NOTE could put `isPrimitive` after the length and size checks...
// but not really needed because look at `toNumber` & +false = 0 etc so
else if (numberPrimitive(x)) {
return toLength_1(x)
}
// --- main checks .length, .size, or for-in
else if (hasIn_1(x, 'length')) {
return x.length
}
else if (hasIn_1(x, 'size')) {
return x.size
}
else {
let count = 0;
for (let property in x) hasOwnProperty_1(x, property) && ++count;
return count
}
};
/* ___filename___: src/deps/util/numberFromZero.js */
/* eslint no-confusing-arrow: "OFF" */
/**
* @desc when number > 1, use number -1
* otherwise, when number == 1, use 0
* default, use number
*
* @memberOf util
* @since 5.0.0-beta.6
* @name numberFromZero
*
* @param {number} x number to start from 0 if over 1
* @return {number} number from 0
*
* @see util/length
* @see util/lengthMinusOne
* @see util/lengthFromZero
*
* @example
*
* lengthFromZero([1]) //=> 1
* lengthFromZero([]) //=> 0
* lengthFromZero([1, 2, 3]) //=> 2
* lengthFromZero({length: -1}) //=> 0
*
*/
var numberFromZero = x =>
// over 1, subtract 1
x > 1
? x - 1
// is 1, use 1, else 0
: x === 1
? 1
: 0;
/* ___filename___: src/deps/native/LARGE_ARRAY_SIZE.js */
/* ___filename___: src/deps/is/array.js */
/* ___filename___: src/deps/util/size.js */
/* ___filename___: src/deps/util/numberFromZero.js */
/* ___filename___: src/deps/array/preAllocate.js */
// const lengthMinusOne = require('../util/lengthMinusOne')
// const lengthFrom0 = require('../util/lengthFromZero')
// @TODO also ensure we coerce this number...?
// @NOTE calls from0 twice but inlined makes less diff than adding pointer
const arrFrom0 = x => new Array(numberFromZero(x) > LARGE_ARRAY_SIZE ? 0 : numberFromZero(x));
/**
* @desc make a new empty Array filled with a pre-allocated-length-from-zero
* @memberOf array
* @name preAllocate
* @since 5.0.0
* @func
*
* @param {Object|Array|number} x array or object to return an empty array.of.fill (pre-allocated)
* @return {Array} preallocated array full of undefined
*
* @TODO not sure about pre-allocating objects?
*
* {@link https://github.com/facebook/react/blob/8f4d30737def9fa3456149826414643b5cbbe4bf/docs/docs/optimizing-performance.md react-opt}
* {@link https://thewayofcode.wordpress.com/tag/array-pre-allocation/ the-way-of-code-array}
* {@link https://www.html5rocks.com/en/tutorials/speed/v8/#toc-topic-numbers html-5-rocks-v8}
* @see {@link html5-rocks-v8}
* @see {@link the-way-of-code-array}
* @see {@link react-opt}
* @see is/numberPrimitive
* @see is/array
* @see util/size
*
* @NOTE could be an `||` but it's annoying how it deopts sometimes (arr checks)
*
* @example
*
* preAllocate({eh: true})
* //=> {}
*
* preAllocate([1, 2, 10])
* //=> [undefined, undefined, undefined]
*
* preAllocate(2)
* //=> [undefined, undefined]
*
*/
var preAllocate = function preAllocate(x) {
// @TODO now that size is better, this can just be...
// return arrFrom0(size(x))
return numberPrimitive(x)
? arrFrom0(x)
: array(x)
? arrFrom0(x.length)
: arrFrom0(size(x))
};
/