eruda2
Version:
Console for Mobile Browsers
1,735 lines (1,401 loc) • 102 kB
JavaScript
// Built by eustia.
(function(root, factory)
{
if (typeof define === 'function' && define.amd)
{
define([], factory);
} else if (typeof module === 'object' && module.exports)
{
module.exports = factory();
} else { root.util = factory(); }
}(this, function ()
{
/* eslint-disable */
var _ = {};
if (typeof window === 'object' && window.util) _ = window.util;
/* ------------------------------ types ------------------------------ */
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;
* }
* type Fn<T> = (...args: any[]) => T;
* type AnyFn = Fn<any>;
* type PlainObj<T> = { [name: string]: T };
* }
* export declare const types: {};
*/
exports = {};
return exports;
})({});
/* ------------------------------ noop ------------------------------ */
var noop = _.noop = (function (exports) {
/* A no-operation function.
*/
/* example
* noop(); // Does nothing
*/
/* typescript
* export declare function noop(): void;
*/
exports = function() {};
return exports;
})({});
/* ------------------------------ isObj ------------------------------ */
var isObj = _.isObj = (function (exports) {
/* Check if value is the language type of Object.
*
* |Name |Desc |
* |------|--------------------------|
* |val |Value to check |
* |return|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(val) {
var type = typeof val;
return !!val && (type === 'function' || type === 'object');
};
return exports;
})({});
/* ------------------------------ has ------------------------------ */
var has = _.has = (function (exports) {
/* Checks if key is a direct property.
*
* |Name |Desc |
* |------|--------------------------------|
* |obj |Object to query |
* |key |Path to check |
* |return|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(obj, key) {
return hasOwnProp.call(obj, key);
};
return exports;
})({});
/* ------------------------------ keys ------------------------------ */
var keys = _.keys = (function (exports) {
/* Create an array of the own enumerable property names of object.
*
* |Name |Desc |
* |------|-----------------------|
* |obj |Object to query |
* |return|Array of property names|
*/
/* example
* keys({ a: 1 }); // -> ['a']
*/
/* typescript
* export declare function keys(obj: any): string[];
*/
/* dependencies
* has
*/
if (Object.keys && !false) {
exports = Object.keys;
} else {
exports = function(obj) {
var ret = [];
for (var key in obj) {
if (has(obj, key)) ret.push(key);
}
return ret;
};
}
return exports;
})({});
/* ------------------------------ idxOf ------------------------------ */
var idxOf = _.idxOf = (function (exports) {
/* Get the index at which the first occurrence of value.
*
* |Name |Desc |
* |---------|--------------------|
* |arr |Array to search |
* |val |Value to search for |
* |fromIdx=0|Index to search from|
* |return |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(arr, val, fromIdx) {
return Array.prototype.indexOf.call(arr, val, fromIdx);
};
return exports;
})({});
/* ------------------------------ isUndef ------------------------------ */
var isUndef = _.isUndef = (function (exports) {
/* Check if value is undefined.
*
* |Name |Desc |
* |------|--------------------------|
* |val |Value to check |
* |return|True if value is undefined|
*/
/* example
* isUndef(void 0); // -> true
* isUndef(null); // -> false
*/
/* typescript
* export declare function isUndef(val: any): boolean;
*/
exports = function(val) {
return val === void 0;
};
return exports;
})({});
/* ------------------------------ create ------------------------------ */
var create = _.create = (function (exports) {
/* Create new object using given object as prototype.
*
* |Name |Desc |
* |------|-----------------------|
* |proto |Prototype of new object|
* |return|Created object |
*/
/* example
* const obj = create({ a: 1 });
* console.log(obj.a); // -> 1
*/
/* typescript
* export declare function create(proto?: object): any;
*/
/* dependencies
* isObj
*/
exports = function(proto) {
if (!isObj(proto)) return {};
if (objCreate && !false) return objCreate(proto);
function noop() {}
noop.prototype = proto;
return new noop();
};
var objCreate = Object.create;
return exports;
})({});
/* ------------------------------ inherits ------------------------------ */
var inherits = _.inherits = (function (exports) {
/* Inherit the prototype methods from one constructor into another.
*
* |Name |Desc |
* |----------|-----------|
* |Class |Child Class|
* |SuperClass|Super Class|
*/
/* example
* function People(name) {
* this._name = name;
* }
* People.prototype = {
* getName: function() {
* return this._name;
* }
* };
* function Student(name) {
* this._name = name;
* }
* inherits(Student, People);
* const s = new Student('RedHood');
* s.getName(); // -> 'RedHood'
*/
/* typescript
* export declare function inherits(
* Class: types.AnyFn,
* SuperClass: types.AnyFn
* ): void;
*/
/* dependencies
* create types
*/
exports = function(Class, SuperClass) {
Class.prototype = create(SuperClass.prototype);
};
return exports;
})({});
/* ------------------------------ ucs2 ------------------------------ */
var ucs2 = _.ucs2 = (function (exports) {
/* UCS-2 encoding and decoding.
*
* ### encode
*
* Create a string using an array of code point values.
*
* |Name |Desc |
* |------|--------------------|
* |arr |Array of code points|
* |return|Encoded string |
*
* ### decode
*
* Create an array of code point values using a string.
*
* |Name |Desc |
* |------|--------------------|
* |str |Input string |
* |return|Array of code points|
*/
/* example
* ucs2.encode([0x61, 0x62, 0x63]); // -> 'abc'
* ucs2.decode('abc'); // -> [0x61, 0x62, 0x63]
* '𝌆'.length; // -> 2
* ucs2.decode('𝌆').length; // -> 1
*/
/* typescript
* export declare const ucs2: {
* encode(arr: number[]): string;
* decode(str: string): number[];
* };
*/
// https://mathiasbynens.be/notes/javascript-encoding
exports = {
encode: function(arr) {
return String.fromCodePoint.apply(String, arr);
},
decode: function(str) {
var ret = [];
var i = 0;
var len = str.length;
while (i < len) {
var c = str.charCodeAt(i++); // A high surrogate
if (c >= 0xd800 && c <= 0xdbff && i < len) {
var tail = str.charCodeAt(i++); // nextC >= 0xDC00 && nextC <= 0xDFFF
if ((tail & 0xfc00) === 0xdc00) {
// C = (H - 0xD800) * 0x400 + L - 0xDC00 + 0x10000
ret.push(((c & 0x3ff) << 10) + (tail & 0x3ff) + 0x10000);
} else {
ret.push(c);
i--;
}
} else {
ret.push(c);
}
}
return ret;
}
};
return exports;
})({});
/* ------------------------------ utf8 ------------------------------ */
var utf8 = _.utf8 = (function (exports) {
/* UTF-8 encoding and decoding.
*
* ### encode
*
* Turn any UTF-8 decoded string into UTF-8 encoded string.
*
* |Name |Desc |
* |------|----------------|
* |str |String to encode|
* |return|Encoded string |
*
* ### decode
*
* Turn any UTF-8 encoded string into UTF-8 decoded string.
*
* |Name |Desc |
* |----------|----------------------|
* |str |String to decode |
* |safe=false|Suppress error if true|
* |return |Decoded string |
*/
/* example
* utf8.encode('\uD800\uDC00'); // -> '\xF0\x90\x80\x80'
* utf8.decode('\xF0\x90\x80\x80'); // -> '\uD800\uDC00'
*/
/* typescript
* export declare const utf8: {
* encode(str: string): string;
* decode(str: string, safe?: boolean): string;
* };
*/
/* dependencies
* ucs2
*/ // https://encoding.spec.whatwg.org/#utf-8
exports = {
encode: function(str) {
var codePoints = ucs2.decode(str);
var byteArr = '';
for (var i = 0, len = codePoints.length; i < len; i++) {
byteArr += encodeCodePoint(codePoints[i]);
}
return byteArr;
},
decode: function(str, safe) {
byteArr = ucs2.decode(str);
byteIdx = 0;
byteCount = byteArr.length;
codePoint = 0;
bytesSeen = 0;
bytesNeeded = 0;
lowerBoundary = 0x80;
upperBoundary = 0xbf;
var codePoints = [];
var tmp;
while ((tmp = decodeCodePoint(safe)) !== false) {
codePoints.push(tmp);
}
return ucs2.encode(codePoints);
}
};
var fromCharCode = String.fromCharCode;
function encodeCodePoint(codePoint) {
// U+0000 to U+0080, ASCII code point
if ((codePoint & 0xffffff80) === 0) {
return fromCharCode(codePoint);
}
var ret = '',
count,
offset; // U+0080 to U+07FF, inclusive
if ((codePoint & 0xfffff800) === 0) {
count = 1;
offset = 0xc0;
} else if ((codePoint & 0xffff0000) === 0) {
// U+0800 to U+FFFF, inclusive
count = 2;
offset = 0xe0;
} else if ((codePoint & 0xffe00000) == 0) {
// U+10000 to U+10FFFF, inclusive
count = 3;
offset = 0xf0;
}
ret += fromCharCode((codePoint >> (6 * count)) + offset);
while (count > 0) {
var tmp = codePoint >> (6 * (count - 1));
ret += fromCharCode(0x80 | (tmp & 0x3f));
count--;
}
return ret;
}
var byteArr,
byteIdx,
byteCount,
codePoint,
bytesSeen,
bytesNeeded,
lowerBoundary,
upperBoundary;
function decodeCodePoint(safe) {
/* eslint-disable no-constant-condition */
while (true) {
if (byteIdx >= byteCount && bytesNeeded) {
if (safe) return goBack();
throw new Error('Invalid byte index');
}
if (byteIdx === byteCount) return false;
var byte = byteArr[byteIdx];
byteIdx++;
if (!bytesNeeded) {
// 0x00 to 0x7F
if ((byte & 0x80) === 0) {
return byte;
} // 0xC2 to 0xDF
if ((byte & 0xe0) === 0xc0) {
bytesNeeded = 1;
codePoint = byte & 0x1f;
} else if ((byte & 0xf0) === 0xe0) {
// 0xE0 to 0xEF
if (byte === 0xe0) lowerBoundary = 0xa0;
if (byte === 0xed) upperBoundary = 0x9f;
bytesNeeded = 2;
codePoint = byte & 0xf;
} else if ((byte & 0xf8) === 0xf0) {
// 0xF0 to 0xF4
if (byte === 0xf0) lowerBoundary = 0x90;
if (byte === 0xf4) upperBoundary = 0x8f;
bytesNeeded = 3;
codePoint = byte & 0x7;
} else {
if (safe) return goBack();
throw new Error('Invalid UTF-8 detected');
}
continue;
}
if (byte < lowerBoundary || byte > upperBoundary) {
if (safe) {
byteIdx--;
return goBack();
}
throw new Error('Invalid continuation byte');
}
lowerBoundary = 0x80;
upperBoundary = 0xbf;
codePoint = (codePoint << 6) | (byte & 0x3f);
bytesSeen++;
if (bytesSeen !== bytesNeeded) continue;
var tmp = codePoint;
codePoint = 0;
bytesNeeded = 0;
bytesSeen = 0;
return tmp;
}
}
function goBack() {
var start = byteIdx - bytesSeen - 1;
byteIdx = start + 1;
codePoint = 0;
bytesNeeded = 0;
bytesSeen = 0;
lowerBoundary = 0x80;
upperBoundary = 0xbf;
return byteArr[start];
}
return exports;
})({});
/* ------------------------------ restArgs ------------------------------ */
var restArgs = _.restArgs = (function (exports) {
/* This accumulates the arguments passed into an array, after a given index.
*
* |Name |Desc |
* |----------|---------------------------------------|
* |function |Function that needs rest parameters |
* |startIndex|The start index to accumulates |
* |return |Generated function with rest parameters|
*/
/* example
* const paramArr = restArgs(function(rest) {
* return rest;
* });
* paramArr(1, 2, 3, 4); // -> [1, 2, 3, 4]
*/
/* typescript
* export declare function restArgs(
* fn: types.AnyFn,
* startIndex?: number
* ): types.AnyFn;
*/
/* dependencies
* types
*/
exports = function(fn, startIdx) {
startIdx = startIdx == null ? fn.length - 1 : +startIdx;
return function() {
var len = Math.max(arguments.length - startIdx, 0);
var rest = new Array(len);
var i;
for (i = 0; i < len; i++) {
rest[i] = arguments[i + startIdx];
} // Call runs faster than apply.
switch (startIdx) {
case 0:
return fn.call(this, rest);
case 1:
return fn.call(this, arguments[0], rest);
case 2:
return fn.call(this, arguments[0], arguments[1], rest);
}
var args = new Array(startIdx + 1);
for (i = 0; i < startIdx; i++) {
args[i] = arguments[i];
}
args[startIdx] = rest;
return fn.apply(this, args);
};
};
return exports;
})({});
/* ------------------------------ optimizeCb ------------------------------ */
var optimizeCb = _.optimizeCb = (function (exports) {
/* Used for function context binding.
*/
/* typescript
* export declare function optimizeCb(
* fn: types.AnyFn,
* ctx: any,
* argCount?: number
* ): types.AnyFn;
*/
/* dependencies
* isUndef types
*/
exports = function(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;
})({});
/* ------------------------------ endWith ------------------------------ */
var endWith = _.endWith = (function (exports) {
/* Check if string ends with the given target string.
*
* |Name |Desc |
* |------|-------------------------------|
* |str |The string to search |
* |suffix|String suffix |
* |return|True if string ends with target|
*/
/* example
* endWith('ab', 'b'); // -> true
*/
/* typescript
* export declare function endWith(str: string, suffix: string): boolean;
*/
exports = function(str, suffix) {
var idx = str.length - suffix.length;
return idx >= 0 && str.indexOf(suffix, idx) === idx;
};
return exports;
})({});
/* ------------------------------ toStr ------------------------------ */
var toStr = _.toStr = (function (exports) {
/* Convert value to a string.
*
* |Name |Desc |
* |------|----------------|
* |val |Value to convert|
* |return|Result 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(val) {
return val == null ? '' : val.toString();
};
return exports;
})({});
/* ------------------------------ escapeJsStr ------------------------------ */
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 |Desc |
* |------|----------------|
* |str |String to escape|
* |return|Escaped string |
*/
/* example
* escapeJsStr('"\n'); // -> '\\"\\\\n'
*/
/* typescript
* export declare function escapeJsStr(str: string): string;
*/
/* dependencies
* toStr
*/
exports = function(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;
})({});
/* ------------------------------ evalCss ------------------------------ */
_.evalCss = (function (exports) {
/* Load css into page.
*
* |Name|Desc |
* |----|--------|
* |css |Css code|
*/
/* example
* evalCss('body{background:#08c}');
*/
/* typescript
* export declare function evalCss(css: string): void;
*/
exports = function(css) {
var style = document.createElement('style');
style.textContent = css;
style.type = 'text/css';
document.head.appendChild(style);
};
return exports;
})({});
/* ------------------------------ identity ------------------------------ */
var identity = _.identity = (function (exports) {
/* Return the first argument given.
*
* |Name |Desc |
* |------|-----------|
* |val |Any value |
* |return|Given value|
*/
/* example
* identity('a'); // -> 'a'
*/
/* typescript
* export declare function identity<T>(val: T): T;
*/
exports = function(val) {
return val;
};
return exports;
})({});
/* ------------------------------ objToStr ------------------------------ */
var objToStr = _.objToStr = (function (exports) {
/* Alias of Object.prototype.toString.
*
* |Name |Desc |
* |------|------------------------------------|
* |val |Source value |
* |return|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(val) {
return ObjToStr.call(val);
};
return exports;
})({});
/* ------------------------------ isArgs ------------------------------ */
var isArgs = _.isArgs = (function (exports) {
/* Check if value is classified as an arguments object.
*
* |Name |Desc |
* |------|------------------------------------|
* |val |Value to check |
* |return|True if value is an arguments object|
*/
/* example
* isArgs(
* (function() {
* return arguments;
* })()
* ); // -> true
*/
/* typescript
* export declare function isArgs(val: any): boolean;
*/
/* dependencies
* objToStr
*/
exports = function(val) {
return objToStr(val) === '[object Arguments]';
};
return exports;
})({});
/* ------------------------------ isArr ------------------------------ */
var isArr = _.isArr = (function (exports) {
/* Check if value is an `Array` object.
*
* |Name |Desc |
* |------|----------------------------------|
* |val |Value to check |
* |return|True if value is an `Array` object|
*/
/* example
* isArr([]); // -> true
* isArr({}); // -> false
*/
/* typescript
* export declare function isArr(val: any): boolean;
*/
/* dependencies
* objToStr
*/
if (Array.isArray && !false) {
exports = Array.isArray;
} else {
exports = function(val) {
return objToStr(val) === '[object Array]';
};
}
return exports;
})({});
/* ------------------------------ castPath ------------------------------ */
var castPath = _.castPath = (function (exports) {
/* Cast value into a property path array.
*
* |Name |Desc |
* |------|-------------------|
* |path |Value to inspect |
* |obj |Object to query |
* |return|Property path array|
*/
/* example
* castPath('a.b.c'); // -> ['a', 'b', 'c']
* castPath(['a']); // -> ['a']
* castPath('a[0].b'); // -> ['a', '0', 'b']
* castPath('a.b.c', { 'a.b.c': true }); // -> ['a.b.c']
*/
/* typescript
* export declare function castPath(path: string | string[], obj?: any): string[];
*/
/* dependencies
* has isArr
*/
exports = function(str, obj) {
if (isArr(str)) return str;
if (obj && has(obj, str)) return [str];
var ret = [];
str.replace(regPropName, function(match, number, quote, str) {
ret.push(quote ? str.replace(regEscapeChar, '$1') : number || match);
});
return ret;
}; // Lodash _stringToPath
var regPropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
var regEscapeChar = /\\(\\)?/g;
return exports;
})({});
/* ------------------------------ safeGet ------------------------------ */
var safeGet = _.safeGet = (function (exports) {
/* Get object property, don't throw undefined error.
*
* |Name |Desc |
* |------|-------------------------|
* |obj |Object to query |
* |path |Path of property to get |
* |return|Target value or undefined|
*/
/* example
* const obj = { a: { aa: { aaa: 1 } } };
* safeGet(obj, 'a.aa.aaa'); // -> 1
* safeGet(obj, ['a', 'aa']); // -> {aaa: 1}
* safeGet(obj, 'a.b'); // -> undefined
*/
/* typescript
* export declare function safeGet(obj: any, path: string | string[]): any;
*/
/* dependencies
* isUndef castPath
*/
exports = function(obj, path) {
path = castPath(path, obj);
var prop;
prop = path.shift();
while (!isUndef(prop)) {
obj = obj[prop];
if (obj == null) return;
prop = path.shift();
}
return obj;
};
return exports;
})({});
/* ------------------------------ flatten ------------------------------ */
var flatten = _.flatten = (function (exports) {
/* Recursively flatten an array.
*
* |Name |Desc |
* |------|-------------------|
* |arr |Array to flatten |
* |return|New flattened array|
*/
/* example
* flatten(['a', ['b', ['c']], 'd', ['e']]); // -> ['a', 'b', 'c', 'd', 'e']
*/
/* typescript
* export declare function flatten(arr: any[]): any[];
*/
/* dependencies
* isArr
*/
exports = function(arr) {
return flat(arr, []);
};
function flat(arr, res) {
var len = arr.length,
i = -1,
cur;
while (len--) {
cur = arr[++i];
isArr(cur) ? flat(cur, res) : res.push(cur);
}
return res;
}
return exports;
})({});
/* ------------------------------ isFn ------------------------------ */
var isFn = _.isFn = (function (exports) {
/* Check if value is a function.
*
* |Name |Desc |
* |------|---------------------------|
* |val |Value to check |
* |return|True if value is a function|
*
* Generator function is also classified as true.
*/
/* example
* isFn(function() {}); // -> true
* isFn(function*() {}); // -> true
* isFn(async function() {}); // -> true
*/
/* typescript
* export declare function isFn(val: any): boolean;
*/
/* dependencies
* objToStr
*/
exports = function(val) {
var objStr = objToStr(val);
return (
objStr === '[object Function]' ||
objStr === '[object GeneratorFunction]' ||
objStr === '[object AsyncFunction]'
);
};
return exports;
})({});
/* ------------------------------ getProto ------------------------------ */
var getProto = _.getProto = (function (exports) {
/* Get prototype of an object.
*
* |Name |Desc |
* |------|---------------------------------------------|
* |obj |Target object |
* |return|Prototype of given object, null if not exists|
*/
/* example
* const a = {};
* getProto(Object.create(a)); // -> a
*/
/* typescript
* export declare function getProto(obj: any): any;
*/
/* dependencies
* isObj isFn
*/
var getPrototypeOf = Object.getPrototypeOf;
var ObjectCtr = {}.constructor;
exports = function(obj) {
if (!isObj(obj)) return;
if (getPrototypeOf && !false) return getPrototypeOf(obj);
var proto = obj.__proto__;
if (proto || proto === null) return proto;
if (isFn(obj.constructor)) return obj.constructor.prototype;
if (obj instanceof ObjectCtr) return ObjectCtr.prototype;
};
return exports;
})({});
/* ------------------------------ isMiniProgram ------------------------------ */
var isMiniProgram = _.isMiniProgram = (function (exports) {
/* Check if running in wechat mini program.
*/
/* example
* console.log(isMiniProgram); // -> true if running in mini program.
*/
/* typescript
* export declare const isMiniProgram: boolean;
*/
/* dependencies
* isFn
*/
/* eslint-disable no-undef */
exports = typeof wx !== 'undefined' && isFn(wx.openLocation);
return exports;
})({});
/* ------------------------------ isNum ------------------------------ */
var isNum = _.isNum = (function (exports) {
/* Check if value is classified as a Number primitive or object.
*
* |Name |Desc |
* |------|-------------------------------------|
* |val |Value to check |
* |return|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(val) {
return objToStr(val) === '[object Number]';
};
return exports;
})({});
/* ------------------------------ isArrLike ------------------------------ */
var isArrLike = _.isArrLike = (function (exports) {
/* Check if value is array-like.
*
* |Name |Desc |
* |------|---------------------------|
* |val |Value to check |
* |return|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(val) {
if (!val) return false;
var len = val.length;
return isNum(len) && len >= 0 && len <= MAX_ARR_IDX && !isFn(val);
};
return exports;
})({});
/* ------------------------------ each ------------------------------ */
var each = _.each = (function (exports) {
/* Iterate over elements of collection and invokes iterator for each element.
*
* |Name |Desc |
* |--------|------------------------------|
* |obj |Collection to iterate over |
* |iterator|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(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 ------------------------------ */
var createAssigner = _.createAssigner = (function (exports) {
/* Used to create extend, extendOwn and defaults.
*
* |Name |Desc |
* |--------|------------------------------|
* |keysFn |Function to get object keys |
* |defaults|No override when set to true |
* |return |Result function, extend... |
*/
/* typescript
* export declare function createAssigner(
* keysFn: types.AnyFn,
* defaults: boolean
* ): types.AnyFn;
*/
/* dependencies
* isUndef each types
*/
exports = function(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;
})({});
/* ------------------------------ extendOwn ------------------------------ */
var extendOwn = _.extendOwn = (function (exports) {
/* Like extend, but only copies own properties over to the destination object.
*
* |Name |Desc |
* |-----------|------------------|
* |destination|Destination object|
* |...sources |Sources objects |
* |return |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;
})({});
/* ------------------------------ values ------------------------------ */
var values = _.values = (function (exports) {
/* Create an array of the own enumerable property values of object.
*
* |Name |Desc |
* |------|------------------------|
* |obj |Object to query |
* |return|Array of property values|
*/
/* example
* values({ one: 1, two: 2 }); // -> [1, 2]
*/
/* typescript
* export declare function values(obj: any): any[];
*/
/* dependencies
* each
*/
exports = function(obj) {
var ret = [];
each(obj, function(val) {
ret.push(val);
});
return ret;
};
return exports;
})({});
/* ------------------------------ isStr ------------------------------ */
var isStr = _.isStr = (function (exports) {
/* Check if value is a string primitive.
*
* |Name |Desc |
* |------|-----------------------------------|
* |val |Value to check |
* |return|True if value is a string primitive|
*/
/* example
* isStr('licia'); // -> true
*/
/* typescript
* export declare function isStr(val: any): boolean;
*/
/* dependencies
* objToStr
*/
exports = function(val) {
return objToStr(val) === '[object String]';
};
return exports;
})({});
/* ------------------------------ contain ------------------------------ */
var contain = _.contain = (function (exports) {
/* Check if the value is present in the list.
*
* |Name |Desc |
* |------|------------------------------------|
* |target|Target object |
* |val |Value to check |
* |return|True if value is present in the list|
*/
/* example
* contain([1, 2, 3], 1); // -> true
* contain({ a: 1, b: 2 }, 1); // -> true
* contain('abc', 'a'); // -> true
*/
/* typescript
* export declare function contain(arr: any[] | {} | string, val: any): boolean;
*/
/* dependencies
* idxOf isStr isArrLike values
*/
exports = function(arr, val) {
if (isStr(arr)) return arr.indexOf(val) > -1;
if (!isArrLike(arr)) arr = values(arr);
return idxOf(arr, val) >= 0;
};
return exports;
})({});
/* ------------------------------ isBuffer ------------------------------ */
var isBuffer = _.isBuffer = (function (exports) {
/* Check if value is a buffer.
*
* |Name |Desc |
* |------|-------------------------|
* |val |The value to check |
* |return|True if value is a buffer|
*/
/* example
* isBuffer(new Buffer(4)); // -> true
*/
/* typescript
* export declare function isBuffer(val: any): boolean;
*/
/* dependencies
* isFn
*/
exports = function(val) {
if (val == null) return false;
if (val._isBuffer) return true;
return (
val.constructor &&
isFn(val.constructor.isBuffer) &&
val.constructor.isBuffer(val)
);
};
return exports;
})({});
/* ------------------------------ isEmpty ------------------------------ */
var isEmpty = _.isEmpty = (function (exports) {
/* Check if value is an empty object or array.
*
* |Name |Desc |
* |------|----------------------|
* |val |Value to check |
* |return|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(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 ------------------------------ */
var isMatch = _.isMatch = (function (exports) {
/* Check if keys and values in src are contained in obj.
*
* |Name |Desc |
* |------|----------------------------------|
* |obj |Object to inspect |
* |src |Object of property values to match|
* |return|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(obj, src) {
var _keys = keys(src);
var 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;
})({});
/* ------------------------------ isNaN ------------------------------ */
var isNaN = _.isNaN = (function (exports) {
/* Check if value is an NaN.
*
* |Name |Desc |
* |------|-----------------------|
* |val |Value to check |
* |return|True if value is an NaN|
*
* Undefined is not an NaN, different from global isNaN function.
*/
/* example
* isNaN(0); // -> false
* isNaN(NaN); // -> true
*/
/* typescript
* export declare function isNaN(val: any): boolean;
*/
/* dependencies
* isNum
*/
exports = function(val) {
return isNum(val) && val !== +val;
};
return exports;
})({});
/* ------------------------------ isNil ------------------------------ */
var isNil = _.isNil = (function (exports) {
/* Check if value is null or undefined, the same as value == null.
*
* |Name |Desc |
* |------|----------------------------------|
* |val |Value to check |
* |return|True if value is null or undefined|
*/
/* example
* isNil(null); // -> true
* isNil(void 0); // -> true
* isNil(undefined); // -> true
* isNil(false); // -> false
* isNil(0); // -> false
* isNil([]); // -> false
*/
/* typescript
* export declare function isNil(val: any): boolean;
*/
exports = function(val) {
return val == null;
};
return exports;
})({});
/* ------------------------------ isPromise ------------------------------ */
var isPromise = _.isPromise = (function (exports) {
/* Check if value looks like a promise.
*
* |Name |Desc |
* |------|----------------------------------|
* |val |Value to check |
* |return|True if value looks like a promise|
*/
/* example
* isPromise(new Promise(function() {})); // -> true
* isPromise({}); // -> false
*/
/* typescript
* export declare function isPromise(val: any): boolean;
*/
/* dependencies
* isObj isFn
*/
exports = function(val) {
return isObj(val) && isFn(val.then) && isFn(val.catch);
};
return exports;
})({});
/* ------------------------------ lowerCase ------------------------------ */
var lowerCase = _.lowerCase = (function (exports) {
/* Convert string to lower case.
*
* |Name |Desc |
* |------|------------------|
* |str |String to convert |
* |return|Lower cased string|
*/
/* example
* lowerCase('TEST'); // -> 'test'
*/
/* typescript
* export declare function lowerCase(str: string): string;
*/
/* dependencies
* toStr
*/
exports = function(str) {
return toStr(str).toLocaleLowerCase();
};
return exports;
})({});
/* ------------------------------ ltrim ------------------------------ */
var ltrim = _.ltrim = (function (exports) {
/* Remove chars or white-spaces from beginning of string.
*
* |Name |Desc |
* |------|------------------|
* |str |String to trim |
* |chars |Characters to trim|
* |return|Trimmed string |
*/
/* example
* ltrim(' abc '); // -> 'abc '
* ltrim('_abc_', '_'); // -> 'abc_'
* ltrim('_abc_', ['a', '_']); // -> 'bc_'
*/
/* typescript
* export declare function ltrim(str: string, chars?: string | string[]): string;
*/
var regSpace = /^\s+/;
exports = function(str, chars) {
if (chars == null) return str.replace(regSpace, '');
var start = 0;
va