From 8453b66b9224c4474f758af4066b5b4bdc13e540 Mon Sep 17 00:00:00 2001 From: toxic-johann <353904974@qq.com> Date: Sat, 1 Jun 2019 23:56:28 +0800 Subject: [PATCH] 0.4.0 --- lib/index.browser.js | 1930 +++++++++++++++++++++++++++++++----------- lib/index.js | 26 +- lib/index.min.js | 2 +- lib/index.mjs | 24 +- package.json | 2 +- 5 files changed, 1455 insertions(+), 529 deletions(-) diff --git a/lib/index.browser.js b/lib/index.browser.js index dee854f..dff0063 100644 --- a/lib/index.browser.js +++ b/lib/index.browser.js @@ -1,508 +1,1444 @@ /** - * toxic-utils v0.3.1 + * toxic-utils v0.4.0 * (c) 2017-2019 toxic-johann * Released under MIT - * Built ad Thu Apr 25 2019 23:19:04 GMT+0800 (China Standard Time) + * Built ad Sat Jun 01 2019 23:56:22 GMT+0800 (China Standard Time) */ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : - typeof define === 'function' && define.amd ? define(['exports'], factory) : - (global = global || self, factory(global.toxicUtils = {})); + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = global || self, factory(global.toxicUtils = {})); }(this, function (exports) { 'use strict'; - var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; - - /** Detect free variable `global` from Node.js. */ - var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; - - var _freeGlobal = freeGlobal; - - /** Detect free variable `self`. */ - var freeSelf = typeof self == 'object' && self && self.Object === Object && self; - - /** Used as a reference to the global object. */ - var root = _freeGlobal || freeSelf || Function('return this')(); - - var _root = root; - - /** Built-in value references. */ - var Symbol = _root.Symbol; - - var _Symbol = Symbol; - - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** Used to check objects for own properties. */ - var hasOwnProperty = objectProto.hasOwnProperty; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var nativeObjectToString = objectProto.toString; - - /** Built-in value references. */ - var symToStringTag = _Symbol ? _Symbol.toStringTag : undefined; - - /** - * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. - * - * @private - * @param {*} value The value to query. - * @returns {string} Returns the raw `toStringTag`. - */ - function getRawTag(value) { - var isOwn = hasOwnProperty.call(value, symToStringTag), - tag = value[symToStringTag]; - - try { - value[symToStringTag] = undefined; - var unmasked = true; - } catch (e) {} - - var result = nativeObjectToString.call(value); - if (unmasked) { - if (isOwn) { - value[symToStringTag] = tag; - } else { - delete value[symToStringTag]; - } - } - return result; - } - - var _getRawTag = getRawTag; - - /** Used for built-in method references. */ - var objectProto$1 = Object.prototype; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var nativeObjectToString$1 = objectProto$1.toString; - - /** - * Converts `value` to a string using `Object.prototype.toString`. - * - * @private - * @param {*} value The value to convert. - * @returns {string} Returns the converted string. - */ - function objectToString(value) { - return nativeObjectToString$1.call(value); - } - - var _objectToString = objectToString; - - /** `Object#toString` result references. */ - var nullTag = '[object Null]', - undefinedTag = '[object Undefined]'; - - /** Built-in value references. */ - var symToStringTag$1 = _Symbol ? _Symbol.toStringTag : undefined; - - /** - * The base implementation of `getTag` without fallbacks for buggy environments. - * - * @private - * @param {*} value The value to query. - * @returns {string} Returns the `toStringTag`. - */ - function baseGetTag(value) { - if (value == null) { - return value === undefined ? undefinedTag : nullTag; - } - return (symToStringTag$1 && symToStringTag$1 in Object(value)) - ? _getRawTag(value) - : _objectToString(value); - } - - var _baseGetTag = baseGetTag; - - /** - * Checks if `value` is classified as an `Array` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array, else `false`. - * @example - * - * _.isArray([1, 2, 3]); - * // => true - * - * _.isArray(document.body.children); - * // => false - * - * _.isArray('abc'); - * // => false - * - * _.isArray(_.noop); - * // => false - */ - var isArray = Array.isArray; - - var isArray_1 = isArray; - - /** - * Checks if `value` is object-like. A value is object-like if it's not `null` - * and has a `typeof` result of "object". - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is object-like, else `false`. - * @example - * - * _.isObjectLike({}); - * // => true - * - * _.isObjectLike([1, 2, 3]); - * // => true - * - * _.isObjectLike(_.noop); - * // => false - * - * _.isObjectLike(null); - * // => false - */ - function isObjectLike(value) { - return value != null && typeof value == 'object'; - } - - var isObjectLike_1 = isObjectLike; - - /** `Object#toString` result references. */ - var stringTag = '[object String]'; - - /** - * Checks if `value` is classified as a `String` primitive or object. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a string, else `false`. - * @example - * - * _.isString('abc'); - * // => true - * - * _.isString(1); - * // => false - */ - function isString(value) { - return typeof value == 'string' || - (!isArray_1(value) && isObjectLike_1(value) && _baseGetTag(value) == stringTag); - } - - var isString_1 = isString; - - /** - * Creates a unary function that invokes `func` with its argument transformed. - * - * @private - * @param {Function} func The function to wrap. - * @param {Function} transform The argument transform. - * @returns {Function} Returns the new function. - */ - function overArg(func, transform) { - return function(arg) { - return func(transform(arg)); - }; - } - - var _overArg = overArg; - - /** Built-in value references. */ - var getPrototype = _overArg(Object.getPrototypeOf, Object); - - var _getPrototype = getPrototype; - - /** `Object#toString` result references. */ - var objectTag = '[object Object]'; - - /** Used for built-in method references. */ - var funcProto = Function.prototype, - objectProto$2 = Object.prototype; - - /** Used to resolve the decompiled source of functions. */ - var funcToString = funcProto.toString; - - /** Used to check objects for own properties. */ - var hasOwnProperty$1 = objectProto$2.hasOwnProperty; - - /** Used to infer the `Object` constructor. */ - var objectCtorString = funcToString.call(Object); - - /** - * Checks if `value` is a plain object, that is, an object created by the - * `Object` constructor or one with a `[[Prototype]]` of `null`. - * - * @static - * @memberOf _ - * @since 0.8.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. - * @example - * - * function Foo() { - * this.a = 1; - * } - * - * _.isPlainObject(new Foo); - * // => false - * - * _.isPlainObject([1, 2, 3]); - * // => false - * - * _.isPlainObject({ 'x': 0, 'y': 0 }); - * // => true - * - * _.isPlainObject(Object.create(null)); - * // => true - */ - function isPlainObject(value) { - if (!isObjectLike_1(value) || _baseGetTag(value) != objectTag) { - return false; - } - var proto = _getPrototype(value); - if (proto === null) { - return true; - } - var Ctor = hasOwnProperty$1.call(proto, 'constructor') && proto.constructor; - return typeof Ctor == 'function' && Ctor instanceof Ctor && - funcToString.call(Ctor) == objectCtorString; - } - - var isPlainObject_1 = isPlainObject; - - /** - * Checks if `value` is the - * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) - * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an object, else `false`. - * @example - * - * _.isObject({}); - * // => true - * - * _.isObject([1, 2, 3]); - * // => true - * - * _.isObject(_.noop); - * // => true - * - * _.isObject(null); - * // => false - */ - function isObject(value) { - var type = typeof value; - return value != null && (type == 'object' || type == 'function'); - } - - var isObject_1 = isObject; - - /** - * Checks if `value` is `null` or `undefined`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is nullish, else `false`. - * @example - * - * _.isNil(null); - * // => true - * - * _.isNil(void 0); - * // => true - * - * _.isNil(NaN); - * // => false - */ - function isNil(value) { - return value == null; - } - - var isNil_1 = isNil; - - function genTraversalHandler(fn, setter) { - if (setter === void 0) { - setter = function setter(target, key, value) { - target[key] = value; - }; - } - - function recursiveFn(source, target, key) { - if (isArray_1(source) || isPlainObject_1(source)) { - target = !isObject_1(target) ? isPlainObject_1(source) ? {} : [] : target; - - for (var name_1 in source) { - if (!source.hasOwnProperty(name_1)) { - continue; - } - - setter(target, name_1, recursiveFn(source[name_1], target[name_1], name_1)); - } - - return target; - } - - return fn(source, target, key); - } - - return recursiveFn; - } - var myDeepAssign = genTraversalHandler(function (val) { - return val; - }); - function deepClone(source) { - if (!isObject_1(source)) { - throw new TypeError("deepClone only accept non primitive type"); - } - - return myDeepAssign(source); - } - function deepAssign() { - var args = []; - - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - - if (args.length < 2) { - throw new Error("deepAssign accept two and more argument"); - } - - for (var i = args.length - 1; i > -1; i--) { - if (!isObject_1(args[i])) { - throw new TypeError("deepAssign only accept non primitive type"); - } - } - - var target = args.shift(); - args.forEach(function (source) { - return myDeepAssign(source, target); - }); - return target; - } - function camelize(str, isBig) { - return str.replace(/(^|[^a-zA-Z]+)([a-zA-Z])/g, function (match, spilt, initials, index) { - return !isBig && index === 0 ? initials.toLowerCase() : initials.toUpperCase(); - }); - } - function hypenate(str) { - return camelize(str).replace(/([A-Z])/g, function (match) { - return "-" + match.toLowerCase(); - }); - } - function bind(fn, context) { - if (fn.bind) { - return fn.bind(context); - } else if (fn.apply) { - return function __autobind__() { - var args = []; - - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - - return fn.apply(context, args); - }; - } - - return function __autobind__() { - var args = []; - - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - - return fn.call.apply(fn, [context].concat(args)); - }; - } - function uuid() { - return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4(); - } - function S4() { - return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1); - } - function rand(length) { - var str = ""; - - while (str.length < length) { - str += S4(); - } - - return str.slice(0, length); - } - function getDeepProperty(obj, keys, _a) { - var _b = _a === void 0 ? {} : _a, - _c = _b.throwError, - throwError = _c === void 0 ? false : _c, - backup = _b.backup; - - if (isString_1(keys)) { - keys = keys.split("."); - } - - if (!isArray_1(keys)) { - throw new TypeError("keys of getDeepProperty must be string or Array"); - } - - var read = []; - var target = obj; - - for (var i = 0, len = keys.length; i < len; i++) { - var key = keys[i]; - - if (isNil_1(target)) { - if (throwError) { - throw new Error("obj" + (read.length > 0 ? "." + read.join(".") : " itself") + " is " + target); - } else { - return backup; - } - } - - target = target[key]; - read.push(key); - } - - return target; - } - - exports.S4 = S4; - exports.bind = bind; - exports.camelize = camelize; - exports.deepAssign = deepAssign; - exports.deepClone = deepClone; - exports.genTraversalHandler = genTraversalHandler; - exports.getDeepProperty = getDeepProperty; - exports.hypenate = hypenate; - exports.rand = rand; - exports.uuid = uuid; - - Object.defineProperty(exports, '__esModule', { value: true }); + /** Detect free variable `global` from Node.js. */ + var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; + + /** Detect free variable `self`. */ + var freeSelf = typeof self == 'object' && self && self.Object === Object && self; + + /** Used as a reference to the global object. */ + var root = freeGlobal || freeSelf || Function('return this')(); + + /** Built-in value references. */ + var Symbol = root.Symbol; + + /** Used for built-in method references. */ + var objectProto = Object.prototype; + + /** Used to check objects for own properties. */ + var hasOwnProperty = objectProto.hasOwnProperty; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ + var nativeObjectToString = objectProto.toString; + + /** Built-in value references. */ + var symToStringTag = Symbol ? Symbol.toStringTag : undefined; + + /** + * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the raw `toStringTag`. + */ + function getRawTag(value) { + var isOwn = hasOwnProperty.call(value, symToStringTag), + tag = value[symToStringTag]; + + try { + value[symToStringTag] = undefined; + var unmasked = true; + } catch (e) {} + + var result = nativeObjectToString.call(value); + if (unmasked) { + if (isOwn) { + value[symToStringTag] = tag; + } else { + delete value[symToStringTag]; + } + } + return result; + } + + /** Used for built-in method references. */ + var objectProto$1 = Object.prototype; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ + var nativeObjectToString$1 = objectProto$1.toString; + + /** + * Converts `value` to a string using `Object.prototype.toString`. + * + * @private + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + */ + function objectToString(value) { + return nativeObjectToString$1.call(value); + } + + /** `Object#toString` result references. */ + var nullTag = '[object Null]', + undefinedTag = '[object Undefined]'; + + /** Built-in value references. */ + var symToStringTag$1 = Symbol ? Symbol.toStringTag : undefined; + + /** + * The base implementation of `getTag` without fallbacks for buggy environments. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the `toStringTag`. + */ + function baseGetTag(value) { + if (value == null) { + return value === undefined ? undefinedTag : nullTag; + } + return (symToStringTag$1 && symToStringTag$1 in Object(value)) + ? getRawTag(value) + : objectToString(value); + } + + /** + * Checks if `value` is object-like. A value is object-like if it's not `null` + * and has a `typeof` result of "object". + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is object-like, else `false`. + * @example + * + * _.isObjectLike({}); + * // => true + * + * _.isObjectLike([1, 2, 3]); + * // => true + * + * _.isObjectLike(_.noop); + * // => false + * + * _.isObjectLike(null); + * // => false + */ + function isObjectLike(value) { + return value != null && typeof value == 'object'; + } + + /** + * A specialized version of `_.map` for arrays without support for iteratee + * shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + */ + + /** + * Checks if `value` is classified as an `Array` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array, else `false`. + * @example + * + * _.isArray([1, 2, 3]); + * // => true + * + * _.isArray(document.body.children); + * // => false + * + * _.isArray('abc'); + * // => false + * + * _.isArray(_.noop); + * // => false + */ + var isArray = Array.isArray; + + /** + * Checks if `value` is the + * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) + * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(_.noop); + * // => true + * + * _.isObject(null); + * // => false + */ + function isObject(value) { + var type = typeof value; + return value != null && (type == 'object' || type == 'function'); + } + + /** + * This method returns the first argument it receives. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Util + * @param {*} value Any value. + * @returns {*} Returns `value`. + * @example + * + * var object = { 'a': 1 }; + * + * console.log(_.identity(object) === object); + * // => true + */ + + /** Used for built-in method references. */ + + /** + * Gets the value at `key` of `object`. + * + * @private + * @param {Object} [object] The object to query. + * @param {string} key The key of the property to get. + * @returns {*} Returns the property value. + */ + + /** + * A faster alternative to `Function#apply`, this function invokes `func` + * with the `this` binding of `thisArg` and the arguments of `args`. + * + * @private + * @param {Function} func The function to invoke. + * @param {*} thisArg The `this` binding of `func`. + * @param {Array} args The arguments to invoke `func` with. + * @returns {*} Returns the result of `func`. + */ + + /* Built-in method references for those with the same name as other `lodash` methods. */ + + /* Built-in method references for those with the same name as other `lodash` methods. */ + + /** + * Gets the number of `placeholder` occurrences in `array`. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} placeholder The placeholder to search for. + * @returns {number} Returns the placeholder count. + */ + + /** + * The function whose prototype chain sequence wrappers inherit from. + * + * @private + */ + + /** + * This method returns `undefined`. + * + * @static + * @memberOf _ + * @since 2.3.0 + * @category Util + * @example + * + * _.times(2, _.noop); + * // => [undefined, undefined] + */ + + /** Used to lookup unminified function names. */ + + /** + * Copies the values of `source` to `array`. + * + * @private + * @param {Array} source The array to copy values from. + * @param {Array} [array=[]] The array to copy values to. + * @returns {Array} Returns `array`. + */ + + /** Used to detect hot functions by number of calls within a span of milliseconds. */ + + /** Used to match wrap detail comments. */ + + /** Used to match wrap detail comments. */ + + /** + * Creates a function that returns `value`. + * + * @static + * @memberOf _ + * @since 2.4.0 + * @category Util + * @param {*} value The value to return from the new function. + * @returns {Function} Returns the new constant function. + * @example + * + * var objects = _.times(2, _.constant({ 'a': 1 })); + * + * console.log(objects); + * // => [{ 'a': 1 }, { 'a': 1 }] + * + * console.log(objects[0] === objects[1]); + * // => true + */ + + /** + * A specialized version of `_.forEach` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns `array`. + */ + + /** + * The base implementation of `_.findIndex` and `_.findLastIndex` without + * support for iteratee shorthands. + * + * @private + * @param {Array} array The array to inspect. + * @param {Function} predicate The function invoked per iteration. + * @param {number} fromIndex The index to search from. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + + /** + * The base implementation of `_.isNaN` without support for number objects. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. + */ + + /** + * A specialized version of `_.indexOf` which performs strict equality + * comparisons of values, i.e. `===`. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + + /** + * Gets the argument placeholder value for `func`. + * + * @private + * @param {Function} func The function to inspect. + * @returns {*} Returns the placeholder value. + */ + + /** Used as references for various `Number` constants. */ + + /** Used as the internal argument placeholder. */ + + /** + * Performs a + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * comparison between two values to determine if they are equivalent. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @example + * + * var object = { 'a': 1 }; + * var other = { 'a': 1 }; + * + * _.eq(object, object); + * // => true + * + * _.eq(object, other); + * // => false + * + * _.eq('a', 'a'); + * // => true + * + * _.eq('a', Object('a')); + * // => false + * + * _.eq(NaN, NaN); + * // => true + */ + + /** Used as references for various `Number` constants. */ + + /** Used for built-in method references. */ + + /** + * The base implementation of `_.times` without support for iteratee shorthands + * or max array length checks. + * + * @private + * @param {number} n The number of times to invoke `iteratee`. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the array of results. + */ + + /** + * This method returns `false`. + * + * @static + * @memberOf _ + * @since 4.13.0 + * @category Util + * @returns {boolean} Returns `false`. + * @example + * + * _.times(2, _.stubFalse); + * // => [false, false] + */ + + /** + * The base implementation of `_.unary` without support for storing metadata. + * + * @private + * @param {Function} func The function to cap arguments for. + * @returns {Function} Returns the new capped function. + */ + + /** + * Creates a unary function that invokes `func` with its argument transformed. + * + * @private + * @param {Function} func The function to wrap. + * @param {Function} transform The argument transform. + * @returns {Function} Returns the new function. + */ + function overArg(func, transform) { + return function(arg) { + return func(transform(arg)); + }; + } + + /** + * This function is like + * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) + * except that it includes inherited enumerable properties. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + */ + + /** + * Removes `key` and its value from the hash. + * + * @private + * @name delete + * @memberOf Hash + * @param {Object} hash The hash to modify. + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + + /** + * Removes all key-value entries from the list cache. + * + * @private + * @name clear + * @memberOf ListCache + */ + + /** + * Checks if `value` is suitable for use as unique object key. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is suitable, else `false`. + */ + + /** + * Appends the elements of `values` to `array`. + * + * @private + * @param {Array} array The array to modify. + * @param {Array} values The values to append. + * @returns {Array} Returns `array`. + */ + + /** Built-in value references. */ + var getPrototype = overArg(Object.getPrototypeOf, Object); + + /** `Object#toString` result references. */ + var objectTag = '[object Object]'; + + /** Used for built-in method references. */ + var funcProto = Function.prototype, + objectProto$2 = Object.prototype; + + /** Used to resolve the decompiled source of functions. */ + var funcToString = funcProto.toString; + + /** Used to check objects for own properties. */ + var hasOwnProperty$1 = objectProto$2.hasOwnProperty; + + /** Used to infer the `Object` constructor. */ + var objectCtorString = funcToString.call(Object); + + /** + * Checks if `value` is a plain object, that is, an object created by the + * `Object` constructor or one with a `[[Prototype]]` of `null`. + * + * @static + * @memberOf _ + * @since 0.8.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. + * @example + * + * function Foo() { + * this.a = 1; + * } + * + * _.isPlainObject(new Foo); + * // => false + * + * _.isPlainObject([1, 2, 3]); + * // => false + * + * _.isPlainObject({ 'x': 0, 'y': 0 }); + * // => true + * + * _.isPlainObject(Object.create(null)); + * // => true + */ + function isPlainObject(value) { + if (!isObjectLike(value) || baseGetTag(value) != objectTag) { + return false; + } + var proto = getPrototype(value); + if (proto === null) { + return true; + } + var Ctor = hasOwnProperty$1.call(proto, 'constructor') && proto.constructor; + return typeof Ctor == 'function' && Ctor instanceof Ctor && + funcToString.call(Ctor) == objectCtorString; + } + + /** + * The base implementation of `_.slice` without an iteratee call guard. + * + * @private + * @param {Array} array The array to slice. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns the slice of `array`. + */ + + /** Used to compose unicode character classes. */ + + /** + * Converts an ASCII `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ + + /** Used to compose unicode character classes. */ + + /** + * A specialized version of `_.reduce` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @param {boolean} [initAccum] Specify using the first element of `array` as + * the initial value. + * @returns {*} Returns the accumulated value. + */ + + /** + * The base implementation of `_.propertyOf` without support for deep paths. + * + * @private + * @param {Object} object The object to query. + * @returns {Function} Returns the new accessor function. + */ + + /** Used to match words composed of alphanumeric characters. */ + + /** Used to detect strings that need a more robust regexp to match words. */ + + /** Used to compose unicode character classes. */ + + /** + * The base implementation of `_.clamp` which doesn't coerce arguments. + * + * @private + * @param {number} number The number to clamp. + * @param {number} [lower] The lower bound. + * @param {number} upper The upper bound. + * @returns {number} Returns the clamped number. + */ + + /** + * Removes `key` and its value from the stack. + * + * @private + * @name delete + * @memberOf Stack + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + + /** + * Gets the stack value for `key`. + * + * @private + * @name get + * @memberOf Stack + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ + + /** + * Checks if a stack value for `key` exists. + * + * @private + * @name has + * @memberOf Stack + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + + /** + * A specialized version of `_.filter` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + */ + + /** + * This method returns a new empty array. + * + * @static + * @memberOf _ + * @since 4.13.0 + * @category Util + * @returns {Array} Returns the new empty array. + * @example + * + * var arrays = _.times(2, _.stubArray); + * + * console.log(arrays); + * // => [[], []] + * + * console.log(arrays[0] === arrays[1]); + * // => false + */ + + /** Used for built-in method references. */ + + /** Used to match `RegExp` flags from their coerced string values. */ + + /** + * Creates an array with all falsey values removed. The values `false`, `null`, + * `0`, `""`, `undefined`, and `NaN` are falsey. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to compact. + * @returns {Array} Returns the new array of filtered values. + * @example + * + * _.compact([0, 1, false, 2, '', 3]); + * // => [1, 2, 3] + */ + + /** Used to stand-in for `undefined` hash values. */ + + /** + * Checks if `value` is in the array cache. + * + * @private + * @name has + * @memberOf SetCache + * @param {*} value The value to search for. + * @returns {number} Returns `true` if `value` is found, else `false`. + */ + + /** + * A specialized version of `_.some` for arrays without support for iteratee + * shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. + */ + + /** + * Checks if a `cache` value for `key` exists. + * + * @private + * @param {Object} cache The cache to query. + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + + /** + * Converts `map` to its key-value pairs. + * + * @private + * @param {Object} map The map to convert. + * @returns {Array} Returns the key-value pairs. + */ + + /** + * Converts `set` to an array of its values. + * + * @private + * @param {Object} set The set to convert. + * @returns {Array} Returns the values. + */ + + /** + * A specialized version of `matchesProperty` for source values suitable + * for strict equality comparisons, i.e. `===`. + * + * @private + * @param {string} key The key of the property to get. + * @param {*} srcValue The value to match. + * @returns {Function} Returns the new spec function. + */ + + /** + * The base implementation of `_.hasIn` without support for deep paths. + * + * @private + * @param {Object} [object] The object to query. + * @param {Array|string} key The key to check. + * @returns {boolean} Returns `true` if `key` exists, else `false`. + */ + + /** + * The base implementation of `_.property` without support for deep paths. + * + * @private + * @param {string} key The key of the property to get. + * @returns {Function} Returns the new accessor function. + */ + + /** + * The base implementation of `_.conformsTo` which accepts `props` to check. + * + * @private + * @param {Object} object The object to inspect. + * @param {Object} source The object of property predicates to conform to. + * @returns {boolean} Returns `true` if `object` conforms, else `false`. + */ + + /** + * A specialized version of `baseAggregator` for arrays. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + + /** + * Creates a base function for methods like `_.forIn` and `_.forOwn`. + * + * @private + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new base function. + */ + + /** + * Checks `value` to determine whether a default value should be returned in + * its place. The `defaultValue` is returned if `value` is `NaN`, `null`, + * or `undefined`. + * + * @static + * @memberOf _ + * @since 4.14.0 + * @category Util + * @param {*} value The value to check. + * @param {*} defaultValue The default value. + * @returns {*} Returns the resolved value. + * @example + * + * _.defaultTo(1, 10); + * // => 1 + * + * _.defaultTo(undefined, 10); + * // => 10 + */ + + /** + * Gets the value at `key`, unless `key` is "__proto__". + * + * @private + * @param {Object} object The object to query. + * @param {string} key The key of the property to get. + * @returns {*} Returns the property value. + */ + + /** Error message constants. */ + + /** + * This function is like `arrayIncludes` except that it accepts a comparator. + * + * @private + * @param {Array} [array] The array to inspect. + * @param {*} target The value to search for. + * @param {Function} comparator The comparator invoked per element. + * @returns {boolean} Returns `true` if `target` is found, else `false`. + */ + + /** + * Gets the last element of `array`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to query. + * @returns {*} Returns the last element of `array`. + * @example + * + * _.last([1, 2, 3]); + * // => 3 + */ + + /** + * A specialized version of `_.forEachRight` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns `array`. + */ + + /** + * Converts `set` to its value-value pairs. + * + * @private + * @param {Object} set The set to convert. + * @returns {Array} Returns the value-value pairs. + */ + + /** + * A specialized version of `_.every` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false`. + */ + + /** + * The base implementation of methods like `_.findKey` and `_.findLastKey`, + * without support for iteratee shorthands, which iterates over `collection` + * using `eachFunc`. + * + * @private + * @param {Array|Object} collection The collection to inspect. + * @param {Function} predicate The function invoked per iteration. + * @param {Function} eachFunc The function to iterate over `collection`. + * @returns {*} Returns the found element or its key, else `undefined`. + */ + + /** + * Gets the first element of `array`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @alias first + * @category Array + * @param {Array} array The array to query. + * @returns {*} Returns the first element of `array`. + * @example + * + * _.head([1, 2, 3]); + * // => 1 + * + * _.head([]); + * // => undefined + */ + + /** + * The inverse of `_.toPairs`; this method returns an object composed + * from key-value `pairs`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} pairs The key-value pairs. + * @returns {Object} Returns the new object. + * @example + * + * _.fromPairs([['a', 1], ['b', 2]]); + * // => { 'a': 1, 'b': 2 } + */ + + /** + * The base implementation of `_.gt` which doesn't coerce arguments. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is greater than `other`, + * else `false`. + */ + + /** Used for built-in method references. */ + + /* Built-in method references for those with the same name as other `lodash` methods. */ + + /** `Object#toString` result references. */ + var stringTag = '[object String]'; + + /** + * Checks if `value` is classified as a `String` primitive or object. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a string, else `false`. + * @example + * + * _.isString('abc'); + * // => true + * + * _.isString(1); + * // => false + */ + function isString(value) { + return typeof value == 'string' || + (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag); + } + + /** + * Checks if `value` is `null` or `undefined`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is nullish, else `false`. + * @example + * + * _.isNil(null); + * // => true + * + * _.isNil(void 0); + * // => true + * + * _.isNil(NaN); + * // => false + */ + function isNil(value) { + return value == null; + } + + /** + * Checks if `value` is `null`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `null`, else `false`. + * @example + * + * _.isNull(null); + * // => true + * + * _.isNull(void 0); + * // => false + */ + + /** + * Checks if `value` is `undefined`. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. + * @example + * + * _.isUndefined(void 0); + * // => true + * + * _.isUndefined(null); + * // => false + */ + + /** Used for built-in method references. */ + + /** + * A specialized version of `_.lastIndexOf` which performs strict equality + * comparisons of values, i.e. `===`. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + + /** + * The base implementation of `_.lt` which doesn't coerce arguments. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is less than `other`, + * else `false`. + */ + + /** + * The base implementation of `_.sum` and `_.sumBy` without support for + * iteratee shorthands. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {number} Returns the sum. + */ + + /** Error message constants. */ + + /** + * Converts `iterator` to an array. + * + * @private + * @param {Object} iterator The iterator to convert. + * @returns {Array} Returns the converted array. + */ + + /** + * The base implementation of `_.sortBy` which uses `comparer` to define the + * sort order of `array` and replaces criteria objects with their corresponding + * values. + * + * @private + * @param {Array} array The array to sort. + * @param {Function} comparer The function to define sort order. + * @returns {Array} Returns `array`. + */ + + /** Used as references for various `Number` constants. */ + + /** Used to compose unicode character classes. */ + + /** + * This function is like `baseIndexOf` except that it accepts a comparator. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @param {Function} comparator The comparator invoked per element. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + + /* Built-in method references for those with the same name as other `lodash` methods. */ + + /* Built-in method references for those with the same name as other `lodash` methods. */ + + /** + * The base implementation of `_.reduce` and `_.reduceRight`, without support + * for iteratee shorthands, which iterates over `collection` using `eachFunc`. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} accumulator The initial value. + * @param {boolean} initAccum Specify using the first or last element of + * `collection` as the initial value. + * @param {Function} eachFunc The function to iterate over `collection`. + * @returns {*} Returns the accumulated value. + */ + + /** + * A specialized version of `_.reduceRight` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @param {boolean} [initAccum] Specify using the last element of `array` as + * the initial value. + * @returns {*} Returns the accumulated value. + */ + + /** Used for built-in method references. */ + + /** + * This method returns a new empty object. + * + * @static + * @memberOf _ + * @since 4.13.0 + * @category Util + * @returns {Object} Returns the new empty object. + * @example + * + * var objects = _.times(2, _.stubObject); + * + * console.log(objects); + * // => [{}, {}] + * + * console.log(objects[0] === objects[1]); + * // => false + */ + + /** + * This method returns an empty string. + * + * @static + * @memberOf _ + * @since 4.13.0 + * @category Util + * @returns {string} Returns the empty string. + * @example + * + * _.times(2, _.stubString); + * // => ['', ''] + */ + + /** + * This method returns `true`. + * + * @static + * @memberOf _ + * @since 4.13.0 + * @category Util + * @returns {boolean} Returns `true`. + * @example + * + * _.times(2, _.stubTrue); + * // => [true, true] + */ + + /** + * This method invokes `interceptor` and returns `value`. The interceptor + * is invoked with one argument; (value). The purpose of this method is to + * "tap into" a method chain sequence in order to modify intermediate results. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Seq + * @param {*} value The value to provide to `interceptor`. + * @param {Function} interceptor The function to invoke. + * @returns {*} Returns `value`. + * @example + * + * _([1, 2, 3]) + * .tap(function(array) { + * // Mutate input array. + * array.pop(); + * }) + * .reverse() + * .value(); + * // => [2, 1] + */ + + /** Used to escape characters for inclusion in compiled string literals. */ + + /** Used to match template delimiters. */ + + /** Used to match template delimiters. */ + + /** Used to match template delimiters. */ + + /** + * This method is like `_.tap` except that it returns the result of `interceptor`. + * The purpose of this method is to "pass thru" values replacing intermediate + * results in a method chain sequence. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Seq + * @param {*} value The value to provide to `interceptor`. + * @param {Function} interceptor The function to invoke. + * @returns {*} Returns the result of `interceptor`. + * @example + * + * _(' abc ') + * .chain() + * .trim() + * .thru(function(value) { + * return [value]; + * }) + * .value(); + * // => ['abc'] + */ + + /** + * Enables the wrapper to be iterable. + * + * @name Symbol.iterator + * @memberOf _ + * @since 4.0.0 + * @category Seq + * @returns {Object} Returns the wrapper object. + * @example + * + * var wrapped = _([1, 2]); + * + * wrapped[Symbol.iterator]() === wrapped; + * // => true + * + * Array.from(wrapped); + * // => [1, 2] + */ + + /** + * This base implementation of `_.zipObject` which assigns values using `assignFunc`. + * + * @private + * @param {Array} props The property identifiers. + * @param {Array} values The property values. + * @param {Function} assignFunc The function to assign values. + * @returns {Object} Returns the new object. + */ + + /* Built-in method references for those with the same name as other `lodash` methods. */ + + /** + * @license + * Lodash (Custom Build) + * Build: `lodash modularize exports="es" -o ./` + * Copyright JS Foundation and other contributors + * Released under MIT license + * Based on Underscore.js 1.8.3 + * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + */ + + /** + * @license + * Lodash (Custom Build) + * Build: `lodash modularize exports="es" -o ./` + * Copyright JS Foundation and other contributors + * Released under MIT license + * Based on Underscore.js 1.8.3 + * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + */ + + function genTraversalHandler(fn, setter) { + if (setter === void 0) { + setter = function setter(target, key, value) { + target[key] = value; + }; + } + + function recursiveFn(source, target, key) { + if (isArray(source) || isPlainObject(source)) { + target = !isObject(target) ? isPlainObject(source) ? {} : [] : target; + + for (var name_1 in source) { + if (!source.hasOwnProperty(name_1)) { + continue; + } + + setter(target, name_1, recursiveFn(source[name_1], target[name_1], name_1)); + } + + return target; + } + + return fn(source, target, key); + } + + return recursiveFn; + } + var myDeepAssign = genTraversalHandler(function (val) { + return val; + }); + function deepClone(source) { + if (!isObject(source)) { + throw new TypeError("deepClone only accept non primitive type"); + } + + return myDeepAssign(source); + } + function deepAssign() { + var args = []; + + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + + if (args.length < 2) { + throw new Error("deepAssign accept two and more argument"); + } + + for (var i = args.length - 1; i > -1; i--) { + if (!isObject(args[i])) { + throw new TypeError("deepAssign only accept non primitive type"); + } + } + + var target = args.shift(); + args.forEach(function (source) { + return myDeepAssign(source, target); + }); + return target; + } + function camelize(str, isBig) { + return str.replace(/(^|[^a-zA-Z]+)([a-zA-Z])/g, function (match, spilt, initials, index) { + return !isBig && index === 0 ? initials.toLowerCase() : initials.toUpperCase(); + }); + } + function hypenate(str) { + return camelize(str).replace(/([A-Z])/g, function (match) { + return "-" + match.toLowerCase(); + }); + } + function bind(fn, context) { + if (fn.bind) { + return fn.bind(context); + } else if (fn.apply) { + return function __autobind__() { + var args = []; + + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + + return fn.apply(context, args); + }; + } + + return function __autobind__() { + var args = []; + + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + + return fn.call.apply(fn, [context].concat(args)); + }; + } + function uuid() { + return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4(); + } + function S4() { + return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1); + } + function rand(length) { + var str = ""; + + while (str.length < length) { + str += S4(); + } + + return str.slice(0, length); + } + function getDeepProperty(obj, keys, _a) { + var _b = _a === void 0 ? {} : _a, + _c = _b.throwError, + throwError = _c === void 0 ? false : _c, + backup = _b.backup; + + if (isString(keys)) { + keys = keys.split("."); + } + + if (!isArray(keys)) { + throw new TypeError("keys of getDeepProperty must be string or Array"); + } + + var read = []; + var target = obj; + + for (var i = 0, len = keys.length; i < len; i++) { + var key = keys[i]; + + if (isNil(target)) { + if (throwError) { + throw new Error("obj" + (read.length > 0 ? "." + read.join(".") : " itself") + " is " + target); + } else { + return backup; + } + } + + target = target[key]; + read.push(key); + } + + return target; + } + + exports.S4 = S4; + exports.bind = bind; + exports.camelize = camelize; + exports.deepAssign = deepAssign; + exports.deepClone = deepClone; + exports.genTraversalHandler = genTraversalHandler; + exports.getDeepProperty = getDeepProperty; + exports.hypenate = hypenate; + exports.rand = rand; + exports.uuid = uuid; + + Object.defineProperty(exports, '__esModule', { value: true }); })); diff --git a/lib/index.js b/lib/index.js index b834828..5f990e1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,22 +1,16 @@ /** - * toxic-utils v0.3.1 + * toxic-utils v0.4.0 * (c) 2017-2019 toxic-johann * Released under MIT - * Built ad Thu Apr 25 2019 23:19:01 GMT+0800 (China Standard Time) + * Built ad Sat Jun 01 2019 23:56:18 GMT+0800 (China Standard Time) */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); -function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } - -var _isString = _interopDefault(require('lodash/isString')); -var _isPlainObject = _interopDefault(require('lodash/isPlainObject')); -var _isObject = _interopDefault(require('lodash/isObject')); -var _isNil = _interopDefault(require('lodash/isNil')); -var _isArray = _interopDefault(require('lodash/isArray')); +var lodashEs = require('lodash-es'); function genTraversalHandler(fn, setter) { if (setter === void 0) { @@ -26,8 +20,8 @@ function genTraversalHandler(fn, setter) { } function recursiveFn(source, target, key) { - if (_isArray(source) || _isPlainObject(source)) { - target = !_isObject(target) ? _isPlainObject(source) ? {} : [] : target; + if (lodashEs.isArray(source) || lodashEs.isPlainObject(source)) { + target = !lodashEs.isObject(target) ? lodashEs.isPlainObject(source) ? {} : [] : target; for (var name_1 in source) { if (!source.hasOwnProperty(name_1)) { @@ -49,7 +43,7 @@ var myDeepAssign = genTraversalHandler(function (val) { return val; }); function deepClone(source) { - if (!_isObject(source)) { + if (!lodashEs.isObject(source)) { throw new TypeError("deepClone only accept non primitive type"); } @@ -67,7 +61,7 @@ function deepAssign() { } for (var i = args.length - 1; i > -1; i--) { - if (!_isObject(args[i])) { + if (!lodashEs.isObject(args[i])) { throw new TypeError("deepAssign only accept non primitive type"); } } @@ -134,11 +128,11 @@ function getDeepProperty(obj, keys, _a) { throwError = _c === void 0 ? false : _c, backup = _b.backup; - if (_isString(keys)) { + if (lodashEs.isString(keys)) { keys = keys.split("."); } - if (!_isArray(keys)) { + if (!lodashEs.isArray(keys)) { throw new TypeError("keys of getDeepProperty must be string or Array"); } @@ -148,7 +142,7 @@ function getDeepProperty(obj, keys, _a) { for (var i = 0, len = keys.length; i < len; i++) { var key = keys[i]; - if (_isNil(target)) { + if (lodashEs.isNil(target)) { if (throwError) { throw new Error("obj" + (read.length > 0 ? "." + read.join(".") : " itself") + " is " + target); } else { diff --git a/lib/index.min.js b/lib/index.min.js index 085a55d..505eb55 100644 --- a/lib/index.min.js +++ b/lib/index.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).toxicUtils={})}(this,function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n="object"==typeof e&&e&&e.Object===Object&&e,r="object"==typeof self&&self&&self.Object===Object&&self,o=(n||r||Function("return this")()).Symbol,i=Object.prototype,u=i.hasOwnProperty,c=i.toString,f=o?o.toStringTag:void 0;var a=function(t){var e=u.call(t,f),n=t[f];try{var r=!(t[f]=void 0)}catch(t){}var o=c.call(t);return r&&(e?t[f]=n:delete t[f]),o},l=Object.prototype.toString;var p=function(t){return l.call(t)},s=o?o.toStringTag:void 0;var d=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":s&&s in Object(t)?a(t):p(t)},y=Array.isArray;var v=function(t){return null!=t&&"object"==typeof t};var g=function(t){return"string"==typeof t||!y(t)&&v(t)&&"[object String]"==d(t)};var b=function(e,n){return function(t){return e(n(t))}}(Object.getPrototypeOf,Object),h=Function.prototype,j=Object.prototype,w=h.toString,O=j.hasOwnProperty,m=w.call(Object);var A=function(t){if(!v(t)||"[object Object]"!=d(t))return!1;var e=b(t);if(null===e)return!0;var n=O.call(e,"constructor")&&e.constructor;return"function"==typeof n&&n instanceof n&&w.call(n)==m};var S=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)};var T=function(t){return null==t};function E(i,u){return void 0===u&&(u=function(t,e,n){t[e]=n}),function t(e,n,r){if(y(e)||A(e)){for(var o in n=S(n)?n:A(e)?{}:[],e)e.hasOwnProperty(o)&&u(n,o,t(e[o],n[o],o));return n}return i(e,n,r)}}var P=E(function(t){return t});function C(t,o){return t.replace(/(^|[^a-zA-Z]+)([a-zA-Z])/g,function(t,e,n,r){return o||0!==r?n.toUpperCase():n.toLowerCase()})}function x(){return(65536*(1+Math.random())|0).toString(16).substring(1)}t.S4=x,t.bind=function(n,r){return n.bind?n.bind(r):n.apply?function(){for(var t=[],e=0;e");for(var c=[],f=t,a=0,l=e.length;a");for(var u=[],f=t,a=0,l=r.length;a -1; i--) { - if (!_isObject(args[i])) { + if (!isObject(args[i])) { throw new TypeError("deepAssign only accept non primitive type"); } } @@ -128,11 +124,11 @@ function getDeepProperty(obj, keys, _a) { throwError = _c === void 0 ? false : _c, backup = _b.backup; - if (_isString(keys)) { + if (isString(keys)) { keys = keys.split("."); } - if (!_isArray(keys)) { + if (!isArray(keys)) { throw new TypeError("keys of getDeepProperty must be string or Array"); } @@ -142,7 +138,7 @@ function getDeepProperty(obj, keys, _a) { for (var i = 0, len = keys.length; i < len; i++) { var key = keys[i]; - if (_isNil(target)) { + if (isNil(target)) { if (throwError) { throw new Error("obj" + (read.length > 0 ? "." + read.join(".") : " itself") + " is " + target); } else { diff --git a/package.json b/package.json index 1245926..3cd389f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "toxic-utils", - "version": "0.3.1", + "version": "0.4.0", "description": "utils", "main": "lib/index.js", "module": "lib/index.mjs",