mirror of
https://github.com/liriliri/eruda.git
synced 2026-03-24 09:48:37 +08:00
1258 lines
33 KiB
JavaScript
1258 lines
33 KiB
JavaScript
// Built by eustia.
|
|
/* eslint-disable */
|
|
"use strict";
|
|
|
|
var _ = {};
|
|
|
|
/* ------------------------------ allKeys ------------------------------ */
|
|
|
|
export var allKeys = _.allKeys = (function (exports) {
|
|
/* Retrieve all the names of object's own and inherited properties.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|------|---------------------------|
|
|
* |obj |object|Object to query |
|
|
* |return|array |Array of all property names|
|
|
*
|
|
* Members of Object's prototype won't be retrieved.
|
|
*/
|
|
|
|
/* example
|
|
* var obj = Object.create({zero: 0});
|
|
* obj.one = 1;
|
|
* allKeys(obj) // -> ['zero', 'one']
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function allKeys(obj: any): string[];
|
|
*/
|
|
exports = function exports(obj) {
|
|
var ret = [],
|
|
key;
|
|
|
|
for (key in obj) {
|
|
ret.push(key);
|
|
}
|
|
|
|
return ret;
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ idxOf ------------------------------ */
|
|
|
|
export var idxOf = _.idxOf = (function (exports) {
|
|
/* Get the index at which the first occurrence of value.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |---------|------|--------------------|
|
|
* |arr |array |Array to search |
|
|
* |val |* |Value to search for |
|
|
* |fromIdx=0|number|Index to search from|
|
|
* |return |number|Value index |
|
|
*/
|
|
|
|
/* example
|
|
* idxOf([1, 2, 1, 2], 2, 2); // -> 3
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function idxOf(arr: any[], val: any, fromIdx?: number): number;
|
|
*/
|
|
exports = function exports(arr, val, fromIdx) {
|
|
return Array.prototype.indexOf.call(arr, val, fromIdx);
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ isUndef ------------------------------ */
|
|
|
|
export var isUndef = _.isUndef = (function (exports) {
|
|
/* Check if value is undefined.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|-------|--------------------------|
|
|
* |val |* |Value to check |
|
|
* |return|boolean|True if value is undefined|
|
|
*/
|
|
|
|
/* example
|
|
* isUndef(void 0); // -> true
|
|
* isUndef(null); // -> false
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function isUndef(val: any): boolean;
|
|
*/
|
|
exports = function exports(val) {
|
|
return val === void 0;
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ optimizeCb ------------------------------ */
|
|
|
|
export var optimizeCb = _.optimizeCb = (function (exports) {
|
|
/* Used for function context binding.
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function optimizeCb(fn: Function, ctx: any, argCount?: number): Function;
|
|
*/
|
|
|
|
/* dependencies
|
|
* isUndef
|
|
*/
|
|
|
|
exports = function exports(fn, ctx, argCount) {
|
|
if (isUndef(ctx)) return fn;
|
|
|
|
switch (argCount == null ? 3 : argCount) {
|
|
case 1:
|
|
return function(val) {
|
|
return fn.call(ctx, val);
|
|
};
|
|
|
|
case 3:
|
|
return function(val, idx, collection) {
|
|
return fn.call(ctx, val, idx, collection);
|
|
};
|
|
|
|
case 4:
|
|
return function(accumulator, val, idx, collection) {
|
|
return fn.call(ctx, accumulator, val, idx, collection);
|
|
};
|
|
}
|
|
|
|
return function() {
|
|
return fn.apply(ctx, arguments);
|
|
};
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ types ------------------------------ */
|
|
|
|
export var types = _.types = (function (exports) {
|
|
/* Used for typescript definitions only.
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare namespace types {
|
|
* interface Collection<T> {}
|
|
* interface List<T> extends Collection<T> {
|
|
* [index: number]: T;
|
|
* length: number;
|
|
* }
|
|
* interface ListIterator<T, TResult> {
|
|
* (value: T, index: number, list: List<T>): TResult;
|
|
* }
|
|
* interface Dictionary<T> extends Collection<T> {
|
|
* [index: string]: T;
|
|
* }
|
|
* interface ObjectIterator<T, TResult> {
|
|
* (element: T, key: string, list: Dictionary<T>): TResult;
|
|
* }
|
|
* interface MemoIterator<T, TResult> {
|
|
* (prev: TResult, curr: T, index: number, list: List<T>): TResult;
|
|
* }
|
|
* interface MemoObjectIterator<T, TResult> {
|
|
* (prev: TResult, curr: T, key: string, list: Dictionary<T>): TResult;
|
|
* }
|
|
* }
|
|
* export declare const types: {}
|
|
*/
|
|
exports = {};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ endWith ------------------------------ */
|
|
|
|
export var endWith = _.endWith = (function (exports) {
|
|
/* Check if string ends with the given target string.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|-------|-------------------------------|
|
|
* |str |string |The string to search |
|
|
* |suffix|string |String suffix |
|
|
* |return|boolean|True if string ends with target|
|
|
*/
|
|
|
|
/* example
|
|
* endWith('ab', 'b'); // -> true
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function endWith(str: string, suffix: string): boolean;
|
|
*/
|
|
exports = function exports(str, suffix) {
|
|
var idx = str.length - suffix.length;
|
|
return idx >= 0 && str.indexOf(suffix, idx) === idx;
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ toStr ------------------------------ */
|
|
|
|
export var toStr = _.toStr = (function (exports) {
|
|
/* Convert value to a string.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|------|----------------|
|
|
* |val |* |Value to convert|
|
|
* |return|string|Resulted string |
|
|
*/
|
|
|
|
/* example
|
|
* toStr(null); // -> ''
|
|
* toStr(1); // -> '1'
|
|
* toStr(false); // -> 'false'
|
|
* toStr([1, 2, 3]); // -> '1,2,3'
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function toStr(val: any): string;
|
|
*/
|
|
exports = function exports(val) {
|
|
return val == null ? '' : val.toString();
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ escapeJsStr ------------------------------ */
|
|
|
|
export var escapeJsStr = _.escapeJsStr = (function (exports) {
|
|
/* Escape string to be a valid JavaScript string literal between quotes.
|
|
*
|
|
* http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|------|----------------|
|
|
* |str |string|String to escape|
|
|
* |return|string|Escaped string |
|
|
*/
|
|
|
|
/* example
|
|
* escapeJsStr('\"\n'); // -> '\\"\\\\n'
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function escapeJsStr(str: string): string;
|
|
*/
|
|
|
|
/* dependencies
|
|
* toStr
|
|
*/
|
|
|
|
exports = function exports(str) {
|
|
return toStr(str).replace(regEscapeChars, function(char) {
|
|
switch (char) {
|
|
case '"':
|
|
case "'":
|
|
case '\\':
|
|
return '\\' + char;
|
|
|
|
case '\n':
|
|
return '\\n';
|
|
|
|
case '\r':
|
|
return '\\r';
|
|
// Line separator
|
|
|
|
case '\u2028':
|
|
return '\\u2028';
|
|
// Paragraph separator
|
|
|
|
case '\u2029':
|
|
return '\\u2029';
|
|
}
|
|
});
|
|
};
|
|
|
|
var regEscapeChars = /["'\\\n\r\u2028\u2029]/g;
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ escapeJsonStr ------------------------------ */
|
|
|
|
export var escapeJsonStr = _.escapeJsonStr = (function (exports) {
|
|
/* Escape json string.
|
|
*/
|
|
|
|
/* dependencies
|
|
* escapeJsStr
|
|
*/
|
|
|
|
function exports(str) {
|
|
return escapeJsStr(str)
|
|
.replace(/\\'/g, "'")
|
|
.replace(/\t/g, '\\t')
|
|
}
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ has ------------------------------ */
|
|
|
|
export var has = _.has = (function (exports) {
|
|
/* Checks if key is a direct property.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|-------|--------------------------------|
|
|
* |obj |object |Object to query |
|
|
* |key |string |Path to check |
|
|
* |return|boolean|True if key is a direct property|
|
|
*/
|
|
|
|
/* example
|
|
* has({one: 1}, 'one'); // -> true
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function has(obj: {}, key: string): boolean;
|
|
*/
|
|
var hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
|
exports = function exports(obj, key) {
|
|
return hasOwnProp.call(obj, key);
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ identity ------------------------------ */
|
|
|
|
export var identity = _.identity = (function (exports) {
|
|
/* Return the first argument given.
|
|
*
|
|
* |Name |Type|Desc |
|
|
* |------|----|-----------|
|
|
* |val |* |Any value |
|
|
* |return|* |Given value|
|
|
*/
|
|
|
|
/* example
|
|
* identity('a'); // -> 'a'
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function identity<T>(val: T): T;
|
|
*/
|
|
exports = function exports(val) {
|
|
return val;
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ objToStr ------------------------------ */
|
|
|
|
export var objToStr = _.objToStr = (function (exports) {
|
|
/* Alias of Object.prototype.toString.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|------|------------------------------------|
|
|
* |val |* |Source value |
|
|
* |return|string|String representation of given value|
|
|
*/
|
|
|
|
/* example
|
|
* objToStr(5); // -> '[object Number]'
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function objToStr(val: any): string;
|
|
*/
|
|
var ObjToStr = Object.prototype.toString;
|
|
|
|
exports = function exports(val) {
|
|
return ObjToStr.call(val);
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ isArgs ------------------------------ */
|
|
|
|
export var isArgs = _.isArgs = (function (exports) {
|
|
/* Check if value is classified as an arguments object.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|-------|------------------------------------|
|
|
* |val |* |Value to check |
|
|
* |return|boolean|True if value is an arguments object|
|
|
*/
|
|
|
|
/* example
|
|
* (function () {
|
|
* isArgs(arguments); // -> true
|
|
* })();
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function isArgs(val: any): boolean;
|
|
*/
|
|
|
|
/* dependencies
|
|
* objToStr
|
|
*/
|
|
|
|
exports = function exports(val) {
|
|
return objToStr(val) === '[object Arguments]';
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ isArr ------------------------------ */
|
|
|
|
export var isArr = _.isArr = (function (exports) {
|
|
/* Check if value is an `Array` object.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|-------|----------------------------------|
|
|
* |val |* |Value to check |
|
|
* |return|boolean|True if value is an `Array` object|
|
|
*/
|
|
|
|
/* example
|
|
* isArr([]); // -> true
|
|
* isArr({}); // -> false
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function isArr(val: any): boolean;
|
|
*/
|
|
|
|
/* dependencies
|
|
* objToStr
|
|
*/
|
|
|
|
exports =
|
|
Array.isArray ||
|
|
function(val) {
|
|
return objToStr(val) === '[object Array]';
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ isNum ------------------------------ */
|
|
|
|
export var isNum = _.isNum = (function (exports) {
|
|
/* Check if value is classified as a Number primitive or object.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|-------|-------------------------------------|
|
|
* |val |* |Value to check |
|
|
* |return|boolean|True if value is correctly classified|
|
|
*/
|
|
|
|
/* example
|
|
* isNum(5); // -> true
|
|
* isNum(5.1); // -> true
|
|
* isNum({}); // -> false
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function isNum(val: any): boolean;
|
|
*/
|
|
|
|
/* dependencies
|
|
* objToStr
|
|
*/
|
|
|
|
exports = function exports(val) {
|
|
return objToStr(val) === '[object Number]';
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ isFn ------------------------------ */
|
|
|
|
export var isFn = _.isFn = (function (exports) {
|
|
/* Check if value is a function.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|-------|---------------------------|
|
|
* |val |* |Value to check |
|
|
* |return|boolean|True if value is a function|
|
|
*
|
|
* Generator function is also classified as true.
|
|
*/
|
|
|
|
/* example
|
|
* isFn(function() {}); // -> true
|
|
* isFn(function*() {}); // -> true
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function isFn(val: any): boolean;
|
|
*/
|
|
|
|
/* dependencies
|
|
* objToStr
|
|
*/
|
|
|
|
exports = function exports(val) {
|
|
var objStr = objToStr(val);
|
|
return (
|
|
objStr === '[object Function]' ||
|
|
objStr === '[object GeneratorFunction]'
|
|
);
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ isArrLike ------------------------------ */
|
|
|
|
export var isArrLike = _.isArrLike = (function (exports) {
|
|
/* Check if value is array-like.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|-------|---------------------------|
|
|
* |val |* |Value to check |
|
|
* |return|boolean|True if value is array like|
|
|
*
|
|
* Function returns false.
|
|
*/
|
|
|
|
/* example
|
|
* isArrLike('test'); // -> true
|
|
* isArrLike(document.body.children); // -> true;
|
|
* isArrLike([1, 2, 3]); // -> true
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function isArrLike(val: any): boolean;
|
|
*/
|
|
|
|
/* dependencies
|
|
* isNum isFn
|
|
*/
|
|
|
|
var MAX_ARR_IDX = Math.pow(2, 53) - 1;
|
|
|
|
exports = function exports(val) {
|
|
if (!val) return false;
|
|
var len = val.length;
|
|
return isNum(len) && len >= 0 && len <= MAX_ARR_IDX && !isFn(val);
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ isBrowser ------------------------------ */
|
|
|
|
export var isBrowser = _.isBrowser = (function (exports) {
|
|
function _typeof(obj) {
|
|
if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
|
|
_typeof = function _typeof(obj) {
|
|
return typeof obj;
|
|
};
|
|
} else {
|
|
_typeof = function _typeof(obj) {
|
|
return obj &&
|
|
typeof Symbol === 'function' &&
|
|
obj.constructor === Symbol &&
|
|
obj !== Symbol.prototype
|
|
? 'symbol'
|
|
: typeof obj;
|
|
};
|
|
}
|
|
return _typeof(obj);
|
|
}
|
|
|
|
/* Check if running in a browser.
|
|
*/
|
|
|
|
/* example
|
|
* console.log(isBrowser); // -> true if running in a browser
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare const isBrowser: boolean;
|
|
*/
|
|
exports =
|
|
(typeof window === 'undefined' ? 'undefined' : _typeof(window)) ===
|
|
'object' &&
|
|
(typeof document === 'undefined' ? 'undefined' : _typeof(document)) ===
|
|
'object' &&
|
|
document.nodeType === 9;
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ root ------------------------------ */
|
|
|
|
export var root = _.root = (function (exports) {
|
|
/* Root object reference, `global` in nodeJs, `window` in browser. */
|
|
|
|
/* typescript
|
|
* export declare const root: any;
|
|
*/
|
|
|
|
/* dependencies
|
|
* isBrowser
|
|
*/
|
|
|
|
exports = isBrowser ? window : global;
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ detectMocha ------------------------------ */
|
|
|
|
export var detectMocha = _.detectMocha = (function (exports) {
|
|
/* Detect if mocha is running.
|
|
*/
|
|
|
|
/* example
|
|
* detectMocha(); // -> True if mocha is running.
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function detectMocha(): boolean;
|
|
*/
|
|
|
|
/* dependencies
|
|
* root
|
|
*/
|
|
|
|
exports = function exports() {
|
|
for (var i = 0, len = methods.length; i < len; i++) {
|
|
var method = methods[i];
|
|
if (typeof root[method] !== 'function') return false;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
var methods = ['afterEach', 'after', 'beforeEach', 'before', 'describe', 'it'];
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ keys ------------------------------ */
|
|
|
|
export var keys = _.keys = (function (exports) {
|
|
/* Create an array of the own enumerable property names of object.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|------|-----------------------|
|
|
* |obj |object|Object to query |
|
|
* |return|array |Array of property names|
|
|
*/
|
|
|
|
/* example
|
|
* keys({a: 1}); // -> ['a']
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function keys(obj: any): string[];
|
|
*/
|
|
|
|
/* dependencies
|
|
* has detectMocha
|
|
*/
|
|
|
|
if (Object.keys && !detectMocha()) {
|
|
exports = Object.keys;
|
|
} else {
|
|
exports = function exports(obj) {
|
|
var ret = [],
|
|
key;
|
|
|
|
for (key in obj) {
|
|
if (has(obj, key)) ret.push(key);
|
|
}
|
|
|
|
return ret;
|
|
};
|
|
}
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ each ------------------------------ */
|
|
|
|
export var each = _.each = (function (exports) {
|
|
/* Iterate over elements of collection and invokes iterator for each element.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |--------|------------|------------------------------|
|
|
* |obj |object array|Collection to iterate over |
|
|
* |iterator|function |Function invoked per iteration|
|
|
* |[ctx] |* |Function context |
|
|
*/
|
|
|
|
/* example
|
|
* each({'a': 1, 'b': 2}, function (val, key) {});
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function each<T>(
|
|
* list: types.List<T>,
|
|
* iterator: types.ListIterator<T, void>,
|
|
* ctx?: any
|
|
* ): types.List<T>;
|
|
* export declare function each<T>(
|
|
* object: types.Dictionary<T>,
|
|
* iterator: types.ObjectIterator<T, void>,
|
|
* ctx?: any
|
|
* ): types.Collection<T>;
|
|
*/
|
|
|
|
/* dependencies
|
|
* isArrLike keys optimizeCb types
|
|
*/
|
|
|
|
exports = function exports(obj, iterator, ctx) {
|
|
iterator = optimizeCb(iterator, ctx);
|
|
var i, len;
|
|
|
|
if (isArrLike(obj)) {
|
|
for (i = 0, len = obj.length; i < len; i++) {
|
|
iterator(obj[i], i, obj);
|
|
}
|
|
} else {
|
|
var _keys = keys(obj);
|
|
|
|
for (i = 0, len = _keys.length; i < len; i++) {
|
|
iterator(obj[_keys[i]], _keys[i], obj);
|
|
}
|
|
}
|
|
|
|
return obj;
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ createAssigner ------------------------------ */
|
|
|
|
export var createAssigner = _.createAssigner = (function (exports) {
|
|
/* Used to create extend, extendOwn and defaults.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |--------|--------|------------------------------|
|
|
* |keysFn |function|Function to get object keys |
|
|
* |defaults|boolean |No override when set to true |
|
|
* |return |function|Result function, extend... |
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function createAssigner(keysFn: Function, defaults: boolean): Function;
|
|
*/
|
|
|
|
/* dependencies
|
|
* isUndef each
|
|
*/
|
|
|
|
exports = function exports(keysFn, defaults) {
|
|
return function(obj) {
|
|
each(arguments, function(src, idx) {
|
|
if (idx === 0) return;
|
|
var keys = keysFn(src);
|
|
each(keys, function(key) {
|
|
if (!defaults || isUndef(obj[key])) obj[key] = src[key];
|
|
});
|
|
});
|
|
return obj;
|
|
};
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ extend ------------------------------ */
|
|
|
|
export var extend = _.extend = (function (exports) {
|
|
/* Copy all of the properties in the source objects over to the destination object.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |-----------|------|------------------|
|
|
* |destination|object|Destination object|
|
|
* |...sources |object|Sources objects |
|
|
* |return |object|Destination object|
|
|
*/
|
|
|
|
/* example
|
|
* extend({name: 'RedHood'}, {age: 24}); // -> {name: 'RedHood', age: 24}
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function extend(destination: any, ...sources: any[]): any;
|
|
*/
|
|
|
|
/* dependencies
|
|
* createAssigner allKeys
|
|
*/
|
|
|
|
exports = createAssigner(allKeys);
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ values ------------------------------ */
|
|
|
|
export var values = _.values = (function (exports) {
|
|
/* Create an array of the own enumerable property values of object.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|------|------------------------|
|
|
* |obj |object|Object to query |
|
|
* |return|array |Array of property values|
|
|
*/
|
|
|
|
/* example
|
|
* values({one: 1, two: 2}); // -> [1, 2]
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function values(obj: any): any[];
|
|
*/
|
|
|
|
/* dependencies
|
|
* each
|
|
*/
|
|
|
|
exports = function exports(obj) {
|
|
var ret = [];
|
|
each(obj, function(val) {
|
|
ret.push(val);
|
|
});
|
|
return ret;
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ contain ------------------------------ */
|
|
|
|
export var contain = _.contain = (function (exports) {
|
|
/* Check if the value is present in the list.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|------------|------------------------------------|
|
|
* |target|array object|Target object |
|
|
* |value |* |Value to check |
|
|
* |return|boolean |True if value is present in the list|
|
|
*/
|
|
|
|
/* example
|
|
* contain([1, 2, 3], 1); // -> true
|
|
* contain({a: 1, b: 2}, 1); // -> true
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function contain(arr: any[] | {}, val: any): boolean;
|
|
*/
|
|
|
|
/* dependencies
|
|
* idxOf isArrLike values
|
|
*/
|
|
|
|
exports = function exports(arr, val) {
|
|
if (!isArrLike(arr)) arr = values(arr);
|
|
return idxOf(arr, val) >= 0;
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ extendOwn ------------------------------ */
|
|
|
|
export var extendOwn = _.extendOwn = (function (exports) {
|
|
/* Like extend, but only copies own properties over to the destination object.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |-----------|------|------------------|
|
|
* |destination|object|Destination object|
|
|
* |...sources |object|Sources objects |
|
|
* |return |object|Destination object|
|
|
*/
|
|
|
|
/* example
|
|
* extendOwn({name: 'RedHood'}, {age: 24}); // -> {name: 'RedHood', age: 24}
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function extendOwn(destination: any, ...sources: any[]): any;
|
|
*/
|
|
|
|
/* dependencies
|
|
* keys createAssigner
|
|
*/
|
|
|
|
exports = createAssigner(keys);
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ isStr ------------------------------ */
|
|
|
|
export var isStr = _.isStr = (function (exports) {
|
|
/* Check if value is a string primitive.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|-------|-----------------------------------|
|
|
* |val |* |Value to check |
|
|
* |return|boolean|True if value is a string primitive|
|
|
*/
|
|
|
|
/* example
|
|
* isStr('licia'); // -> true
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function isStr(val: any): boolean;
|
|
*/
|
|
|
|
/* dependencies
|
|
* objToStr
|
|
*/
|
|
|
|
exports = function exports(val) {
|
|
return objToStr(val) === '[object String]';
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ isEmpty ------------------------------ */
|
|
|
|
export var isEmpty = _.isEmpty = (function (exports) {
|
|
/* Check if value is an empty object or array.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|-------|----------------------|
|
|
* |val |* |Value to check |
|
|
* |return|boolean|True if value is empty|
|
|
*/
|
|
|
|
/* example
|
|
* isEmpty([]); // -> true
|
|
* isEmpty({}); // -> true
|
|
* isEmpty(''); // -> true
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function isEmpty(val: any): boolean;
|
|
*/
|
|
|
|
/* dependencies
|
|
* isArrLike isArr isStr isArgs keys
|
|
*/
|
|
|
|
exports = function exports(val) {
|
|
if (val == null) return true;
|
|
|
|
if (isArrLike(val) && (isArr(val) || isStr(val) || isArgs(val))) {
|
|
return val.length === 0;
|
|
}
|
|
|
|
return keys(val).length === 0;
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ isMatch ------------------------------ */
|
|
|
|
export var isMatch = _.isMatch = (function (exports) {
|
|
/* Check if keys and values in src are contained in obj.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|-------|----------------------------------|
|
|
* |obj |object |Object to inspect |
|
|
* |src |object |Object of property values to match|
|
|
* |return|boolean|True if object is match |
|
|
*/
|
|
|
|
/* example
|
|
* isMatch({a: 1, b: 2}, {a: 1}); // -> true
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function isMatch(obj: any, src: any): boolean;
|
|
*/
|
|
|
|
/* dependencies
|
|
* keys
|
|
*/
|
|
|
|
exports = function exports(obj, src) {
|
|
var _keys = keys(src),
|
|
len = _keys.length;
|
|
|
|
if (obj == null) return !len;
|
|
obj = Object(obj);
|
|
|
|
for (var i = 0; i < len; i++) {
|
|
var key = _keys[i];
|
|
if (src[key] !== obj[key] || !(key in obj)) return false;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ isObj ------------------------------ */
|
|
|
|
export var isObj = _.isObj = (function (exports) {
|
|
function _typeof(obj) {
|
|
if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
|
|
_typeof = function _typeof(obj) {
|
|
return typeof obj;
|
|
};
|
|
} else {
|
|
_typeof = function _typeof(obj) {
|
|
return obj &&
|
|
typeof Symbol === 'function' &&
|
|
obj.constructor === Symbol &&
|
|
obj !== Symbol.prototype
|
|
? 'symbol'
|
|
: typeof obj;
|
|
};
|
|
}
|
|
return _typeof(obj);
|
|
}
|
|
|
|
/* Check if value is the language type of Object.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|-------|--------------------------|
|
|
* |val |* |Value to check |
|
|
* |return|boolean|True if value is an object|
|
|
*
|
|
* [Language Spec](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
|
|
*/
|
|
|
|
/* example
|
|
* isObj({}); // -> true
|
|
* isObj([]); // -> true
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function isObj(val: any): boolean;
|
|
*/
|
|
exports = function exports(val) {
|
|
var type = _typeof(val);
|
|
|
|
return !!val && (type === 'function' || type === 'object');
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ isRegExp ------------------------------ */
|
|
|
|
export var isRegExp = _.isRegExp = (function (exports) {
|
|
/* Check if value is a regular expression.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|-------|-------------------------------------|
|
|
* |val |* |Value to check |
|
|
* |return|boolean|True if value is a regular expression|
|
|
*/
|
|
|
|
/* example
|
|
* isRegExp(/a/); // -> true
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function isRegExp(val: any): boolean;
|
|
*/
|
|
|
|
/* dependencies
|
|
* objToStr
|
|
*/
|
|
|
|
exports = function exports(val) {
|
|
return objToStr(val) === '[object RegExp]';
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ last ------------------------------ */
|
|
|
|
export var last = _.last = (function (exports) {
|
|
/* Get the last element of array.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|-----|-------------------------|
|
|
* |arr |array|The array to query |
|
|
* |return|* |The last element of array|
|
|
*/
|
|
|
|
/* example
|
|
* last([1, 2]); // -> 2
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function last(arr: any[]): any;
|
|
*/
|
|
exports = function exports(arr) {
|
|
var len = arr ? arr.length : 0;
|
|
if (len) return arr[len - 1];
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ matcher ------------------------------ */
|
|
|
|
export var matcher = _.matcher = (function (exports) {
|
|
/* Return a predicate function that checks if attrs are contained in an object.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |------|--------|----------------------------------|
|
|
* |attrs |object |Object of property values to match|
|
|
* |return|function|New predicate function |
|
|
*/
|
|
|
|
/* example
|
|
* const objects = [
|
|
* {a: 1, b: 2, c: 3 },
|
|
* {a: 4, b: 5, c: 6 }
|
|
* ];
|
|
* // filter(objects, matcher({a: 4, c: 6 }));
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function matcher(attrs: any): Function;
|
|
*/
|
|
|
|
/* dependencies
|
|
* extendOwn isMatch
|
|
*/
|
|
|
|
exports = function exports(attrs) {
|
|
attrs = extendOwn({}, attrs);
|
|
return function(obj) {
|
|
return isMatch(obj, attrs);
|
|
};
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ safeCb ------------------------------ */
|
|
|
|
export var safeCb = _.safeCb = (function (exports) {
|
|
/* Create callback based on input value.
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function safeCb(val?: any, ctx?: any, argCount?: number): Function;
|
|
*/
|
|
|
|
/* dependencies
|
|
* isFn isObj optimizeCb matcher identity
|
|
*/
|
|
|
|
exports = function exports(val, ctx, argCount) {
|
|
if (val == null) return identity;
|
|
if (isFn(val)) return optimizeCb(val, ctx, argCount);
|
|
if (isObj(val)) return matcher(val);
|
|
return function(key) {
|
|
return function(obj) {
|
|
return obj == null ? undefined : obj[key];
|
|
};
|
|
};
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ filter ------------------------------ */
|
|
|
|
export var filter = _.filter = (function (exports) {
|
|
/* Iterates over elements of collection, returning an array of all the values that pass a truth test.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |---------|--------|---------------------------------------|
|
|
* |obj |array |Collection to iterate over |
|
|
* |predicate|function|Function invoked per iteration |
|
|
* |[ctx] |* |Predicate context |
|
|
* |return |array |Array of all values that pass predicate|
|
|
*/
|
|
|
|
/* example
|
|
* filter([1, 2, 3, 4, 5], function (val) {
|
|
* return val % 2 === 0;
|
|
* }); // -> [2, 4]
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function filter<T>(
|
|
* list: types.List<T>,
|
|
* iterator: types.ListIterator<T, boolean>,
|
|
* context?: any
|
|
* ): T[];
|
|
* export declare function filter<T>(
|
|
* object: types.Dictionary<T>,
|
|
* iterator: types.ObjectIterator<T, boolean>,
|
|
* context?: any
|
|
* ): T[];
|
|
*/
|
|
|
|
/* dependencies
|
|
* safeCb each types
|
|
*/
|
|
|
|
exports = function exports(obj, predicate, ctx) {
|
|
var ret = [];
|
|
predicate = safeCb(predicate, ctx);
|
|
each(obj, function(val, idx, list) {
|
|
if (predicate(val, idx, list)) ret.push(val);
|
|
});
|
|
return ret;
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
/* ------------------------------ uniqId ------------------------------ */
|
|
|
|
export var uniqId = _.uniqId = (function (exports) {
|
|
/* Generate a globally-unique id.
|
|
*
|
|
* |Name |Type |Desc |
|
|
* |--------|------|------------------|
|
|
* |[prefix]|string|Id prefix |
|
|
* |return |string|Globally-unique id|
|
|
*/
|
|
|
|
/* example
|
|
* uniqId('eusita_'); // -> 'eustia_xxx'
|
|
*/
|
|
|
|
/* typescript
|
|
* export declare function uniqId(prefix?: string): string;
|
|
*/
|
|
var idCounter = 0;
|
|
|
|
exports = function exports(prefix) {
|
|
var id = ++idCounter + '';
|
|
return prefix ? prefix + id : id;
|
|
};
|
|
|
|
return exports;
|
|
})({});
|
|
|
|
export default _; |