diff --git a/doc/TOOL_API.md b/doc/TOOL_API.md index 4d282f9..447c5e1 100644 --- a/doc/TOOL_API.md +++ b/doc/TOOL_API.md @@ -159,6 +159,21 @@ info.add('title', 'content'); info.add('location', () => location.href); ``` +### get + +Get info or infos. + +|Name |Type |Desc | +|------|---------------|------------| +|name |string |Info name | +|return|string function|Info content| + +```javascript +info.add('title', 'content') +info.get(); // -> [{name: 'title', val: 'content'}] +info.get('title') // -> 'content' +``` + ### remove Remove specified info. diff --git a/doc/UTIL_API.md b/doc/UTIL_API.md index 88368d9..4bf4a90 100644 --- a/doc/UTIL_API.md +++ b/doc/UTIL_API.md @@ -1,7 +1,7 @@ -# Eruda Util Documentation - -## $ - +# Eruda Util Documentation + +## $ + jQuery like style dom manipulator. ### Available methods @@ -19,10 +19,10 @@ $btn.on('click', function () { // Do something... }); -``` - -## $attr - +``` + +## $attr + Element attribute manipulation. Get the value of an attribute for the first element in the set of matched elements. @@ -63,10 +63,10 @@ $attr('#test', { 'attr1': 'test', 'attr2': 'test' }); -``` - -## $class - +``` + +## $class + Element class manipulations. ### add @@ -114,10 +114,10 @@ $class.remove('#test', 'class1'); $class.has('#test', 'class1'); // -> false $class.toggle('#test', 'class1'); $class.has('#test', 'class1'); // -> true -``` - -## $css - +``` + +## $css + Element css manipulation. Get the computed style properties for the first element in the set of matched elements. @@ -148,18 +148,18 @@ $css('#test', { }); $css('#test', 'display', 'block'); $css('#test', 'color'); // -> #fff -``` - -## $data - +``` + +## $data + Wrapper of $attr, adds data- prefix to keys. ```javascript $data('#test', 'attr1', 'eustia'); -``` - -## $event - +``` + +## $event + bind events to certain dom elements. ```javascript @@ -169,10 +169,10 @@ function clickHandler() } $event.on('#test', 'click', clickHandler); $event.off('#test', 'click', clickHandler); -``` - -## $insert - +``` + +## $insert + Insert html on different position. ### before @@ -206,10 +206,10 @@ $insert.prepend('#test', '
licia
'); // ->
licia
$insert.append('#test', '
licia
'); // ->
licia
-``` - -## $offset - +``` + +## $offset + Get the position of the element in document. |Name |Type |Desc | @@ -218,10 +218,10 @@ Get the position of the element in document. ```javascript $offset('#test'); // -> {left: 0, top: 0, width: 0, height: 0} -``` - -## $property - +``` + +## $property + Element property html, text, val getter and setter. ### html @@ -243,10 +243,10 @@ set the value of every matched element. ```javascript $property.html('#test', 'licia'); $property.html('#test'); // -> licia -``` - -## $remove - +``` + +## $remove + Remove the set of matched elements from the DOM. |Name |Type |Desc | @@ -255,10 +255,10 @@ Remove the set of matched elements from the DOM. ```javascript $remove('#test'); -``` - -## $safeEls - +``` + +## $safeEls + Convert value into an array, if it's a string, do querySelector. |Name |Type |Desc | @@ -268,10 +268,10 @@ Convert value into an array, if it's a string, do querySelector. ```javascript $safeEls('.test'); // -> Array of elements with test class -``` - -## $show - +``` + +## $show + Show elements. |Name |Type |Desc | @@ -280,10 +280,10 @@ Show elements. ```javascript $show('#test'); -``` - -## Class - +``` + +## Class + Create JavaScript class. |Name |Type |Desc | @@ -326,10 +326,10 @@ var Student = People.extend({ var a = new Student('allen', 17, 'Hogwarts'); a.introduce(); // -> 'I am allen, 17 years old. \n I study at Hogwarts.' Student.is(a); // -> true -``` - -## Emitter - +``` + +## Emitter + Event emitter class which provides observer pattern. ### on @@ -371,10 +371,10 @@ var event = new Emitter(); event.on('test', function () { console.log('test') }); event.emit('test'); // Logs out 'test'. Emitter.mixin({}); -``` - -## Enum - +``` + +## Enum + Enum type implementation. ### constructor @@ -396,10 +396,10 @@ if (val === importance.CRITICAL) { // Do something. } -``` - -## LocalStore - +``` + +## LocalStore + LocalStorage wrapper. Extend from Store. @@ -414,10 +414,10 @@ Extend from Store. ```javascript var store = new LocalStore('licia'); store.set('name', 'licia'); -``` - -## Logger - +``` + +## Logger + Simple logger with level filter. ### constructor @@ -466,10 +466,10 @@ logger.on('debug', function (argList) { // Affected by log level. }); -``` - -## MutationObserver - +``` + +## MutationObserver + Safe MutationObserver, does nothing if MutationObserver is not supported. ```javascript @@ -479,10 +479,10 @@ var observer = new MutationObserver(function (mutations) }); observer.observe(document.htmlElement); observer.disconnect(); -``` - -## Select - +``` + +## Select + Simple wrapper of querySelectorAll to make dom selection easier. ### constructor @@ -513,10 +513,10 @@ $test.find('.test').each(function (idx, element) { // Manipulate dom nodes }); -``` - -## Store - +``` + +## Store + Memory storage. Extend from Emitter. @@ -593,10 +593,10 @@ store.on('change', function (key, newVal, oldVal) { // It triggers whenever set is called. }); -``` - -## Url - +``` + +## Url + Simple url manipulator. ### constructor @@ -666,10 +666,10 @@ console.log(url.port); // -> '8080' url.query.foo = 'bar'; url.rmQuery('eruda'); utl.toString(); // -> 'http://example.com:8080/?foo=bar' -``` - -## ajax - +``` + +## ajax + Perform an asynchronous HTTP request. |Name |Type |Desc | @@ -678,7 +678,7 @@ Perform an asynchronous HTTP request. Available options: -|Name |Type |Desc | +|Name |Type |Desc | |---------------------------------------------|-------------|---------------------------| |url |string |Request url | |data |string object|Request data | @@ -720,10 +720,10 @@ ajax.get('http://example.com', {}, function (data) { // ... }); -``` - -## allKeys - +``` + +## allKeys + Retrieve all the names of object's own and inherited properties. |Name |Type |Desc | @@ -737,10 +737,10 @@ Retrieve all the names of object's own and inherited properties. var obj = Object.create({zero: 0}); obj.one = 1; allKeys(obj) // -> ['zero', 'one'] -``` - -## before - +``` + +## before + Create a function that invokes less than n times. |Name |Type |Desc | @@ -754,10 +754,10 @@ Subsequent calls to the created function return the result of the last fn invoca ```javascript $(element).on('click', before(5, function() {})); // -> allow function to be call 4 times at last. -``` - -## camelCase - +``` + +## camelCase + Convert string to "camelCase". |Name |Type |Desc | @@ -770,10 +770,10 @@ camelCase('foo-bar'); // -> fooBar camelCase('foo bar'); // -> fooBar camelCase('foo_bar'); // -> fooBar camelCase('foo.bar'); // -> fooBar -``` - -## castPath - +``` + +## castPath + Cast value into a property path array. |Name |Type |Desc | @@ -787,10 +787,10 @@ 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'] -``` - -## chunk - +``` + +## chunk + Split array into groups the length of given size. |Name |Type |Desc | @@ -802,10 +802,10 @@ Split array into groups the length of given size. chunk([1, 2, 3, 4], 2); // -> [[1, 2], [3, 4]] chunk([1, 2, 3, 4], 3); // -> [[1, 2, 3], [4]] chunk([1, 2, 3, 4]); // -> [[1], [2], [3], [4]] -``` - -## clamp - +``` + +## clamp + Clamp number within the inclusive lower and upper bounds. |Name |Type |Desc | @@ -821,10 +821,10 @@ clamp(10, -5, 5); // -> 5 clamp(2, -5, 5); // -> 2 clamp(10, 5); // -> 5 clamp(2, 5); // -> 2 -``` - -## clone - +``` + +## clone + Create a shallow-copied clone of the provided plain object. Any nested objects or arrays will be copied by reference, not duplicated. @@ -836,10 +836,25 @@ Any nested objects or arrays will be copied by reference, not duplicated. ```javascript clone({name: 'eustia'}); // -> {name: 'eustia'} -``` +``` + +## cloneDeep + +Recursively clone value. -## concat +|Name |Type|Desc | +|------|----|-----------------| +|val |* |Value to clone | +|return|* |Deep cloned Value| +```javascript +var obj = [{a: 1}, {a: 2}]; +var obj2 = cloneDeep(obj); +console.log(obj[0] === obj2[1]); // -> false +``` + +## concat + Concat multiple arrays into a single array. |Name |Type |Desc | @@ -849,10 +864,10 @@ Concat multiple arrays into a single array. ```javascript concat([1, 2], [3], [4, 5]); // -> [1, 2, 3, 4, 5] -``` - -## contain - +``` + +## contain + Check if the value is present in the list. |Name |Type |Desc | @@ -864,10 +879,10 @@ Check if the value is present in the list. ```javascript contain([1, 2, 3], 1); // -> true contain({a: 1, b: 2}, 1); // -> true -``` - -## cookie - +``` + +## cookie + Simple api for handling browser cookies. ### get @@ -904,20 +919,20 @@ Remove cookie value. cookie.set('a', '1', {path: '/'}); cookie.get('a'); // -> '1' cookie.remove('a'); -``` - -## createAssigner - +``` + +## createAssigner + 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... | - -## dateFormat - +|return |function|Result function, extend... | + +## dateFormat + Simple but extremely useful date format function. |Name |Type |Desc | @@ -961,10 +976,10 @@ Simple but extremely useful date format function. dateFormat('isoDate'); // -> 2016-11-19 dateFormat('yyyy-mm-dd HH:MM:ss'); // -> 2016-11-19 19:00:04 dateFormat(new Date(), 'yyyy-mm-dd'); // -> 2016-11-19 -``` - -## decodeUriComponent - +``` + +## decodeUriComponent + Better decodeURIComponent that does not throw if input is invalid. |Name |Type |Desc | @@ -975,10 +990,10 @@ Better decodeURIComponent that does not throw if input is invalid. ```javascript decodeUriComponent('%%25%'); // -> '%%%' decodeUriComponent('%E0%A4%A'); // -> '\xE0\xA4%A' -``` - -## defaults - +``` + +## defaults + Fill in undefined properties in object with the first value present in the following list of defaults objects. |Name |Type |Desc | @@ -989,10 +1004,10 @@ Fill in undefined properties in object with the first value present in the follo ```javascript defaults({name: 'RedHood'}, {name: 'Unknown', age: 24}); // -> {name: 'RedHood', age: 24} -``` - -## delegate - +``` + +## delegate + Event delegation. ### add @@ -1018,10 +1033,10 @@ function clickHandler() } delegate.add(container, 'click', '.children', clickHandler); delegate.remove(container, 'click', '.children', clickHandler); -``` - -## detectBrowser - +``` + +## detectBrowser + Detect browser info using ua. |Name |Type |Desc | @@ -1037,18 +1052,18 @@ if (browser.name === 'ie' && browser.version < 9) { // Do something about old IE... } -``` - -## detectMocha - +``` + +## detectMocha + Detect if mocha is running. ```javascript detectMocha(); // -> True if mocha is running. -``` - -## detectOs - +``` + +## detectOs + Detect operating system using ua. |Name |Type |Desc | @@ -1063,10 +1078,10 @@ if (detectOs() === 'ios') { // Do something about ios... } -``` - -## each - +``` + +## each + Iterate over elements of collection and invokes iteratee for each element. |Name |Type |Desc | @@ -1077,10 +1092,10 @@ Iterate over elements of collection and invokes iteratee for each element. ```javascript each({'a': 1, 'b': 2}, function (val, key) {}); -``` - -## endWith - +``` + +## endWith + Check if string ends with the given target string. |Name |Type |Desc | @@ -1091,10 +1106,10 @@ Check if string ends with the given target string. ```javascript endWith('ab', 'b'); // -> true -``` - -## escape - +``` + +## escape + Escapes a string for insertion into HTML, replacing &, <, >, ", `, and ' characters. |Name |Type |Desc | @@ -1104,10 +1119,10 @@ Escapes a string for insertion into HTML, replacing &, <, >, ", `, and ' charact ```javascript escape('You & Me'); -> // -> 'You & Me' -``` - -## escapeJsStr - +``` + +## escapeJsStr + Escape string to be a valid JavaScript string literal between quotes. http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4 @@ -1119,14 +1134,14 @@ http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4 ```javascript escapeJsStr('\"\n'); // -> '\\"\\\\n' -``` - -## escapeJsonStr - -Escape json string. - -## escapeRegExp - +``` + +## escapeJsonStr + +Escape json string. + +## escapeRegExp + Escape special chars to be used as literals in RegExp constructors. |Name |Type |Desc | @@ -1136,14 +1151,14 @@ Escape special chars to be used as literals in RegExp constructors. ```javascript escapeRegExp('[licia]'); // -> '\\[licia\\]' -``` - -## evalCss - -Eval css. - -## extend - +``` + +## evalCss + +Eval css. + +## extend + Copy all of the properties in the source objects over to the destination object. |Name |Type |Desc | @@ -1154,10 +1169,10 @@ Copy all of the properties in the source objects over to the destination object. ```javascript extend({name: 'RedHood'}, {age: 24}); // -> {name: 'RedHood', age: 24} -``` - -## extendOwn - +``` + +## extendOwn + Like extend, but only copies own properties over to the destination object. |Name |Type |Desc | @@ -1168,10 +1183,10 @@ Like extend, but only copies own properties over to the destination object. ```javascript extendOwn({name: 'RedHood'}, {age: 24}); // -> {name: 'RedHood', age: 24} -``` - -## fileSize - +``` + +## fileSize + Turn bytes into human readable file size. |Name |Type |Desc | @@ -1185,10 +1200,10 @@ fileSize(1500); // -> '1.46K' fileSize(1500000); // -> '1.43M' fileSize(1500000000); // -> '1.4G' fileSize(1500000000000); // -> '1.36T' -``` - -## filter - +``` + +## filter + Iterates over elements of collection, returning an array of all the values that pass a truth test. |Name |Type |Desc | @@ -1203,10 +1218,10 @@ filter([1, 2, 3, 4, 5], function (val) { return val % 2 === 0; }); // -> [2, 4] -``` - -## freeze - +``` + +## freeze + Shortcut for Object.freeze. Use Object.defineProperties if Object.freeze is not supported. @@ -1221,22 +1236,22 @@ var a = {b: 1}; freeze(a); a.b = 2; console.log(a); // -> {b: 1} -``` - -## fullUrl - -Add origin to url if needed. - -## getFileName - -Extract file name from url. - -## getObjType - -Get object type. - -## has - +``` + +## fullUrl + +Add origin to url if needed. + +## getFileName + +Extract file name from url. + +## getObjType + +Get object type. + +## has + Checks if key is a direct property. |Name |Type |Desc | @@ -1247,10 +1262,10 @@ Checks if key is a direct property. ```javascript has({one: 1}, 'one'); // -> true -``` - -## identity - +``` + +## identity + Return the first argument given. |Name |Type|Desc | @@ -1260,10 +1275,10 @@ Return the first argument given. ```javascript identity('a'); // -> 'a' -``` - -## idxOf - +``` + +## idxOf + Get the index at which the first occurrence of value. |Name |Type |Desc | @@ -1274,10 +1289,10 @@ Get the index at which the first occurrence of value. ```javascript idxOf([1, 2, 1, 2], 2, 2); // -> 3 -``` - -## inherits - +``` + +## inherits + Inherit the prototype methods from one constructor into another. |Name |Type |Desc | @@ -1303,10 +1318,10 @@ function Student(name) inherits(Student, People); var s = new Student('RedHood'); s.getName(); // -> 'RedHood' -``` - -## isArgs - +``` + +## isArgs + Check if value is classified as an arguments object. |Name |Type |Desc | @@ -1318,10 +1333,10 @@ Check if value is classified as an arguments object. (function () { isArgs(arguments); // -> true })(); -``` - -## isArr - +``` + +## isArr + Check if value is an `Array` object. |Name |Type |Desc | @@ -1332,10 +1347,10 @@ Check if value is an `Array` object. ```javascript isArr([]); // -> true isArr({}); // -> false -``` - -## isArrLike - +``` + +## isArrLike + Check if value is array-like. |Name |Type |Desc | @@ -1349,10 +1364,10 @@ Check if value is array-like. isArrLike('test'); // -> true isArrLike(document.body.children); // -> true; isArrLike([1, 2, 3]); // -> true -``` - -## isBool - +``` + +## isBool + Check if value is a boolean primitive. |Name |Type |Desc | @@ -1364,22 +1379,22 @@ Check if value is a boolean primitive. isBool(true); // -> true isBool(false); // -> true isBool(1); // -> false -``` - -## isBrowser - +``` + +## isBrowser + Check if running in a browser. ```javascript console.log(isBrowser); // -> true if running in a browser -``` - -## isCrossOrig - -Check if a url is cross origin. - -## isDate - +``` + +## isCrossOrig + +Check if a url is cross origin. + +## isDate + Check if value is classified as a Date object. |Name |Type |Desc | @@ -1389,10 +1404,10 @@ Check if value is classified as a Date object. ```javascript isDate(new Date()); // -> true -``` - -## isEl - +``` + +## isEl + Check if value is a DOM element. |Name |Type |Desc | @@ -1402,10 +1417,10 @@ Check if value is a DOM element. ```javascript isEl(document.body); // -> true -``` - -## isEmpty - +``` + +## isEmpty + Check if value is an empty object or array. |Name |Type |Desc | @@ -1417,10 +1432,10 @@ Check if value is an empty object or array. isEmpty([]); // -> true isEmpty({}); // -> true isEmpty(''); // -> true -``` - -## isErr - +``` + +## isErr + Check if value is an error. |Name |Type |Desc | @@ -1430,14 +1445,14 @@ Check if value is an error. ```javascript isErr(new Error()); // -> true -``` - -## isErudaEl - -See if an element is within eruda. - -## isFn - +``` + +## isErudaEl + +See if an element is within eruda. + +## isFn + Check if value is a function. |Name |Type |Desc | @@ -1450,10 +1465,10 @@ Generator function is also classified as true. ```javascript isFn(function() {}); // -> true isFn(function*() {}); // -> true -``` - -## isMatch - +``` + +## isMatch + Check if keys and values in src are contained in obj. |Name |Type |Desc | @@ -1464,18 +1479,18 @@ Check if keys and values in src are contained in obj. ```javascript isMatch({a: 1, b: 2}, {a: 1}); // -> true -``` - -## isMiniProgram - +``` + +## isMiniProgram + Check if running in wechat mini program. ```javascript console.log(isMiniProgram); // -> true if running in mini program. -``` - -## isMobile - +``` + +## isMobile + Check whether client is using a mobile browser using ua. |Name |Type |Desc | @@ -1485,10 +1500,10 @@ Check whether client is using a mobile browser using ua. ```javascript isMobile(navigator.userAgent); -``` - -## isNaN - +``` + +## isNaN + Check if value is an NaN. |Name |Type |Desc | @@ -1501,10 +1516,10 @@ Undefined is not an NaN, different from global isNaN function. ```javascript isNaN(0); // -> false isNaN(NaN); // -> true -``` - -## isNative - +``` + +## isNative + Check if value is a native function. |Name |Type |Desc | @@ -1515,10 +1530,10 @@ Check if value is a native function. ```javascript isNative(function () {}); // -> false isNative(Math.min); // -> true -``` - -## isNil - +``` + +## isNil + Check if value is null or undefined, the same as value == null. |Name |Type |Desc | @@ -1533,10 +1548,10 @@ isNil(undefined); // -> true isNil(false); // -> false isNil(0); // -> false isNil([]); // -> false -``` - -## isNull - +``` + +## isNull + Check if value is an Null. |Name |Type |Desc | @@ -1546,10 +1561,10 @@ Check if value is an Null. ```javascript isNull(null); // -> true -``` - -## isNum - +``` + +## isNum + Check if value is classified as a Number primitive or object. |Name |Type |Desc | @@ -1561,10 +1576,10 @@ Check if value is classified as a Number primitive or object. isNum(5); // -> true isNum(5.1); // -> true isNum({}); // -> false -``` - -## isObj - +``` + +## isObj + Check if value is the language type of Object. |Name |Type |Desc | @@ -1577,10 +1592,10 @@ Check if value is the language type of Object. ```javascript isObj({}); // -> true isObj([]); // -> true -``` - -## isRegExp - +``` + +## isRegExp + Check if value is a regular expression. |Name |Type |Desc | @@ -1590,10 +1605,10 @@ Check if value is a regular expression. ```javascript isRegExp(/a/); // -> true -``` - -## isStr - +``` + +## isStr + Check if value is a string primitive. |Name |Type |Desc | @@ -1603,10 +1618,10 @@ Check if value is a string primitive. ```javascript isStr('licia'); // -> true -``` - -## isUndef - +``` + +## isUndef + Check if value is undefined. |Name |Type |Desc | @@ -1617,10 +1632,10 @@ Check if value is undefined. ```javascript isUndef(void 0); // -> true isUndef(null); // -> false -``` - -## kebabCase - +``` + +## kebabCase + Convert string to "kebabCase". |Name |Type |Desc | @@ -1633,10 +1648,10 @@ kebabCase('fooBar'); // -> foo-bar kebabCase('foo bar'); // -> foo-bar kebabCase('foo_bar'); // -> foo-bar kebabCase('foo.bar'); // -> foo-bar -``` - -## keys - +``` + +## keys + Create an array of the own enumerable property names of object. |Name |Type |Desc | @@ -1646,10 +1661,10 @@ Create an array of the own enumerable property names of object. ```javascript keys({a: 1}); // -> ['a'] -``` - -## last - +``` + +## last + Get the last element of array. |Name |Type |Desc | @@ -1659,10 +1674,10 @@ Get the last element of array. ```javascript last([1, 2]); // -> 2 -``` - -## loadJs - +``` + +## loadJs + Inject script tag into page with given src value. |Name|Type |Desc | @@ -1675,10 +1690,10 @@ loadJs('main.js', function (isLoaded) { // Do something... }); -``` - -## lpad - +``` + +## lpad + Pad string on the left side if it's shorter than length. |Name |Type |Desc | @@ -1693,10 +1708,10 @@ lpad('a', 5); // -> ' a' lpad('a', 5, '-'); // -> '----a' lpad('abc', 3, '-'); // -> 'abc' lpad('abc', 5, 'ab'); // -> 'ababc' -``` - -## ltrim - +``` + +## ltrim + Remove chars or white-spaces from beginning of string. |Name |Type |Desc | @@ -1709,10 +1724,10 @@ Remove chars or white-spaces from beginning of string. ltrim(' abc '); // -> 'abc ' ltrim('_abc_', '_'); // -> 'abc_' ltrim('_abc_', ['a', '_']); // -> 'bc_' -``` - -## map - +``` + +## map + Create an array of values by running each element in collection through iteratee. |Name |Type |Desc | @@ -1724,10 +1739,25 @@ Create an array of values by running each element in collection through iteratee ```javascript map([4, 8], function (n) { return n * n; }); // -> [16, 64] -``` +``` + +## mapObj + +Map for objects. -## matcher +|Name |Type |Desc | +|--------|--------|------------------------------| +|obj |object |Object to iterate over | +|iteratee|function|Function invoked per iteration| +|[ctx] |* |Function context | +|return |object |New mapped object | +```javascript +mapObj({a: 1, b: 2}, function (val, key) { return val + 1 }); // -> {a: 2, b: 3} +``` + +## matcher + Return a predicate function that checks if attrs are contained in an object. |Name |Type |Desc | @@ -1741,10 +1771,10 @@ var objects = [ {a: 4, b: 5, c: 6 } ]; filter(objects, matcher({a: 4, c: 6 })); // -> [{a: 4, b: 5, c: 6 }] -``` - -## memStorage - +``` + +## memStorage + Memory-backed implementation of the Web Storage API. A replacement for environments where localStorage or sessionStorage is not available. @@ -1752,10 +1782,10 @@ A replacement for environments where localStorage or sessionStorage is not avail ```javascript var localStorage = window.localStorage || memStorage; localStorage.setItem('test', 'licia'); -``` - -## memoize - +``` + +## memoize + Memoize a given function by caching the computed result. |Name |Type |Desc | @@ -1769,10 +1799,10 @@ var fibonacci = memoize(function(n) { return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); }); -``` - -## meta - +``` + +## meta + Document meta manipulation, turn name and content into key value pairs. Get meta content with given name. If name is omitted, all pairs will be return. @@ -1814,10 +1844,10 @@ meta({ }); meta.remove('d'); meta.remove(['e', 'f']); -``` - -## ms - +``` + +## ms + Convert time string formats to milliseconds. Turn time string into milliseconds. @@ -1843,10 +1873,10 @@ ms('1y'); // -> 31557600000 ms('1000'); // -> 1000 ms(1500); // -> '1.5s' ms(60000); // -> '1m' -``` - -## nextTick - +``` + +## nextTick + Next tick for both node and browser. |Name|Type |Desc | @@ -1862,26 +1892,26 @@ nextTick(function () { // Do something... }); -``` - -## noop - +``` + +## noop + A no-operation function. ```javascript noop(); // Does nothing -``` - -## now - +``` + +## now + Gets the number of milliseconds that have elapsed since the Unix epoch. ```javascript now(); // -> 1468826678701 -``` - -## objToStr - +``` + +## objToStr + Alias of Object.prototype.toString. |Name |Type |Desc | @@ -1891,10 +1921,10 @@ Alias of Object.prototype.toString. ```javascript objToStr(5); // -> '[object Number]' -``` - -## once - +``` + +## once + Create a function that invokes once. |Name |Type |Desc | @@ -1907,14 +1937,14 @@ function init() {}; var initOnce = once(init); initOnce(); initOnce(); // -> init is invoked once -``` - -## optimizeCb - -Used for function context binding. - -## orientation - +``` + +## optimizeCb + +Used for function context binding. + +## orientation + Screen orientation helper. ### on @@ -1935,10 +1965,10 @@ orientation.on('change', function (direction) console.log(direction); // -> 'portrait' }); orientation.get(); // -> 'landscape' -``` - -## partial - +``` + +## partial + Partially apply a function by filling in given arguments. |Name |Type |Desc | @@ -1950,10 +1980,10 @@ Partially apply a function by filling in given arguments. ```javascript var sub5 = partial(function (a, b) { return b - a }, 5); sub(20); // -> 15 -``` - -## perfNow - +``` + +## perfNow + High resolution time up to microsecond precision. ```javascript @@ -1962,10 +1992,10 @@ var start = perfNow(); // Do something. console.log(perfNow() - start); -``` - -## prefix - +``` + +## prefix + Add vendor prefixes to a CSS attribute. |Name |Type |Desc | @@ -1981,14 +2011,14 @@ Create a dasherize version. prefix('text-emphasis'); // -> 'WebkitTextEmphasis' prefix.dash('text-emphasis'); // -> '-webkit-text-emphasis' prefix('color'); // -> 'color' -``` - -## pxToNum - -Turn string like '0px' to number. - -## query - +``` + +## pxToNum + +Turn string like '0px' to number. + +## query + Parse and stringify url query strings. ### parse @@ -2013,10 +2043,10 @@ Stringify an object into a query string. query.parse('foo=bar&eruda=true'); // -> {foo: 'bar', eruda: 'true'} query.stringify({foo: 'bar', eruda: 'true'}); // -> 'foo=bar&eruda=true' query.parse('name=eruda&name=eustia'); // -> {name: ['eruda', 'eustia']} -``` - -## repeat - +``` + +## repeat + Repeat string n-times. |Name |Type |Desc | @@ -2029,10 +2059,10 @@ Repeat string n-times. repeat('a', 3); // -> 'aaa' repeat('ab', 2); // -> 'abab' repeat('*', 0); // -> '' -``` - -## restArgs - +``` + +## restArgs + This accumulates the arguments passed into an array, after a given index. |Name |Type |Desc | @@ -2044,10 +2074,10 @@ This accumulates the arguments passed into an array, after a given index. ```javascript var paramArr = restArgs(function (rest) { return rest }); paramArr(1, 2, 3, 4); // -> [1, 2, 3, 4] -``` - -## rmCookie - +``` + +## rmCookie + Loop through all possible path and domain to remove cookie. |Name|Type |Desc | @@ -2056,14 +2086,14 @@ Loop through all possible path and domain to remove cookie. ```javascript rmCookie('test'); -``` - -## root - -Root object reference, `global` in nodeJs, `window` in browser. - -## rtrim - +``` + +## root + +Root object reference, `global` in nodeJs, `window` in browser. + +## rtrim + Remove chars or white-spaces from end of string. |Name |Type |Desc | @@ -2076,14 +2106,14 @@ Remove chars or white-spaces from end of string. rtrim(' abc '); // -> ' abc' rtrim('_abc_', '_'); // -> '_abc' rtrim('_abc_', ['c', '_']); // -> '_ab' -``` - -## safeCb - -Create callback based on input value. - -## safeGet - +``` + +## safeCb + +Create callback based on input value. + +## safeGet + Get object property, don't throw undefined error. |Name |Type |Desc | @@ -2097,14 +2127,14 @@ var obj = {a: {aa: {aaa: 1}}}; safeGet(obj, 'a.aa.aaa'); // -> 1 safeGet(obj, ['a', 'aa']); // -> {aaa: 1} safeGet(obj, 'a.b'); // -> undefined -``` - -## safeStorage - -Safe localStorage and sessionStorage. - -## slice - +``` + +## safeStorage + +Safe localStorage and sessionStorage. + +## slice + Create slice of source array or array-like object. |Name |Type |Desc | @@ -2115,10 +2145,10 @@ Create slice of source array or array-like object. ```javascript slice([1, 2, 3, 4], 1, 2); // -> [2] -``` - -## some - +``` + +## some + Check if predicate return truthy for any element. |Name |Type |Desc | @@ -2133,10 +2163,10 @@ some([2, 5], function (val) { return val % 2 === 0; }); // -> true -``` - -## splitCase - +``` + +## splitCase + Split different string case to an array. |Name |Type |Desc | @@ -2151,10 +2181,10 @@ splitCase('foo_bar'); // -> ['foo', 'bar'] splitCase('foo.bar'); // -> ['foo', 'bar'] splitCase('fooBar'); // -> ['foo', 'bar'] splitCase('foo-Bar'); // -> ['foo', 'bar'] -``` - -## startWith - +``` + +## startWith + Check if string starts with the given target string. |Name |Type |Desc | @@ -2165,10 +2195,10 @@ Check if string starts with the given target string. ```javascript startWith('ab', 'a'); // -> true -``` - -## stringify - +``` + +## stringify + JSON stringify with support for circular object, function etc. Undefined is treated as null value. @@ -2184,10 +2214,10 @@ stringify({a: function () {}}); // -> '{"a":"[Function function () {}]"}' var obj = {a: 1}; obj.b = obj; stringify(obj); // -> '{"a":1,"b":"[Circular ~]"}' -``` - -## stripHtmlTag - +``` + +## stripHtmlTag + Strip html tags from a string. |Name |Type |Desc | @@ -2197,10 +2227,10 @@ Strip html tags from a string. ```javascript stripHtmlTag('

Hello

'); // -> 'Hello' -``` - -## toArr - +``` + +## toArr + Convert value to an array. |Name |Type |Desc | @@ -2213,10 +2243,10 @@ toArr({a: 1, b: 2}); // -> [{a: 1, b: 2}] toArr('abc'); // -> ['abc'] toArr(1); // -> [1] toArr(null); // -> [] -``` - -## toInt - +``` + +## toInt + Convert value to an integer. |Name |Type |Desc | @@ -2227,10 +2257,10 @@ Convert value to an integer. ```javascript toInt(1.1); // -> 1 toInt(undefined); // -> 0 -``` - -## toNum - +``` + +## toNum + Convert value to a number. |Name |Type |Desc | @@ -2240,10 +2270,10 @@ Convert value to a number. ```javascript toNum('5'); // -> 5 -``` - -## toSrc - +``` + +## toSrc + Convert function to its source code. |Name |Type |Desc | @@ -2254,10 +2284,10 @@ Convert function to its source code. ```javascript toSrc(Math.min); // -> 'function min() { [native code] }' toSrc(function () {}) // -> 'function () { }' -``` - -## toStr - +``` + +## toStr + Convert value to a string. |Name |Type |Desc | @@ -2270,10 +2300,10 @@ toStr(null); // -> '' toStr(1); // -> '1' toStr(false); // -> 'false' toStr([1, 2, 3]); // -> '1,2,3' -``` - -## trim - +``` + +## trim + Remove chars or white-spaces from beginning end of string. |Name |Type |Desc | @@ -2286,10 +2316,10 @@ Remove chars or white-spaces from beginning end of string. trim(' abc '); // -> 'abc' trim('_abc_', '_'); // -> 'abc' trim('_abc_', ['a', 'c', '_']); // -> 'b' -``` - -## tryIt - +``` + +## tryIt + Run function in a try catch. |Name|Type |Desc | @@ -2305,10 +2335,10 @@ tryIt(function () { if (err) console.log(err); }); -``` - -## type - +``` + +## type + Determine the internal JavaScript [[Class]] of an object. |Name |Type |Desc | @@ -2321,10 +2351,10 @@ type(5); // -> 'number' type({}); // -> 'object' type(function () {}); // -> 'function' type([]); // -> 'array' -``` - -## ucs2 - +``` + +## ucs2 + UCS-2 encoding and decoding. ### encode @@ -2350,10 +2380,10 @@ ucs2.encode([0x61, 0x62, 0x63]); // -> 'abc' ucs2.decode('abc'); // -> [0x61, 0x62, 0x63] '𝌆'.length; // -> 2 ucs2.decode('𝌆').length; // -> 1 -``` - -## uniqId - +``` + +## uniqId + Generate a globally-unique id. |Name |Type |Desc | @@ -2363,10 +2393,10 @@ Generate a globally-unique id. ```javascript uniqId('eusita_'); // -> 'eustia_xxx' -``` - -## unique - +``` + +## unique + Create duplicate-free version of an array. |Name |Type |Desc | @@ -2377,10 +2407,10 @@ Create duplicate-free version of an array. ```javascript unique([1, 2, 3, 1]); // -> [1, 2, 3] -``` - -## upperFirst - +``` + +## upperFirst + Convert the first character of string to upper case. |Name |Type |Desc | @@ -2390,10 +2420,10 @@ Convert the first character of string to upper case. ```javascript upperFirst('red'); // -> Red -``` - -## utf8 - +``` + +## utf8 + UTF-8 encoding and decoding. ### encode @@ -2418,10 +2448,10 @@ Turn any UTF-8 encoded string into UTF-8 decoded string. ```javascript utf8.encode('\uD800\uDC00'); // -> '\xF0\x90\x80\x80' utf8.decode('\xF0\x90\x80\x80'); // -> '\uD800\uDC00' -``` - -## values - +``` + +## values + Create an array of the own enumerable property values of object. |Name |Type |Desc | @@ -2431,18 +2461,18 @@ Create an array of the own enumerable property values of object. ```javascript values({one: 1, two: 2}); // -> [1, 2] -``` - -## viewportScale - +``` + +## viewportScale + Get viewport scale. ```javascript viewportScale(); // -> 3 -``` - -## wrap - +``` + +## wrap + Wrap the function inside a wrapper function, passing it as the first argument. |Name |Type |Desc | @@ -2457,4 +2487,4 @@ var p = wrap(escape, function(fn, text) return '

' + fn(text) + '

'; }); p('You & Me'); // -> '

You & Me

' -``` +``` diff --git a/src/Info/Info.js b/src/Info/Info.js index 224b6f2..f3f5238 100644 --- a/src/Info/Info.js +++ b/src/Info/Info.js @@ -1,6 +1,6 @@ import Tool from '../DevTools/Tool' import defInfo from './defInfo' -import { evalCss, each, isFn } from '../lib/util' +import { evalCss, each, isFn, isUndef, cloneDeep } from '../lib/util' export default class Info extends Tool { constructor() { @@ -28,8 +28,8 @@ export default class Info extends Tool { evalCss.remove(this._style) } add(name, val) { - let infos = this._infos, - isUpdate = false + let infos = this._infos + let isUpdate = false each(infos, info => { if (name !== info.name) return @@ -44,6 +44,21 @@ export default class Info extends Tool { return this } + get(name) { + let infos = this._infos + + if (isUndef(name)) { + return cloneDeep(infos) + } + + let result + + each(infos, info => { + if (name === info.name) result = info.val + }) + + return result + } remove(name) { let infos = this._infos diff --git a/src/lib/util.js b/src/lib/util.js index fd0c598..d5270e1 100644 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -1,11 +1,11 @@ // Built by eustia. -"use strict"; +"use strict"; -var _ = {}; +var _ = {}; -/* ------------------------------ last ------------------------------ */ +/* ------------------------------ last ------------------------------ */ -export var last = _.last = (function () { +export var last = _.last = (function () { /* Get the last element of array. * * |Name |Type |Desc | @@ -27,14 +27,14 @@ export var last = _.last = (function () { var len = arr ? arr.length : 0; if (len) return arr[len - 1]; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isUndef ------------------------------ */ +/* ------------------------------ isUndef ------------------------------ */ -export var isUndef = _.isUndef = (function () { +export var isUndef = _.isUndef = (function () { /* Check if value is undefined. * * |Name |Type |Desc | @@ -55,14 +55,14 @@ export var isUndef = _.isUndef = (function () { function exports(val) { return val === void 0; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isObj ------------------------------ */ +/* ------------------------------ isObj ------------------------------ */ -export var isObj = _.isObj = (function () { +export var isObj = _.isObj = (function () { /* Check if value is the language type of Object. * * |Name |Type |Desc | @@ -87,42 +87,14 @@ export var isObj = _.isObj = (function () { var type = typeof val; return !!val && (type === 'function' || type === 'object'); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ startWith ------------------------------ */ +/* ------------------------------ inherits ------------------------------ */ -export var startWith = _.startWith = (function () { - /* Check if string starts with the given target string. - * - * |Name |Type |Desc | - * |------|-------|---------------------------------| - * |str |string |String to search | - * |prefix|string |String prefix | - * |return|boolean|True if string starts with prefix| - * - * ```javascript - * startWith('ab', 'a'); // -> true - * ``` - */ - - /* module - * env: all - * test: all - */ - - function exports(str, prefix) { - return str.indexOf(prefix) === 0; - } - - return exports; -})(); - -/* ------------------------------ inherits ------------------------------ */ - -export var inherits = _.inherits = (function () { +export var inherits = _.inherits = (function () { /* Inherit the prototype methods from one constructor into another. * * |Name |Type |Desc | @@ -165,14 +137,14 @@ export var inherits = _.inherits = (function () { var objCreate = Object.create; - function noop() {} + function noop() {} - return exports; -})(); + return exports; +})(); -/* ------------------------------ has ------------------------------ */ +/* ------------------------------ has ------------------------------ */ -export var has = _.has = (function () { +export var has = _.has = (function () { /* Checks if key is a direct property. * * |Name |Type |Desc | @@ -195,14 +167,14 @@ export var has = _.has = (function () { function exports(obj, key) { return hasOwnProp.call(obj, key); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ slice ------------------------------ */ +/* ------------------------------ slice ------------------------------ */ -export var slice = _.slice = (function () { +export var slice = _.slice = (function () { /* Create slice of source array or array-like object. * * |Name |Type |Desc | @@ -244,14 +216,14 @@ export var slice = _.slice = (function () { while (start < end) ret.push(arr[start++]); return ret; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isBrowser ------------------------------ */ +/* ------------------------------ isBrowser ------------------------------ */ -export var isBrowser = _.isBrowser = (function (exports) { +export var isBrowser = _.isBrowser = (function (exports) { /* Check if running in a browser. * * ```javascript @@ -267,14 +239,14 @@ export var isBrowser = _.isBrowser = (function (exports) { exports = typeof window === 'object' && typeof document === 'object' && - document.nodeType === 9; + document.nodeType === 9; - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ noop ------------------------------ */ +/* ------------------------------ noop ------------------------------ */ -export var noop = _.noop = (function () { +export var noop = _.noop = (function () { /* A no-operation function. * * ```javascript @@ -287,14 +259,14 @@ export var noop = _.noop = (function () { * test: all */ - function exports() {} + function exports() {} - return exports; -})(); + return exports; +})(); -/* ------------------------------ allKeys ------------------------------ */ +/* ------------------------------ allKeys ------------------------------ */ -export var allKeys = _.allKeys = (function () { +export var allKeys = _.allKeys = (function () { /* Retrieve all the names of object's own and inherited properties. * * |Name |Type |Desc | @@ -323,14 +295,14 @@ export var allKeys = _.allKeys = (function () { for (key in obj) ret.push(key); return ret; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ before ------------------------------ */ +/* ------------------------------ before ------------------------------ */ -export var before = _.before = (function () { +export var before = _.before = (function () { /* Create a function that invokes less than n times. * * |Name |Type |Desc | @@ -361,14 +333,14 @@ export var before = _.before = (function () { return memo; }; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ splitCase ------------------------------ */ +/* ------------------------------ splitCase ------------------------------ */ -export var splitCase = _.splitCase = (function () { +export var splitCase = _.splitCase = (function () { /* Split different string case to an array. * * |Name |Type |Desc | @@ -403,14 +375,14 @@ export var splitCase = _.splitCase = (function () { .replace(regTrim, ''); return str.split('-'); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ camelCase ------------------------------ */ +/* ------------------------------ camelCase ------------------------------ */ -export var camelCase = _.camelCase = (function () { +export var camelCase = _.camelCase = (function () { /* Convert string to "camelCase". * * |Name |Type |Desc | @@ -451,14 +423,14 @@ export var camelCase = _.camelCase = (function () { this[idx] = val.replace(/\w/, function(match) { return match.toUpperCase(); }); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ kebabCase ------------------------------ */ +/* ------------------------------ kebabCase ------------------------------ */ -export var kebabCase = _.kebabCase = (function () { +export var kebabCase = _.kebabCase = (function () { /* Convert string to "kebabCase". * * |Name |Type |Desc | @@ -485,14 +457,14 @@ export var kebabCase = _.kebabCase = (function () { function exports(str) { return splitCase(str).join('-'); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ chunk ------------------------------ */ +/* ------------------------------ chunk ------------------------------ */ -export var chunk = _.chunk = (function () { +export var chunk = _.chunk = (function () { /* Split array into groups the length of given size. * * |Name |Type |Desc | @@ -525,14 +497,14 @@ export var chunk = _.chunk = (function () { } return ret; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ clamp ------------------------------ */ +/* ------------------------------ clamp ------------------------------ */ -export var clamp = _.clamp = (function () { +export var clamp = _.clamp = (function () { /* Clamp number within the inclusive lower and upper bounds. * * |Name |Type |Desc | @@ -571,14 +543,14 @@ export var clamp = _.clamp = (function () { if (n > upper) return upper; return n; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ idxOf ------------------------------ */ +/* ------------------------------ idxOf ------------------------------ */ -export var idxOf = _.idxOf = (function () { +export var idxOf = _.idxOf = (function () { /* Get the index at which the first occurrence of value. * * |Name |Type |Desc | @@ -599,14 +571,14 @@ export var idxOf = _.idxOf = (function () { function exports(arr, val, fromIdx) { return Array.prototype.indexOf.call(arr, val, fromIdx); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ toStr ------------------------------ */ +/* ------------------------------ toStr ------------------------------ */ -export var toStr = _.toStr = (function () { +export var toStr = _.toStr = (function () { /* Convert value to a string. * * |Name |Type |Desc | @@ -629,14 +601,14 @@ export var toStr = _.toStr = (function () { function exports(val) { return val == null ? '' : val.toString(); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ ucs2 ------------------------------ */ +/* ------------------------------ ucs2 ------------------------------ */ -export var ucs2 = _.ucs2 = (function (exports) { +export var ucs2 = _.ucs2 = (function (exports) { /* UCS-2 encoding and decoding. * * ### encode @@ -702,14 +674,14 @@ export var ucs2 = _.ucs2 = (function (exports) { return ret; } - }; + }; - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ utf8 ------------------------------ */ +/* ------------------------------ utf8 ------------------------------ */ -export var utf8 = _.utf8 = (function (exports) { +export var utf8 = _.utf8 = (function (exports) { /* UTF-8 encoding and decoding. * * ### encode @@ -906,14 +878,14 @@ export var utf8 = _.utf8 = (function (exports) { upperBoundary = 0xbf; return byteArr[start]; - } + } - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ root ------------------------------ */ +/* ------------------------------ root ------------------------------ */ -export var root = _.root = (function (exports) { +export var root = _.root = (function (exports) { /* Root object reference, `global` in nodeJs, `window` in browser. */ /* module @@ -925,14 +897,14 @@ export var root = _.root = (function (exports) { * isBrowser */ - exports = isBrowser ? window : global; + exports = isBrowser ? window : global; - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ detectMocha ------------------------------ */ +/* ------------------------------ detectMocha ------------------------------ */ -export var detectMocha = _.detectMocha = (function () { +export var detectMocha = _.detectMocha = (function () { /* Detect if mocha is running. * * ```javascript @@ -959,14 +931,14 @@ export var detectMocha = _.detectMocha = (function () { return true; } - var methods = ['afterEach', 'after', 'beforeEach', 'before', 'describe', 'it']; + var methods = ['afterEach', 'after', 'beforeEach', 'before', 'describe', 'it']; - return exports; -})(); + return exports; +})(); -/* ------------------------------ keys ------------------------------ */ +/* ------------------------------ keys ------------------------------ */ -export var keys = _.keys = (function (exports) { +export var keys = _.keys = (function (exports) { /* Create an array of the own enumerable property names of object. * * |Name |Type |Desc | @@ -1001,14 +973,14 @@ export var keys = _.keys = (function (exports) { return ret; }; - } + } - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ freeze ------------------------------ */ +/* ------------------------------ freeze ------------------------------ */ -export var freeze = _.freeze = (function () { +export var freeze = _.freeze = (function () { /* Shortcut for Object.freeze. * * Use Object.defineProperties if Object.freeze is not supported. @@ -1048,14 +1020,14 @@ export var freeze = _.freeze = (function () { }); return obj; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ detectOs ------------------------------ */ +/* ------------------------------ detectOs ------------------------------ */ -export var detectOs = _.detectOs = (function () { +export var detectOs = _.detectOs = (function () { /* Detect operating system using ua. * * |Name |Type |Desc | @@ -1099,14 +1071,14 @@ export var detectOs = _.detectOs = (function () { } return 'unknown'; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ optimizeCb ------------------------------ */ +/* ------------------------------ optimizeCb ------------------------------ */ -export var optimizeCb = _.optimizeCb = (function () { +export var optimizeCb = _.optimizeCb = (function () { /* Used for function context binding. */ @@ -1140,14 +1112,14 @@ export var optimizeCb = _.optimizeCb = (function () { return function() { return fn.apply(ctx, arguments); }; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ endWith ------------------------------ */ +/* ------------------------------ endWith ------------------------------ */ -export var endWith = _.endWith = (function () { +export var endWith = _.endWith = (function () { /* Check if string ends with the given target string. * * |Name |Type |Desc | @@ -1170,14 +1142,14 @@ export var endWith = _.endWith = (function () { var idx = str.length - suffix.length; return idx >= 0 && str.indexOf(suffix, idx) === idx; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ escape ------------------------------ */ +/* ------------------------------ escape ------------------------------ */ -export var escape = _.escape = (function () { +export var escape = _.escape = (function () { /* Escapes a string for insertion into HTML, replacing &, <, >, ", `, and ' characters. * * |Name |Type |Desc | @@ -1218,14 +1190,14 @@ export var escape = _.escape = (function () { function replaceFn(match) { return map[match]; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ escapeJsStr ------------------------------ */ +/* ------------------------------ escapeJsStr ------------------------------ */ -export var escapeJsStr = _.escapeJsStr = (function () { +export var escapeJsStr = _.escapeJsStr = (function () { /* Escape string to be a valid JavaScript string literal between quotes. * * http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4 @@ -1270,14 +1242,14 @@ export var escapeJsStr = _.escapeJsStr = (function () { }); } - var regEscapeChars = /["'\\\n\r\u2028\u2029]/g; + var regEscapeChars = /["'\\\n\r\u2028\u2029]/g; - return exports; -})(); + return exports; +})(); -/* ------------------------------ escapeJsonStr ------------------------------ */ +/* ------------------------------ escapeJsonStr ------------------------------ */ -export var escapeJsonStr = _.escapeJsonStr = (function () { +export var escapeJsonStr = _.escapeJsonStr = (function () { /* Escape json string. */ @@ -1286,15 +1258,15 @@ export var escapeJsonStr = _.escapeJsonStr = (function () { */ function exports(str) { - return escapeJsStr(str).replace(/\\'/g, "'"); - } + return escapeJsStr(str).replace(/\\'/g, "'") + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ escapeRegExp ------------------------------ */ +/* ------------------------------ escapeRegExp ------------------------------ */ -export var escapeRegExp = _.escapeRegExp = (function () { +export var escapeRegExp = _.escapeRegExp = (function () { /* Escape special chars to be used as literals in RegExp constructors. * * |Name |Type |Desc | @@ -1314,14 +1286,14 @@ export var escapeRegExp = _.escapeRegExp = (function () { function exports(str) { return str.replace(/\W/g, '\\$&'); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ fileSize ------------------------------ */ +/* ------------------------------ fileSize ------------------------------ */ -export var fileSize = _.fileSize = (function () { +export var fileSize = _.fileSize = (function () { /* Turn bytes into human readable file size. * * |Name |Type |Desc | @@ -1352,14 +1324,42 @@ export var fileSize = _.fileSize = (function () { return +val.toFixed(2) + suffixList[suffixIdx]; } - var suffixList = ['', 'K', 'M', 'G', 'T']; + var suffixList = ['', 'K', 'M', 'G', 'T']; - return exports; -})(); + return exports; +})(); -/* ------------------------------ fullUrl ------------------------------ */ +/* ------------------------------ startWith ------------------------------ */ -export var fullUrl = _.fullUrl = (function () { +export var startWith = _.startWith = (function () { + /* Check if string starts with the given target string. + * + * |Name |Type |Desc | + * |------|-------|---------------------------------| + * |str |string |String to search | + * |prefix|string |String prefix | + * |return|boolean|True if string starts with prefix| + * + * ```javascript + * startWith('ab', 'a'); // -> true + * ``` + */ + + /* module + * env: all + * test: all + */ + + function exports(str, prefix) { + return str.indexOf(prefix) === 0; + } + + return exports; +})(); + +/* ------------------------------ fullUrl ------------------------------ */ + +export var fullUrl = _.fullUrl = (function () { /* Add origin to url if needed. */ @@ -1367,22 +1367,22 @@ export var fullUrl = _.fullUrl = (function () { * startWith */ - let origin = window.location.origin; + let origin = window.location.origin function exports(url) { - if (startWith(url, 'http')) return url; + if (startWith(url, 'http')) return url - if (!startWith(url, '/')) url = '/' + url; + if (!startWith(url, '/')) url = '/' + url - return origin + url; - } + return origin + url + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ upperFirst ------------------------------ */ +/* ------------------------------ upperFirst ------------------------------ */ -export var upperFirst = _.upperFirst = (function () { +export var upperFirst = _.upperFirst = (function () { /* Convert the first character of string to upper case. * * |Name |Type |Desc | @@ -1404,14 +1404,14 @@ export var upperFirst = _.upperFirst = (function () { if (str.length < 1) return str; return str[0].toUpperCase() + str.slice(1); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ getObjType ------------------------------ */ +/* ------------------------------ getObjType ------------------------------ */ -export var getObjType = _.getObjType = (function () { +export var getObjType = _.getObjType = (function () { /* Get object type. */ @@ -1420,17 +1420,17 @@ export var getObjType = _.getObjType = (function () { */ function exports(obj) { - if (obj.constructor && obj.constructor.name) return obj.constructor.name; + if (obj.constructor && obj.constructor.name) return obj.constructor.name - return upperFirst({}.toString.call(obj).replace(/(\[object )|]/g, '')); - } + return upperFirst({}.toString.call(obj).replace(/(\[object )|]/g, '')) + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ identity ------------------------------ */ +/* ------------------------------ identity ------------------------------ */ -export var identity = _.identity = (function () { +export var identity = _.identity = (function () { /* Return the first argument given. * * |Name |Type|Desc | @@ -1450,14 +1450,14 @@ export var identity = _.identity = (function () { function exports(val) { return val; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ objToStr ------------------------------ */ +/* ------------------------------ objToStr ------------------------------ */ -export var objToStr = _.objToStr = (function () { +export var objToStr = _.objToStr = (function () { /* Alias of Object.prototype.toString. * * |Name |Type |Desc | @@ -1479,14 +1479,14 @@ export var objToStr = _.objToStr = (function () { function exports(val) { return ObjToStr.call(val); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isArgs ------------------------------ */ +/* ------------------------------ isArgs ------------------------------ */ -export var isArgs = _.isArgs = (function () { +export var isArgs = _.isArgs = (function () { /* Check if value is classified as an arguments object. * * |Name |Type |Desc | @@ -1512,14 +1512,14 @@ export var isArgs = _.isArgs = (function () { function exports(val) { return objToStr(val) === '[object Arguments]'; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isArr ------------------------------ */ +/* ------------------------------ isArr ------------------------------ */ -export var isArr = _.isArr = (function (exports) { +export var isArr = _.isArr = (function (exports) { /* Check if value is an `Array` object. * * |Name |Type |Desc | @@ -1546,14 +1546,14 @@ export var isArr = _.isArr = (function (exports) { Array.isArray || function(val) { return objToStr(val) === '[object Array]'; - }; + }; - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ castPath ------------------------------ */ +/* ------------------------------ castPath ------------------------------ */ -export var castPath = _.castPath = (function () { +export var castPath = _.castPath = (function () { /* Cast value into a property path array. * * |Name |Type |Desc | @@ -1594,14 +1594,14 @@ export var castPath = _.castPath = (function () { // Lodash _stringToPath var regPropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g, - regEscapeChar = /\\(\\)?/g; + regEscapeChar = /\\(\\)?/g; - return exports; -})(); + return exports; +})(); -/* ------------------------------ safeGet ------------------------------ */ +/* ------------------------------ safeGet ------------------------------ */ -export var safeGet = _.safeGet = (function () { +export var safeGet = _.safeGet = (function () { /* Get object property, don't throw undefined error. * * |Name |Type |Desc | @@ -1640,14 +1640,14 @@ export var safeGet = _.safeGet = (function () { } return obj; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isDate ------------------------------ */ +/* ------------------------------ isDate ------------------------------ */ -export var isDate = _.isDate = (function () { +export var isDate = _.isDate = (function () { /* Check if value is classified as a Date object. * * |Name |Type |Desc | @@ -1671,14 +1671,14 @@ export var isDate = _.isDate = (function () { function exports(val) { return objToStr(val) === '[object Date]'; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isFn ------------------------------ */ +/* ------------------------------ isFn ------------------------------ */ -export var isFn = _.isFn = (function () { +export var isFn = _.isFn = (function () { /* Check if value is a function. * * |Name |Type |Desc | @@ -1710,14 +1710,14 @@ export var isFn = _.isFn = (function () { objStr === '[object Function]' || objStr === '[object GeneratorFunction]' ); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isMiniProgram ------------------------------ */ +/* ------------------------------ isMiniProgram ------------------------------ */ -export var isMiniProgram = _.isMiniProgram = (function (exports) { +export var isMiniProgram = _.isMiniProgram = (function (exports) { /* Check if running in wechat mini program. * * ```javascript @@ -1735,14 +1735,14 @@ export var isMiniProgram = _.isMiniProgram = (function (exports) { */ /* eslint-disable no-undef */ - exports = typeof wx !== 'undefined' && isFn(wx.openLocation); + exports = typeof wx !== 'undefined' && isFn(wx.openLocation); - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ isNum ------------------------------ */ +/* ------------------------------ isNum ------------------------------ */ -export var isNum = _.isNum = (function () { +export var isNum = _.isNum = (function () { /* Check if value is classified as a Number primitive or object. * * |Name |Type |Desc | @@ -1768,14 +1768,14 @@ export var isNum = _.isNum = (function () { function exports(val) { return objToStr(val) === '[object Number]'; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isArrLike ------------------------------ */ +/* ------------------------------ isArrLike ------------------------------ */ -export var isArrLike = _.isArrLike = (function () { +export var isArrLike = _.isArrLike = (function () { /* Check if value is array-like. * * |Name |Type |Desc | @@ -1809,14 +1809,14 @@ export var isArrLike = _.isArrLike = (function () { var len = val.length; return isNum(len) && len >= 0 && len <= MAX_ARR_IDX && !isFn(val); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ each ------------------------------ */ +/* ------------------------------ each ------------------------------ */ -export var each = _.each = (function () { +export var each = _.each = (function () { /* Iterate over elements of collection and invokes iteratee for each element. * * |Name |Type |Desc | @@ -1854,14 +1854,14 @@ export var each = _.each = (function () { } return obj; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ createAssigner ------------------------------ */ +/* ------------------------------ createAssigner ------------------------------ */ -export var createAssigner = _.createAssigner = (function () { +export var createAssigner = _.createAssigner = (function () { /* Used to create extend, extendOwn and defaults. * * |Name |Type |Desc | @@ -1894,14 +1894,14 @@ export var createAssigner = _.createAssigner = (function () { return obj; }; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ defaults ------------------------------ */ +/* ------------------------------ defaults ------------------------------ */ -export var defaults = _.defaults = (function (exports) { +export var defaults = _.defaults = (function (exports) { /* Fill in undefined properties in object with the first value present in the following list of defaults objects. * * |Name |Type |Desc | @@ -1924,14 +1924,14 @@ export var defaults = _.defaults = (function (exports) { * createAssigner allKeys */ - exports = createAssigner(allKeys, true); + exports = createAssigner(allKeys, true); - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ extend ------------------------------ */ +/* ------------------------------ extend ------------------------------ */ -export var extend = _.extend = (function (exports) { +export var extend = _.extend = (function (exports) { /* Copy all of the properties in the source objects over to the destination object. * * |Name |Type |Desc | @@ -1954,14 +1954,14 @@ export var extend = _.extend = (function (exports) { * createAssigner allKeys */ - exports = createAssigner(allKeys); + exports = createAssigner(allKeys); - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ clone ------------------------------ */ +/* ------------------------------ clone ------------------------------ */ -export var clone = _.clone = (function () { +export var clone = _.clone = (function () { /* Create a shallow-copied clone of the provided plain object. * * Any nested objects or arrays will be copied by reference, not duplicated. @@ -1989,14 +1989,14 @@ export var clone = _.clone = (function () { if (!isObj(obj)) return obj; return isArr(obj) ? obj.slice() : extend({}, obj); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ extendOwn ------------------------------ */ +/* ------------------------------ extendOwn ------------------------------ */ -export var extendOwn = _.extendOwn = (function (exports) { +export var extendOwn = _.extendOwn = (function (exports) { /* Like extend, but only copies own properties over to the destination object. * * |Name |Type |Desc | @@ -2019,14 +2019,14 @@ export var extendOwn = _.extendOwn = (function (exports) { * keys createAssigner */ - exports = createAssigner(keys); + exports = createAssigner(keys); - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ values ------------------------------ */ +/* ------------------------------ values ------------------------------ */ -export var values = _.values = (function () { +export var values = _.values = (function () { /* Create an array of the own enumerable property values of object. * * |Name |Type |Desc | @@ -2056,14 +2056,14 @@ export var values = _.values = (function () { }); return ret; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ contain ------------------------------ */ +/* ------------------------------ contain ------------------------------ */ -export var contain = _.contain = (function () { +export var contain = _.contain = (function () { /* Check if the value is present in the list. * * |Name |Type |Desc | @@ -2091,14 +2091,14 @@ export var contain = _.contain = (function () { if (!isArrLike(arr)) arr = values(arr); return idxOf(arr, val) >= 0; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isStr ------------------------------ */ +/* ------------------------------ isStr ------------------------------ */ -export var isStr = _.isStr = (function () { +export var isStr = _.isStr = (function () { /* Check if value is a string primitive. * * |Name |Type |Desc | @@ -2122,14 +2122,14 @@ export var isStr = _.isStr = (function () { function exports(val) { return objToStr(val) === '[object String]'; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isEmpty ------------------------------ */ +/* ------------------------------ isEmpty ------------------------------ */ -export var isEmpty = _.isEmpty = (function () { +export var isEmpty = _.isEmpty = (function () { /* Check if value is an empty object or array. * * |Name |Type |Desc | @@ -2161,14 +2161,14 @@ export var isEmpty = _.isEmpty = (function () { } return keys(val).length === 0; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isBool ------------------------------ */ +/* ------------------------------ isBool ------------------------------ */ -export var isBool = _.isBool = (function () { +export var isBool = _.isBool = (function () { /* Check if value is a boolean primitive. * * |Name |Type |Desc | @@ -2190,14 +2190,14 @@ export var isBool = _.isBool = (function () { function exports(val) { return val === true || val === false; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isCrossOrig ------------------------------ */ +/* ------------------------------ isCrossOrig ------------------------------ */ -export var isCrossOrig = _.isCrossOrig = (function () { +export var isCrossOrig = _.isCrossOrig = (function () { /* Check if a url is cross origin. */ @@ -2205,18 +2205,18 @@ export var isCrossOrig = _.isCrossOrig = (function () { * startWith */ - var origin = window.location.origin; + var origin = window.location.origin function exports(url) { - return !startWith(url, origin); - } + return !startWith(url, origin) + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isEl ------------------------------ */ +/* ------------------------------ isEl ------------------------------ */ -export var isEl = _.isEl = (function () { +export var isEl = _.isEl = (function () { /* Check if value is a DOM element. * * |Name |Type |Desc | @@ -2236,14 +2236,14 @@ export var isEl = _.isEl = (function () { function exports(val) { return !!(val && val.nodeType === 1); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isErr ------------------------------ */ +/* ------------------------------ isErr ------------------------------ */ -export var isErr = _.isErr = (function () { +export var isErr = _.isErr = (function () { /* Check if value is an error. * * |Name |Type |Desc | @@ -2267,36 +2267,36 @@ export var isErr = _.isErr = (function () { function exports(val) { return objToStr(val) === '[object Error]'; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isErudaEl ------------------------------ */ +/* ------------------------------ isErudaEl ------------------------------ */ -export var isErudaEl = _.isErudaEl = (function () { +export var isErudaEl = _.isErudaEl = (function () { /* See if an element is within eruda. */ function exports(el) { - var parentNode = el.parentNode; + var parentNode = el.parentNode - if (!parentNode) return false; + if (!parentNode) return false - while (parentNode) { - parentNode = parentNode.parentNode; - if (parentNode && parentNode.id === 'eruda') return true; - } + while (parentNode) { + parentNode = parentNode.parentNode + if (parentNode && parentNode.id === 'eruda') return true + } - return false; - } + return false + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isMatch ------------------------------ */ +/* ------------------------------ isMatch ------------------------------ */ -export var isMatch = _.isMatch = (function () { +export var isMatch = _.isMatch = (function () { /* Check if keys and values in src are contained in obj. * * |Name |Type |Desc | @@ -2333,14 +2333,14 @@ export var isMatch = _.isMatch = (function () { } return true; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ memoize ------------------------------ */ +/* ------------------------------ memoize ------------------------------ */ -export var memoize = _.memoize = (function () { +export var memoize = _.memoize = (function () { /* Memoize a given function by caching the computed result. * * |Name |Type |Desc | @@ -2379,14 +2379,14 @@ export var memoize = _.memoize = (function () { memoize.cache = {}; return memoize; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isMobile ------------------------------ */ +/* ------------------------------ isMobile ------------------------------ */ -export var isMobile = _.isMobile = (function (exports) { +export var isMobile = _.isMobile = (function (exports) { /* Check whether client is using a mobile browser using ua. * * |Name |Type |Desc | @@ -2415,14 +2415,14 @@ export var isMobile = _.isMobile = (function (exports) { ua = ua || (isBrowser ? navigator.userAgent : ''); return regMobileAll.test(ua) || regMobileFour.test(ua.substr(0, 4)); - }); + }); - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ prefix ------------------------------ */ +/* ------------------------------ prefix ------------------------------ */ -export var prefix = _.prefix = (function (exports) { +export var prefix = _.prefix = (function (exports) { /* Add vendor prefixes to a CSS attribute. * * |Name |Type |Desc | @@ -2476,14 +2476,14 @@ export var prefix = _.prefix = (function (exports) { var prefixes = ['O', 'ms', 'Moz', 'Webkit'], regPrefixes = /^(O)|(ms)|(Moz)|(Webkit)|(-o-)|(-ms-)|(-moz-)|(-webkit-)/g, - style = document.createElement('p').style; + style = document.createElement('p').style; - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ isNaN ------------------------------ */ +/* ------------------------------ isNaN ------------------------------ */ -export var isNaN = _.isNaN = (function () { +export var isNaN = _.isNaN = (function () { /* Check if value is an NaN. * * |Name |Type |Desc | @@ -2510,14 +2510,14 @@ export var isNaN = _.isNaN = (function () { function exports(val) { return isNum(val) && val !== +val; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isNil ------------------------------ */ +/* ------------------------------ isNil ------------------------------ */ -export var isNil = _.isNil = (function () { +export var isNil = _.isNil = (function () { /* Check if value is null or undefined, the same as value == null. * * |Name |Type |Desc | @@ -2542,14 +2542,14 @@ export var isNil = _.isNil = (function () { function exports(val) { return val == null; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ toSrc ------------------------------ */ +/* ------------------------------ toSrc ------------------------------ */ -export var toSrc = _.toSrc = (function () { +export var toSrc = _.toSrc = (function () { /* Convert function to its source code. * * |Name |Type |Desc | @@ -2588,14 +2588,14 @@ export var toSrc = _.toSrc = (function () { return ''; } - var fnToStr = Function.prototype.toString; + var fnToStr = Function.prototype.toString; - return exports; -})(); + return exports; +})(); -/* ------------------------------ isNative ------------------------------ */ +/* ------------------------------ isNative ------------------------------ */ -export var isNative = _.isNative = (function () { +export var isNative = _.isNative = (function () { /* Check if value is a native function. * * |Name |Type |Desc | @@ -2615,7 +2615,7 @@ export var isNative = _.isNative = (function () { */ /* dependencies - * isObj isFn has toSrc + * isObj isFn toSrc */ function exports(val) { @@ -2640,14 +2640,14 @@ export var isNative = _.isNative = (function () { '$' ); - var regIsHostCtor = /^\[object .+?Constructor\]$/; + var regIsHostCtor = /^\[object .+?Constructor\]$/; - return exports; -})(); + return exports; +})(); -/* ------------------------------ isNull ------------------------------ */ +/* ------------------------------ isNull ------------------------------ */ -export var isNull = _.isNull = (function () { +export var isNull = _.isNull = (function () { /* Check if value is an Null. * * |Name |Type |Desc | @@ -2667,14 +2667,14 @@ export var isNull = _.isNull = (function () { function exports(val) { return val === null; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ isRegExp ------------------------------ */ +/* ------------------------------ isRegExp ------------------------------ */ -export var isRegExp = _.isRegExp = (function () { +export var isRegExp = _.isRegExp = (function () { /* Check if value is a regular expression. * * |Name |Type |Desc | @@ -2698,14 +2698,14 @@ export var isRegExp = _.isRegExp = (function () { function exports(val) { return objToStr(val) === '[object RegExp]'; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ loadJs ------------------------------ */ +/* ------------------------------ loadJs ------------------------------ */ -export var loadJs = _.loadJs = (function () { +export var loadJs = _.loadJs = (function () { /* Inject script tag into page with given src value. * * |Name|Type |Desc | @@ -2738,14 +2738,14 @@ export var loadJs = _.loadJs = (function () { cb && cb(!isNotLoaded); }; document.body.appendChild(script); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ repeat ------------------------------ */ +/* ------------------------------ repeat ------------------------------ */ -export var repeat = _.repeat = (function (exports) { +export var repeat = _.repeat = (function (exports) { /* Repeat string n-times. * * |Name |Type |Desc | @@ -2778,14 +2778,14 @@ export var repeat = _.repeat = (function (exports) { } return ret; - }; + }; - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ lpad ------------------------------ */ +/* ------------------------------ lpad ------------------------------ */ -export var lpad = _.lpad = (function () { +export var lpad = _.lpad = (function () { /* Pad string on the left side if it's shorter than length. * * |Name |Type |Desc | @@ -2822,14 +2822,14 @@ export var lpad = _.lpad = (function () { if (strLen < len) str = (repeat(chars, len - strLen) + str).slice(-len); return str; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ dateFormat ------------------------------ */ +/* ------------------------------ dateFormat ------------------------------ */ -export var dateFormat = _.dateFormat = (function () { +export var dateFormat = _.dateFormat = (function () { /* Simple but extremely useful date format function. * * |Name |Type |Desc | @@ -3033,14 +3033,14 @@ export var dateFormat = _.dateFormat = (function () { 'November', 'December' ] - }; + }; - return exports; -})(); + return exports; +})(); -/* ------------------------------ ltrim ------------------------------ */ +/* ------------------------------ ltrim ------------------------------ */ -export var ltrim = _.ltrim = (function () { +export var ltrim = _.ltrim = (function () { /* Remove chars or white-spaces from beginning of string. * * |Name |Type |Desc | @@ -3088,14 +3088,14 @@ export var ltrim = _.ltrim = (function () { } return start >= len ? '' : str.substr(start, len); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ matcher ------------------------------ */ +/* ------------------------------ matcher ------------------------------ */ -export var matcher = _.matcher = (function () { +export var matcher = _.matcher = (function () { /* Return a predicate function that checks if attrs are contained in an object. * * |Name |Type |Desc | @@ -3127,14 +3127,14 @@ export var matcher = _.matcher = (function () { return function(obj) { return isMatch(obj, attrs); }; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ safeCb ------------------------------ */ +/* ------------------------------ safeCb ------------------------------ */ -export var safeCb = _.safeCb = (function (exports) { +export var safeCb = _.safeCb = (function (exports) { /* Create callback based on input value. */ @@ -3159,14 +3159,14 @@ export var safeCb = _.safeCb = (function (exports) { return obj == null ? undefined : obj[key]; }; }; - }; + }; - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ filter ------------------------------ */ +/* ------------------------------ filter ------------------------------ */ -export var filter = _.filter = (function () { +export var filter = _.filter = (function () { /* Iterates over elements of collection, returning an array of all the values that pass a truth test. * * |Name |Type |Desc | @@ -3203,14 +3203,14 @@ export var filter = _.filter = (function () { }); return ret; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ evalCss ------------------------------ */ +/* ------------------------------ evalCss ------------------------------ */ -export var evalCss = _.evalCss = (function () { +export var evalCss = _.evalCss = (function () { /* Eval css. */ @@ -3219,54 +3219,54 @@ export var evalCss = _.evalCss = (function () { */ var styleList = [], - scale = 1; + scale = 1 function exports(css, container) { - css = toStr(css); + css = toStr(css) - for (var i = 0, len = styleList.length; i < len; i++) { - if (styleList[i].css === css) return; - } + for (var i = 0, len = styleList.length; i < len; i++) { + if (styleList[i].css === css) return + } - container = container || exports.container || document.head; - const el = document.createElement('style'); + container = container || exports.container || document.head + const el = document.createElement('style') - el.type = 'text/css'; - container.appendChild(el); + el.type = 'text/css' + container.appendChild(el) - let style = { css, el, container }; - resetStyle(style); - styleList.push(style); + let style = { css, el, container } + resetStyle(style) + styleList.push(style) - return style; + return style } exports.setScale = function(s) { - scale = s; - each(styleList, style => resetStyle(style)); - }; - - exports.clear = function() { - each(styleList, ({ container, el }) => container.removeChild(el)); - styleList = []; - }; - - exports.remove = function(style) { - styleList = filter(styleList, s => s !== style); - - style.container.removeChild(style.el); - }; - - function resetStyle({ css, el }) { - el.innerText = css.replace(/(\d+)px/g, ($0, $1) => +$1 * scale + 'px'); + scale = s + each(styleList, style => resetStyle(style)) } - return exports; -})(); + exports.clear = function() { + each(styleList, ({ container, el }) => container.removeChild(el)) + styleList = [] + } -/* ------------------------------ map ------------------------------ */ + exports.remove = function(style) { + styleList = filter(styleList, s => s !== style) -export var map = _.map = (function () { + style.container.removeChild(style.el) + } + + function resetStyle({ css, el }) { + el.innerText = css.replace(/(\d+)px/g, ($0, $1) => +$1 * scale + 'px') + } + + return exports; +})(); + +/* ------------------------------ map ------------------------------ */ + +export var map = _.map = (function () { /* Create an array of values by running each element in collection through iteratee. * * |Name |Type |Desc | @@ -3303,14 +3303,14 @@ export var map = _.map = (function () { } return results; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ decodeUriComponent ------------------------------ */ +/* ------------------------------ decodeUriComponent ------------------------------ */ -export var decodeUriComponent = _.decodeUriComponent = (function () { +export var decodeUriComponent = _.decodeUriComponent = (function () { /* Better decodeURIComponent that does not throw if input is invalid. * * |Name |Type |Desc | @@ -3337,8 +3337,6 @@ export var decodeUriComponent = _.decodeUriComponent = (function () { try { return decodeURIComponent(str); } catch (e) { - var replaceMap = {}; - var matches = str.match(regMatcher); each(matches, function(match) { @@ -3364,14 +3362,14 @@ export var decodeUriComponent = _.decodeUriComponent = (function () { return +('0x' + numStr); } - var regMatcher = /(%[a-f0-9]{2})+/gi; + var regMatcher = /(%[a-f0-9]{2})+/gi; - return exports; -})(); + return exports; +})(); -/* ------------------------------ cookie ------------------------------ */ +/* ------------------------------ cookie ------------------------------ */ -export var cookie = _.cookie = (function (exports) { +export var cookie = _.cookie = (function (exports) { /* Simple api for handling browser cookies. * * ### get @@ -3482,14 +3480,14 @@ export var cookie = _.cookie = (function (exports) { return setCookie(key, '', options); } - }; + }; - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ toArr ------------------------------ */ +/* ------------------------------ toArr ------------------------------ */ -export var toArr = _.toArr = (function () { +export var toArr = _.toArr = (function () { /* Convert value to an array. * * |Name |Type |Desc | @@ -3522,14 +3520,14 @@ export var toArr = _.toArr = (function () { if (isArrLike(val) && !isStr(val)) return map(val); return [val]; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ Class ------------------------------ */ +/* ------------------------------ Class ------------------------------ */ -export var Class = _.Class = (function () { +export var Class = _.Class = (function () { /* Create JavaScript class. * * |Name |Type |Desc | @@ -3581,7 +3579,7 @@ export var Class = _.Class = (function () { */ /* dependencies - * extend toArr inherits has safeGet isMiniProgram + * extend toArr inherits safeGet isMiniProgram */ function exports(methods, statics) { @@ -3648,14 +3646,14 @@ export var Class = _.Class = (function () { toString: function() { return this.constructor.name; } - })); + })); - return exports; -})(); + return exports; +})(); -/* ------------------------------ Enum ------------------------------ */ +/* ------------------------------ Enum ------------------------------ */ -export var Enum = _.Enum = (function (exports) { +export var Enum = _.Enum = (function (exports) { /* Enum type implementation. * * ### constructor @@ -3713,14 +3711,14 @@ export var Enum = _.Enum = (function (exports) { freeze(this); } - }); + }); - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ MutationObserver ------------------------------ */ +/* ------------------------------ MutationObserver ------------------------------ */ -export var MutationObserver = _.MutationObserver = (function (exports) { +export var MutationObserver = _.MutationObserver = (function (exports) { /* Safe MutationObserver, does nothing if MutationObserver is not supported. * * ```javascript @@ -3754,14 +3752,14 @@ export var MutationObserver = _.MutationObserver = (function (exports) { disconnect: function() {}, takeRecords: function() {} }); - } + } - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ Select ------------------------------ */ +/* ------------------------------ Select ------------------------------ */ -export var Select = _.Select = (function (exports) { +export var Select = _.Select = (function (exports) { /* Simple wrapper of querySelectorAll to make dom selection easier. * * ### constructor @@ -3847,14 +3845,14 @@ export var Select = _.Select = (function (exports) { first.length = i; return first; - } + } - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ $safeEls ------------------------------ */ +/* ------------------------------ $safeEls ------------------------------ */ -export var $safeEls = _.$safeEls = (function () { +export var $safeEls = _.$safeEls = (function () { /* Convert value into an array, if it's a string, do querySelector. * * |Name |Type |Desc | @@ -3878,14 +3876,14 @@ export var $safeEls = _.$safeEls = (function () { function exports(val) { return toArr(isStr(val) ? new Select(val) : val); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ $attr ------------------------------ */ +/* ------------------------------ $attr ------------------------------ */ -export var $attr = _.$attr = (function () { +export var $attr = _.$attr = (function () { /* Element attribute manipulation. * * Get the value of an attribute for the first element in the set of matched elements. @@ -3974,14 +3972,14 @@ export var $attr = _.$attr = (function () { el.setAttribute(name, val); }); }); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ $data ------------------------------ */ +/* ------------------------------ $data ------------------------------ */ -export var $data = _.$data = (function () { +export var $data = _.$data = (function () { /* Wrapper of $attr, adds data- prefix to keys. * * ```javascript @@ -4010,14 +4008,14 @@ export var $data = _.$data = (function () { } return $attr(nodes, dataName, val); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ $css ------------------------------ */ +/* ------------------------------ $css ------------------------------ */ -export var $css = _.$css = (function () { +export var $css = _.$css = (function () { /* Element css manipulation. * * Get the computed style properties for the first element in the set of matched elements. @@ -4057,7 +4055,7 @@ export var $css = _.$css = (function () { */ /* dependencies - * isStr isObj kebabCase isUndef contain isNum $safeEls startWith prefix + * isStr isObj kebabCase isUndef contain isNum $safeEls prefix */ function exports(nodes, name, val) { @@ -4107,14 +4105,14 @@ export var $css = _.$css = (function () { var needPx = isNum(val) && !contain(cssNumProps, kebabCase(key)); return needPx ? val + 'px' : val; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ $insert ------------------------------ */ +/* ------------------------------ $insert ------------------------------ */ -export var $insert = _.$insert = (function (exports) { +export var $insert = _.$insert = (function (exports) { /* Insert html on different position. * * ### before @@ -4175,14 +4173,14 @@ export var $insert = _.$insert = (function (exports) { node.insertAdjacentHTML(type, val); }); }; - } + } - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ $offset ------------------------------ */ +/* ------------------------------ $offset ------------------------------ */ -export var $offset = _.$offset = (function () { +export var $offset = _.$offset = (function () { /* Get the position of the element in document. * * |Name |Type |Desc | @@ -4216,14 +4214,14 @@ export var $offset = _.$offset = (function () { width: Math.round(clientRect.width), height: Math.round(clientRect.height) }; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ $property ------------------------------ */ +/* ------------------------------ $property ------------------------------ */ -export var $property = _.$property = (function (exports) { +export var $property = _.$property = (function (exports) { /* Element property html, text, val getter and setter. * * ### html @@ -4273,14 +4271,14 @@ export var $property = _.$property = (function (exports) { node[name] = val; }); }; - } + } - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ $remove ------------------------------ */ +/* ------------------------------ $remove ------------------------------ */ -export var $remove = _.$remove = (function () { +export var $remove = _.$remove = (function () { /* Remove the set of matched elements from the DOM. * * |Name |Type |Desc | @@ -4309,14 +4307,14 @@ export var $remove = _.$remove = (function () { if (parent) parent.removeChild(el); }); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ $show ------------------------------ */ +/* ------------------------------ $show ------------------------------ */ -export var $show = _.$show = (function () { +export var $show = _.$show = (function () { /* Show elements. * * |Name |Type |Desc | @@ -4366,14 +4364,14 @@ export var $show = _.$show = (function () { } return elDisplay[elName]; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ delegate ------------------------------ */ +/* ------------------------------ delegate ------------------------------ */ -export var delegate = _.delegate = (function (exports) { +export var delegate = _.delegate = (function (exports) { /* Event delegation. * * ### add @@ -4499,7 +4497,7 @@ export var delegate = _.delegate = (function (exports) { handlers.delegateCount = 0; el.addEventListener( type, - function(e) { + function() { trigger.apply(el, arguments); }, false @@ -4561,14 +4559,14 @@ export var delegate = _.delegate = (function (exports) { this.stopPropagation(); } }) - }; + }; - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ $event ------------------------------ */ +/* ------------------------------ $event ------------------------------ */ -export var $event = _.$event = (function (exports) { +export var $event = _.$event = (function (exports) { /* bind events to certain dom elements. * * ```javascript @@ -4608,14 +4606,14 @@ export var $event = _.$event = (function (exports) { delegate[type](node, event, selector, handler); }); }; - } + } - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ concat ------------------------------ */ +/* ------------------------------ concat ------------------------------ */ -export var concat = _.concat = (function () { +export var concat = _.concat = (function () { /* Concat multiple arrays into a single array. * * |Name |Type |Desc | @@ -4646,14 +4644,103 @@ export var concat = _.concat = (function () { } return ret; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ some ------------------------------ */ +/* ------------------------------ mapObj ------------------------------ */ -export var some = _.some = (function () { +export var mapObj = _.mapObj = (function () { + /* Map for objects. + * + * |Name |Type |Desc | + * |--------|--------|------------------------------| + * |obj |object |Object to iterate over | + * |iteratee|function|Function invoked per iteration| + * |[ctx] |* |Function context | + * |return |object |New mapped object | + * + * ```javascript + * mapObj({a: 1, b: 2}, function (val, key) { return val + 1 }); // -> {a: 2, b: 3} + * ``` + */ + + /* module + * env: all + * test: all + */ + + /* dependencies + * safeCb keys + */ + + function exports(obj, iteratee, ctx) { + iteratee = safeCb(iteratee, ctx); + + var _keys = keys(obj), + len = _keys.length, + ret = {}; + + for (var i = 0; i < len; i++) { + var curKey = _keys[i]; + ret[curKey] = iteratee(obj[curKey], curKey, obj); + } + + return ret; + } + + return exports; +})(); + +/* ------------------------------ cloneDeep ------------------------------ */ + +export var cloneDeep = _.cloneDeep = (function () { + /* Recursively clone value. + * + * |Name |Type|Desc | + * |------|----|-----------------| + * |val |* |Value to clone | + * |return|* |Deep cloned Value| + * + * ```javascript + * var obj = [{a: 1}, {a: 2}]; + * var obj2 = cloneDeep(obj); + * console.log(obj[0] === obj2[1]); // -> false + * ``` + */ + + /* module + * env: all + * test: all + */ + + /* dependencies + * isObj isFn isArr mapObj + */ + + function exports(obj) { + if (isArr(obj)) { + return obj.map(function(val) { + return exports(val); + }); + } + + if (isObj(obj) && !isFn(obj)) { + return mapObj(obj, function(val) { + return exports(val); + }); + } + + return obj; + } + + return exports; +})(); + +/* ------------------------------ some ------------------------------ */ + +export var some = _.some = (function () { /* Check if predicate return truthy for any element. * * |Name |Type |Desc | @@ -4692,14 +4779,14 @@ export var some = _.some = (function () { } return false; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ $class ------------------------------ */ +/* ------------------------------ $class ------------------------------ */ -export var $class = _.$class = (function (exports) { +export var $class = _.$class = (function (exports) { /* Element class manipulations. * * ### add @@ -4807,14 +4894,14 @@ export var $class = _.$class = (function (exports) { function safeName(name) { return isStr(name) ? name.split(/\s+/) : toArr(name); - } + } - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ $ ------------------------------ */ +/* ------------------------------ $ ------------------------------ */ -export var $ = _.$ = (function () { +export var $ = _.$ = (function () { /* jQuery like style dom manipulator. * * ### Available methods @@ -4979,14 +5066,14 @@ export var $ = _.$ = (function () { function isGetter(name, val) { return isUndef(val) && isStr(name); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ memStorage ------------------------------ */ +/* ------------------------------ memStorage ------------------------------ */ -export var memStorage = _.memStorage = (function (exports) { +export var memStorage = _.memStorage = (function (exports) { /* Memory-backed implementation of the Web Storage API. * * A replacement for environments where localStorage or sessionStorage is not available. @@ -5065,14 +5152,14 @@ export var memStorage = _.memStorage = (function (exports) { function cloakedKeys() { return keys(cloak); - } + } - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ safeStorage ------------------------------ */ +/* ------------------------------ safeStorage ------------------------------ */ -export var safeStorage = _.safeStorage = (function () { +export var safeStorage = _.safeStorage = (function () { /* Safe localStorage and sessionStorage. */ @@ -5081,40 +5168,40 @@ export var safeStorage = _.safeStorage = (function () { */ function exports(type, memReplacement) { - if (isUndef(memReplacement)) memReplacement = true; + if (isUndef(memReplacement)) memReplacement = true - var ret; + var ret - switch (type) { - case 'local': - ret = window.localStorage; - break; - case 'session': - ret = window.sessionStorage; - break; - } + switch (type) { + case 'local': + ret = window.localStorage + break + case 'session': + ret = window.sessionStorage + break + } - try { - // Safari private browsing - var x = 'test-localStorage-' + Date.now(); - ret.setItem(x, x); - var y = ret.getItem(x); - ret.removeItem(x); - if (y !== x) throw new Error(); - } catch (e) { - if (memReplacement) return memStorage; - return; - } + try { + // Safari private browsing + var x = 'test-localStorage-' + Date.now() + ret.setItem(x, x) + var y = ret.getItem(x) + ret.removeItem(x) + if (y !== x) throw new Error() + } catch (e) { + if (memReplacement) return memStorage + return + } - return ret; - } + return ret + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ meta ------------------------------ */ +/* ------------------------------ meta ------------------------------ */ -export var meta = _.meta = (function () { +export var meta = _.meta = (function () { /* Document meta manipulation, turn name and content into key value pairs. * * Get meta content with given name. If name is omitted, all pairs will be return. @@ -5246,14 +5333,14 @@ export var meta = _.meta = (function () { function selectMeta(name) { return doc.querySelector('meta[name="' + name + '"]'); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ toNum ------------------------------ */ +/* ------------------------------ toNum ------------------------------ */ -export var toNum = _.toNum = (function (exports) { +export var toNum = _.toNum = (function (exports) { /* Convert value to a number. * * |Name |Type |Desc | @@ -5286,14 +5373,14 @@ export var toNum = _.toNum = (function (exports) { if (!isStr(val)) return val === 0 ? val : +val; return +val; - }; + }; - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ ms ------------------------------ */ +/* ------------------------------ ms ------------------------------ */ -export var ms = _.ms = (function () { +export var ms = _.ms = (function () { /* Convert time string formats to milliseconds. * * Turn time string into milliseconds. @@ -5364,14 +5451,14 @@ export var ms = _.ms = (function () { var suffixList = ['y', 'd', 'h', 'm', 's']; - var regStrTime = /^((?:\d+)?\.?\d+) *(s|m|h|d|y)?$/; + var regStrTime = /^((?:\d+)?\.?\d+) *(s|m|h|d|y)?$/; - return exports; -})(); + return exports; +})(); -/* ------------------------------ toInt ------------------------------ */ +/* ------------------------------ toInt ------------------------------ */ -export var toInt = _.toInt = (function () { +export var toInt = _.toInt = (function () { /* Convert value to an integer. * * |Name |Type |Desc | @@ -5400,14 +5487,14 @@ export var toInt = _.toInt = (function () { val = toNum(val); return val - (val % 1); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ detectBrowser ------------------------------ */ +/* ------------------------------ detectBrowser ------------------------------ */ -export var detectBrowser = _.detectBrowser = (function () { +export var detectBrowser = _.detectBrowser = (function () { /* Detect browser info using ua. * * |Name |Type |Desc | @@ -5493,14 +5580,14 @@ export var detectBrowser = _.detectBrowser = (function () { if (idx > -1) return toInt(ua.substring(idx + mark.length, ua.indexOf('.', idx))); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ nextTick ------------------------------ */ +/* ------------------------------ nextTick ------------------------------ */ -export var nextTick = _.nextTick = (function (exports) { +export var nextTick = _.nextTick = (function (exports) { /* Next tick for both node and browser. * * |Name|Type |Desc | @@ -5541,14 +5628,14 @@ export var nextTick = _.nextTick = (function (exports) { throw new TypeError(fn + ' is not a function'); return fn; - } + } - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ now ------------------------------ */ +/* ------------------------------ now ------------------------------ */ -export var now = _.now = (function (exports) { +export var now = _.now = (function (exports) { /* Gets the number of milliseconds that have elapsed since the Unix epoch. * * ```javascript @@ -5565,14 +5652,14 @@ export var now = _.now = (function (exports) { Date.now || function() { return new Date().getTime(); - }; + }; - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ restArgs ------------------------------ */ +/* ------------------------------ restArgs ------------------------------ */ -export var restArgs = _.restArgs = (function () { +export var restArgs = _.restArgs = (function () { /* This accumulates the arguments passed into an array, after a given index. * * |Name |Type |Desc | @@ -5620,14 +5707,14 @@ export var restArgs = _.restArgs = (function () { return fn.apply(this, args); }; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ partial ------------------------------ */ +/* ------------------------------ partial ------------------------------ */ -export var partial = _.partial = (function (exports) { +export var partial = _.partial = (function (exports) { /* Partially apply a function by filling in given arguments. * * |Name |Type |Desc | @@ -5660,14 +5747,14 @@ export var partial = _.partial = (function (exports) { return fn.apply(this, args); }; - }); + }); - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ once ------------------------------ */ +/* ------------------------------ once ------------------------------ */ -export var once = _.once = (function (exports) { +export var once = _.once = (function (exports) { /* Create a function that invokes once. * * |Name |Type |Desc | @@ -5692,14 +5779,14 @@ export var once = _.once = (function (exports) { * partial before */ - exports = partial(before, 2); + exports = partial(before, 2); - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ Emitter ------------------------------ */ +/* ------------------------------ Emitter ------------------------------ */ -export var Emitter = _.Emitter = (function (exports) { +export var Emitter = _.Emitter = (function (exports) { /* Event emitter class which provides observer pattern. * * ### on @@ -5804,14 +5891,14 @@ export var Emitter = _.Emitter = (function (exports) { obj._events = obj._events || {}; } } - ); + ); - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ Logger ------------------------------ */ +/* ------------------------------ Logger ------------------------------ */ -export var Logger = _.Logger = (function (exports) { +export var Logger = _.Logger = (function (exports) { /* Simple logger with level filter. * * ### constructor @@ -5936,14 +6023,14 @@ export var Logger = _.Logger = (function (exports) { SILENT: 5 }) } - ); + ); - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ Store ------------------------------ */ +/* ------------------------------ Store ------------------------------ */ -export var Store = _.Store = (function (exports) { +export var Store = _.Store = (function (exports) { /* Memory storage. * * Extend from Emitter. @@ -6093,14 +6180,14 @@ export var Store = _.Store = (function (exports) { save: function(data) { this._data = data; } - }); + }); - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ orientation ------------------------------ */ +/* ------------------------------ orientation ------------------------------ */ -export var orientation = _.orientation = (function (exports) { +export var orientation = _.orientation = (function (exports) { /* Screen orientation helper. * * ### on @@ -6158,14 +6245,14 @@ export var orientation = _.orientation = (function (exports) { }, 200); }, false - ); + ); - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ perfNow ------------------------------ */ +/* ------------------------------ perfNow ------------------------------ */ -export var perfNow = _.perfNow = (function (exports) { +export var perfNow = _.perfNow = (function (exports) { /* High resolution time up to microsecond precision. * * ```javascript @@ -6208,14 +6295,14 @@ export var perfNow = _.perfNow = (function (exports) { exports = function() { return now() - loadTime; }; - } + } - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ pxToNum ------------------------------ */ +/* ------------------------------ pxToNum ------------------------------ */ -export var pxToNum = _.pxToNum = (function () { +export var pxToNum = _.pxToNum = (function () { /* Turn string like '0px' to number. */ @@ -6224,15 +6311,15 @@ export var pxToNum = _.pxToNum = (function () { */ function exports(str) { - return toNum(str.replace('px', '')); - } + return toNum(str.replace('px', '')) + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ rmCookie ------------------------------ */ +/* ------------------------------ rmCookie ------------------------------ */ -export var rmCookie = _.rmCookie = (function () { +export var rmCookie = _.rmCookie = (function () { /* Loop through all possible path and domain to remove cookie. * * |Name|Type |Desc | @@ -6295,14 +6382,14 @@ export var rmCookie = _.rmCookie = (function () { return !cookie.get(key); } - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ rtrim ------------------------------ */ +/* ------------------------------ rtrim ------------------------------ */ -export var rtrim = _.rtrim = (function () { +export var rtrim = _.rtrim = (function () { /* Remove chars or white-spaces from end of string. * * |Name |Type |Desc | @@ -6349,14 +6436,14 @@ export var rtrim = _.rtrim = (function () { } return end >= 0 ? str.substring(0, end + 1) : ''; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ trim ------------------------------ */ +/* ------------------------------ trim ------------------------------ */ -export var trim = _.trim = (function () { +export var trim = _.trim = (function () { /* Remove chars or white-spaces from beginning end of string. * * |Name |Type |Desc | @@ -6387,14 +6474,14 @@ export var trim = _.trim = (function () { if (chars == null) return str.replace(regSpace, ''); return ltrim(rtrim(str, chars), chars); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ getFileName ------------------------------ */ +/* ------------------------------ getFileName ------------------------------ */ -export var getFileName = _.getFileName = (function () { +export var getFileName = _.getFileName = (function () { /* Extract file name from url. */ @@ -6403,19 +6490,19 @@ export var getFileName = _.getFileName = (function () { */ function exports(url) { - var ret = last(url.split('/')); + var ret = last(url.split('/')) - if (ret.indexOf('?') > -1) ret = trim(ret.split('?')[0]); + if (ret.indexOf('?') > -1) ret = trim(ret.split('?')[0]) - return ret === '' ? 'unknown' : ret; - } + return ret === '' ? 'unknown' : ret + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ query ------------------------------ */ +/* ------------------------------ query ------------------------------ */ -export var query = _.query = (function (exports) { +export var query = _.query = (function (exports) { /* Parse and stringify url query strings. * * ### parse @@ -6499,14 +6586,14 @@ export var query = _.query = (function (exports) { } }; - var regIllegalChars = /^(\?|#|&)/g; + var regIllegalChars = /^(\?|#|&)/g; - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ Url ------------------------------ */ +/* ------------------------------ Url ------------------------------ */ -export var Url = _.Url = (function (exports) { +export var Url = _.Url = (function (exports) { /* Simple url manipulator. * * ### constructor @@ -6715,14 +6802,14 @@ export var Url = _.Url = (function (exports) { var regProto = /^([a-z0-9.+-]+:)/i, regPort = /:[0-9]*$/, - hostEndingChars = ['/', '?', '#']; + hostEndingChars = ['/', '?', '#']; - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ ajax ------------------------------ */ +/* ------------------------------ ajax ------------------------------ */ -export var ajax = _.ajax = (function () { +export var ajax = _.ajax = (function () { /* Perform an asynchronous HTTP request. * * |Name |Type |Desc | @@ -6731,7 +6818,7 @@ export var ajax = _.ajax = (function () { * * Available options: * - * |Name |Type |Desc | + * |Name |Type |Desc | * |---------------------------------------------|-------------|---------------------------| * |url |string |Request url | * |data |string object|Request data | @@ -6885,14 +6972,14 @@ export var ajax = _.ajax = (function () { success: success, dataType: dataType }; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ type ------------------------------ */ +/* ------------------------------ type ------------------------------ */ -export var type = _.type = (function () { +export var type = _.type = (function () { /* Determine the internal JavaScript [[Class]] of an object. * * |Name |Type |Desc | @@ -6929,14 +7016,14 @@ export var type = _.type = (function () { return ret[1].toLowerCase(); } - var regObj = /^\[object\s+(.*?)]$/; + var regObj = /^\[object\s+(.*?)]$/; - return exports; -})(); + return exports; +})(); -/* ------------------------------ stringify ------------------------------ */ +/* ------------------------------ stringify ------------------------------ */ -export var stringify = _.stringify = (function () { +export var stringify = _.stringify = (function () { /* JSON stringify with support for circular object, function etc. * * Undefined is treated as null value. @@ -7004,14 +7091,14 @@ export var stringify = _.stringify = (function () { return val; }; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ LocalStore ------------------------------ */ +/* ------------------------------ LocalStore ------------------------------ */ -export var LocalStore = _.LocalStore = (function (exports) { +export var LocalStore = _.LocalStore = (function (exports) { /* LocalStorage wrapper. * * Extend from Store. @@ -7058,14 +7145,14 @@ export var LocalStore = _.LocalStore = (function (exports) { if (isEmpty(data)) return localStorage.removeItem(this._name); localStorage.setItem(this._name, stringify(data)); } - }); + }); - return exports; -})({}); + return exports; +})({}); -/* ------------------------------ stripHtmlTag ------------------------------ */ +/* ------------------------------ stripHtmlTag ------------------------------ */ -export var stripHtmlTag = _.stripHtmlTag = (function () { +export var stripHtmlTag = _.stripHtmlTag = (function () { /* Strip html tags from a string. * * |Name |Type |Desc | @@ -7087,14 +7174,14 @@ export var stripHtmlTag = _.stripHtmlTag = (function () { function exports(str) { return str.replace(regHtmlTag, ''); - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ tryIt ------------------------------ */ +/* ------------------------------ tryIt ------------------------------ */ -export var tryIt = _.tryIt = (function () { +export var tryIt = _.tryIt = (function () { /* Run function in a try catch. * * |Name|Type |Desc | @@ -7131,14 +7218,14 @@ export var tryIt = _.tryIt = (function () { cb(e); return; } - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ uniqId ------------------------------ */ +/* ------------------------------ uniqId ------------------------------ */ -export var uniqId = _.uniqId = (function () { +export var uniqId = _.uniqId = (function () { /* Generate a globally-unique id. * * |Name |Type |Desc | @@ -7162,14 +7249,14 @@ export var uniqId = _.uniqId = (function () { var id = ++idCounter + ''; return prefix ? prefix + id : id; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ unique ------------------------------ */ +/* ------------------------------ unique ------------------------------ */ -export var unique = _.unique = (function () { +export var unique = _.unique = (function () { /* Create duplicate-free version of an array. * * |Name |Type |Desc | @@ -7208,14 +7295,14 @@ export var unique = _.unique = (function () { function isEqual(a, b) { return a === b; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ viewportScale ------------------------------ */ +/* ------------------------------ viewportScale ------------------------------ */ -export var viewportScale = _.viewportScale = (function () { +export var viewportScale = _.viewportScale = (function () { /* Get viewport scale. * * ```javascript @@ -7262,14 +7349,14 @@ export var viewportScale = _.viewportScale = (function () { if (isNaN(ret)) return 1; return ret; - } + } - return exports; -})(); + return exports; +})(); -/* ------------------------------ wrap ------------------------------ */ +/* ------------------------------ wrap ------------------------------ */ -export var wrap = _.wrap = (function () { +export var wrap = _.wrap = (function () { /* Wrap the function inside a wrapper function, passing it as the first argument. * * |Name |Type |Desc | @@ -7298,9 +7385,9 @@ export var wrap = _.wrap = (function () { function exports(fn, wrapper) { return partial(wrapper, fn); - } + } - return exports; -})(); + return exports; +})(); export default _; \ No newline at end of file diff --git a/test/info.js b/test/info.js index ddc124c..9a3b02a 100644 --- a/test/info.js +++ b/test/info.js @@ -39,6 +39,12 @@ describe('info', function() { expect($tool.find('.eruda-content')).toContainText('eruda') }) + it('get', function() { + expect(tool.get()).toEqual([{ name: 'test', val: 'eruda' }]) + expect(tool.get('test')).toBe('eruda') + expect(tool.get('test2')).not.toBeDefined() + }) + it('remove', function() { tool.remove('test') expect($tool.find('li')).toHaveLength(0)