diff --git a/src/lib/util.js b/src/lib/util.js index 486fde7..b460790 100644 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -83,6 +83,31 @@ module.exports = (function () return exports; })(); + /* ------------------------------ startWith ------------------------------ */ + + 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 + * ``` + */ + + function exports(str, prefix) + { + return str.indexOf(prefix) === 0; + } + + return exports; + })(); + /* ------------------------------ inherits ------------------------------ */ var inherits = _.inherits = (function () @@ -120,7 +145,7 @@ module.exports = (function () if (objCreate) return Class.prototype = objCreate(SuperClass.prototype); noop.prototype = SuperClass.prototype; - Class.prototype = new noop() + Class.prototype = new noop(); } var objCreate = Object.create; @@ -350,6 +375,10 @@ module.exports = (function () * ``` */ + /* dependencies + * splitCase + */ + function exports(str) { var arr = splitCase(str); @@ -393,6 +422,10 @@ module.exports = (function () * ``` */ + /* dependencies + * splitCase + */ + function exports(str) { return splitCase(str).join('-'); @@ -469,6 +502,10 @@ module.exports = (function () * ``` */ + /* dependencies + * has + */ + exports = Object.keys || function (obj) { var ret = [], key; @@ -484,9 +521,49 @@ module.exports = (function () return exports; })({}); + /* ------------------------------ optimizeCb ------------------------------ */ + + var optimizeCb = _.optimizeCb = (function () + { + /* Used for function context binding. + */ + + /* dependencies + * isUndef + */ + + function exports(fn, ctx, argCount) + { + if (isUndef(ctx)) return fn; + + switch (argCount == null ? 3 : argCount) + { + case 1: return function (val) + { + return fn.call(ctx, val); + }; + case 3: return function (val, idx, collection) + { + return fn.call(ctx, val, idx, collection); + }; + case 4: return function (accumulator, val, idx, collection) + { + return fn.call(ctx, accumulator, val, idx, collection); + } + } + + return function () + { + return fn.apply(ctx, arguments); + }; + } + + return exports; + })(); + /* ------------------------------ endWith ------------------------------ */ - var endWith = _.endWith = (function () + _.endWith = (function () { /* Check if string ends with the given target string. * @@ -513,7 +590,7 @@ module.exports = (function () /* ------------------------------ escape ------------------------------ */ - var escape = _.escape = (function () + _.escape = (function () { /* Escapes a string for insertion into HTML, replacing &, <, >, ", `, and ' characters. * @@ -527,6 +604,10 @@ module.exports = (function () * ``` */ + /* dependencies + * keys + */ + function exports(str) { return regTest.test(str) ? str.replace(regReplace, replaceFn) : str; @@ -555,7 +636,7 @@ module.exports = (function () /* ------------------------------ escapeJsonStr ------------------------------ */ - var escapeJsonStr = _.escapeJsonStr = (function () + _.escapeJsonStr = (function () { function exports(str) { @@ -569,7 +650,7 @@ module.exports = (function () /* ------------------------------ escapeRegExp ------------------------------ */ - var escapeRegExp = _.escapeRegExp = (function () + _.escapeRegExp = (function () { /* Escape special chars to be used as literals in RegExp constructors. * @@ -593,7 +674,7 @@ module.exports = (function () /* ------------------------------ evalCss ------------------------------ */ - var evalCss = _.evalCss = (function () + _.evalCss = (function () { var mark = []; @@ -645,8 +726,12 @@ module.exports = (function () /* ------------------------------ getObjType ------------------------------ */ - var getObjType = _.getObjType = (function () + _.getObjType = (function () { + /* dependencies + * upperFirst + */ + function exports(obj) { if (obj.constructor && obj.constructor.name) return obj.constructor.name; @@ -725,6 +810,10 @@ module.exports = (function () * ``` */ + /* dependencies + * objToStr + */ + function exports(val) { return objToStr(val) === '[object Arguments]'; @@ -749,6 +838,10 @@ module.exports = (function () * ``` */ + /* dependencies + * objToStr + */ + function exports(val) { return objToStr(val) === '[object Date]'; @@ -776,6 +869,10 @@ module.exports = (function () * ``` */ + /* dependencies + * objToStr + */ + function exports(val) { var objStr = objToStr(val); @@ -798,6 +895,10 @@ module.exports = (function () * |return|boolean|True if value is correctly classified| */ + /* dependencies + * objToStr + */ + function exports(val) { return objToStr(val) === '[object Number]'; @@ -826,6 +927,10 @@ module.exports = (function () * ``` */ + /* dependencies + * isNum has isFn + */ + var MAX_ARR_IDX = Math.pow(2, 53) - 1; function exports(val) @@ -857,19 +962,25 @@ module.exports = (function () * ``` */ + /* dependencies + * isArrLike keys optimizeCb + */ + function exports(obj, iteratee, ctx) { + iteratee = optimizeCb(iteratee, ctx); + var i, len; if (isArrLike(obj)) { - for (i = 0, len = obj.length; i < len; i++) iteratee.call(ctx, obj[i], i, obj); + for (i = 0, len = obj.length; i < len; i++) iteratee(obj[i], i, obj); } else { var _keys = keys(obj); for (i = 0, len = _keys.length; i < len; i++) { - iteratee.call(ctx, obj[_keys[i]], _keys[i], obj); + iteratee(obj[_keys[i]], _keys[i], obj); } } @@ -892,6 +1003,10 @@ module.exports = (function () * |return |function|Result function, extend... | */ + /* dependencies + * isUndef each + */ + function exports(keysFn, defaults) { return function (obj) @@ -932,6 +1047,10 @@ module.exports = (function () * ``` */ + /* dependencies + * createAssigner allKeys + */ + exports = createAssigner(allKeys, true); return exports; @@ -939,7 +1058,7 @@ module.exports = (function () /* ------------------------------ cookie ------------------------------ */ - var cookie = _.cookie = (function (exports) + _.cookie = (function (exports) { /* Simple api for handling browser cookies. * @@ -980,6 +1099,10 @@ module.exports = (function () * ``` */ + /* dependencies + * defaults isNum isUndef + */ + var defOpts = { path: '/' }; function setCookie(key, val, options) @@ -1066,6 +1189,10 @@ module.exports = (function () * ``` */ + /* dependencies + * createAssigner allKeys + */ + exports = createAssigner(allKeys); return exports; @@ -1088,6 +1215,10 @@ module.exports = (function () * ``` */ + /* dependencies + * keys createAssigner + */ + exports = createAssigner(keys); return exports; @@ -1109,6 +1240,10 @@ module.exports = (function () * ``` */ + /* dependencies + * each + */ + function exports(obj) { var ret = []; @@ -1139,6 +1274,10 @@ module.exports = (function () * ``` */ + /* dependencies + * idxOf isArrLike values + */ + function exports(arr, val) { if (!isArrLike(arr)) arr = values(arr); @@ -1165,6 +1304,10 @@ module.exports = (function () * ``` */ + /* dependencies + * objToStr + */ + function exports(val) { return objToStr(val) === '[object String]'; @@ -1193,6 +1336,10 @@ module.exports = (function () * ``` */ + /* dependencies + * isStr isUndef + */ + function exports(obj, path) { if (isStr(path)) path = path.split('.'); @@ -1229,6 +1376,10 @@ module.exports = (function () * ``` */ + /* dependencies + * objToStr + */ + exports = Array.isArray || function (val) { return objToStr(val) === '[object Array]'; @@ -1255,6 +1406,10 @@ module.exports = (function () * ``` */ + /* dependencies + * isArrLike isArr isStr isArgs keys + */ + function exports(val) { if (val == null) return true; @@ -1272,7 +1427,7 @@ module.exports = (function () /* ------------------------------ isBool ------------------------------ */ - var isBool = _.isBool = (function () + _.isBool = (function () { /* Check if value is a boolean primitive. * @@ -1314,35 +1469,14 @@ module.exports = (function () return exports; })({}); - /* ------------------------------ startWith ------------------------------ */ - - 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 - * ``` - */ - - function exports(str, prefix) - { - return str.indexOf(prefix) === 0; - } - - return exports; - })(); - /* ------------------------------ isCrossOrig ------------------------------ */ - var isCrossOrig = _.isCrossOrig = (function () + _.isCrossOrig = (function () { + /* dependencies + * startWith + */ + var origin = window.location.origin; function exports(url) @@ -1355,7 +1489,7 @@ module.exports = (function () /* ------------------------------ isEl ------------------------------ */ - var isEl = _.isEl = (function () + _.isEl = (function () { /* Check if value is a DOM element. * @@ -1379,7 +1513,7 @@ module.exports = (function () /* ------------------------------ isErr ------------------------------ */ - var isErr = _.isErr = (function () + _.isErr = (function () { /* Check if value is an error. * @@ -1393,6 +1527,10 @@ module.exports = (function () * ``` */ + /* dependencies + * objToStr + */ + function exports(val) { return objToStr(val) === '[object Error]'; @@ -1403,7 +1541,7 @@ module.exports = (function () /* ------------------------------ isErudaEl ------------------------------ */ - var isErudaEl = _.isErudaEl = (function () + _.isErudaEl = (function () { function exports(el) { @@ -1440,6 +1578,10 @@ module.exports = (function () * ``` */ + /* dependencies + * keys + */ + function exports(obj, src) { var _keys = keys(src), @@ -1481,6 +1623,10 @@ module.exports = (function () * ``` */ + /* dependencies + * has + */ + function exports(fn, hashFn) { var memoize = function (key) @@ -1503,7 +1649,7 @@ module.exports = (function () /* ------------------------------ isMobile ------------------------------ */ - var isMobile = _.isMobile = (function (exports) + _.isMobile = (function (exports) { /* Check whether client is using a mobile browser using ua. * @@ -1517,6 +1663,10 @@ module.exports = (function () * ``` */ + /* dependencies + * isBrowser memoize + */ + var regMobileAll = /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i, regMobileFour = /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i; @@ -1532,7 +1682,7 @@ module.exports = (function () /* ------------------------------ isNull ------------------------------ */ - var isNull = _.isNull = (function () + _.isNull = (function () { /* Check if value is an Null. * @@ -1556,7 +1706,7 @@ module.exports = (function () /* ------------------------------ isRegExp ------------------------------ */ - var isRegExp = _.isRegExp = (function () + _.isRegExp = (function () { /* Check if value is a regular expression. * @@ -1570,6 +1720,10 @@ module.exports = (function () * ``` */ + /* dependencies + * objToStr + */ + function exports(val) { return objToStr(val) === '[object RegExp]'; @@ -1580,7 +1734,7 @@ module.exports = (function () /* ------------------------------ loadJs ------------------------------ */ - var loadJs = _.loadJs = (function () + _.loadJs = (function () { /* Inject script tag into page with given src value. * @@ -1674,6 +1828,10 @@ module.exports = (function () * ``` */ + /* dependencies + * repeat + */ + function exports(str, len, chars) { var strLen = str.length; @@ -1690,7 +1848,7 @@ module.exports = (function () /* ------------------------------ dateFormat ------------------------------ */ - var dateFormat = _.dateFormat = (function () + _.dateFormat = (function () { /* Simple but extremely useful date format function. * @@ -1738,6 +1896,10 @@ module.exports = (function () * ``` */ + /* dependencies + * isStr isDate toStr lpad + */ + function exports(date, mask, utc, gmt) { if (arguments.length === 1 && @@ -1925,6 +2087,10 @@ module.exports = (function () * ``` */ + /* dependencies + * extendOwn isMatch + */ + function exports(attrs) { attrs = extendOwn({}, attrs); @@ -1938,149 +2104,6 @@ module.exports = (function () return exports; })(); - /* ------------------------------ memStorage ------------------------------ */ - - var memStorage = _.memStorage = (function (exports) - { - /* Memory-backed implementation of the Web Storage API. - * - * A replacement for environments where localStorage or sessionStorage is not available. - * - * ```javascript - * var localStorage = window.localStorage || memStorage; - * localStorage.setItem('test', 'eris'); - * ``` - */ - - exports = { - getItem: function (key) - { - return (API_KEYS[key] ? cloak[key] : this[key]) || null; - }, - setItem: function (key, val) - { - API_KEYS[key] ? cloak[key] = val : this[key] = val; - }, - removeItem: function (key) - { - API_KEYS[key] ? delete cloak[key] : delete this[key]; - }, - key: function (i) - { - var keys = enumerableKeys(); - - return i >= 0 && i < keys.length ? keys[i] : null; - }, - clear: function () - { - var keys = uncloakedKeys(); - - /* eslint-disable no-cond-assign */ - for (var i = 0, key; key = keys[i]; i++) delete this[key]; - - keys = cloakedKeys(); - - /* eslint-disable no-cond-assign */ - for (i = 0; key = keys[i]; i++) delete cloak[key]; - } - }; - - Object.defineProperty(exports, 'length', { - enumerable: false, - configurable: true, - get: function () - { - return enumerableKeys().length; - } - }); - - var cloak = {}; - - var API_KEYS = { - getItem: 1, - setItem: 1, - removeItem: 1, - key: 1, - clear: 1, - length: 1 - }; - - function enumerableKeys() - { - return uncloakedKeys().concat(cloakedKeys()); - } - - function uncloakedKeys() - { - return keys(exports).filter(function (key) - { - return !API_KEYS[key]; - }); - } - - function cloakedKeys() - { - return keys(cloak); - } - - return exports; - })({}); - - /* ------------------------------ now ------------------------------ */ - - var now = _.now = (function (exports) - { - /* Gets the number of milliseconds that have elapsed since the Unix epoch. - * - * ```javascript - * now(); // -> 1468826678701 - * ``` - */ - - exports = Date.now || function () - { - return new Date().getTime(); - }; - - return exports; - })({}); - - /* ------------------------------ optimizeCb ------------------------------ */ - - var optimizeCb = _.optimizeCb = (function () - { - /* Used for function context binding. - */ - - function exports(fn, ctx, argCount) - { - if (isUndef(ctx)) return fn; - - switch (argCount == null ? 3 : argCount) - { - case 1: return function (val) - { - return fn.call(ctx, val); - }; - case 3: return function (val, idx, collection) - { - return fn.call(ctx, val, idx, collection); - }; - case 4: return function (accumulator, val, idx, collection) - { - return fn.call(ctx, accumulator, val, idx, collection); - } - } - - return function () - { - return fn.apply(ctx, arguments); - }; - } - - return exports; - })(); - /* ------------------------------ safeCb ------------------------------ */ var safeCb = _.safeCb = (function (exports) @@ -2088,6 +2111,10 @@ module.exports = (function () /* Create callback based on input value. */ + /* dependencies + * isFn isObj optimizeCb matcher identity + */ + exports = function (val, ctx, argCount) { if (val == null) return identity; @@ -2129,6 +2156,10 @@ module.exports = (function () * ``` */ + /* dependencies + * safeCb each + */ + function exports(obj, predicate, ctx) { var ret = []; @@ -2164,6 +2195,10 @@ module.exports = (function () * ``` */ + /* dependencies + * safeCb keys isArrLike + */ + function exports(obj, iteratee, ctx) { iteratee = safeCb(iteratee, ctx); @@ -2203,6 +2238,10 @@ module.exports = (function () * ``` */ + /* dependencies + * isArrLike map isArr isStr + */ + function exports(val) { if (!val) return []; @@ -2266,6 +2305,10 @@ module.exports = (function () * ``` */ + /* dependencies + * extend toArr inherits has safeGet + */ + function exports(methods, statics) { return Base.extend(methods, statics); @@ -2364,6 +2407,10 @@ module.exports = (function () * ``` */ + /* dependencies + * Class isStr each + */ + exports = Class({ className: 'Select', initialize: function (selector) @@ -2435,6 +2482,10 @@ module.exports = (function () * ``` */ + /* dependencies + * isStr toArr Select + */ + function exports(val) { return toArr(isStr(val) ? new Select(val) : val); @@ -2490,6 +2541,10 @@ module.exports = (function () * ``` */ + /* dependencies + * toArr isObj isStr each isUndef $safeEls + */ + function exports(els, name, val) { els = $safeEls(els); @@ -2551,6 +2606,10 @@ module.exports = (function () * ``` */ + /* dependencies + * $attr isStr isObj each + */ + function exports(nodes, name, val) { var dataName = name; @@ -2608,6 +2667,10 @@ module.exports = (function () * ``` */ + /* dependencies + * isStr isObj camelCase kebabCase isUndef contain isNum $safeEls startWith + */ + function exports(nodes, name, val) { nodes = $safeEls(nodes); @@ -2637,7 +2700,8 @@ module.exports = (function () var cssText = ';'; each(css, function (val, key) { - cssText += kebabCase(key) + ':' + addPx(key, val) + ';'; + key = dasherize(key); + cssText += key + ':' + addPx(key, val) + ';'; }); node.style.cssText += cssText; }); @@ -2660,6 +2724,14 @@ module.exports = (function () return needPx ? val + 'px' : val; } + function dasherize(str) + { + // -webkit- -o- + if (startWith(str, '-')) return str; + + return kebabCase(str); + } + return exports; })(); @@ -2703,6 +2775,10 @@ module.exports = (function () * ``` */ + /* dependencies + * each $safeEls + */ + exports = { before: insertFactory('beforebegin'), after: insertFactory('afterend'), @@ -2741,6 +2817,10 @@ module.exports = (function () * ``` */ + /* dependencies + * $safeEls + */ + function exports(els) { els = $safeEls(els); @@ -2788,6 +2868,10 @@ module.exports = (function () * ``` */ + /* dependencies + * isUndef each $safeEls + */ + exports = { html: propFactory('innerHTML'), text: propFactory('textContent'), @@ -2827,6 +2911,10 @@ module.exports = (function () * ``` */ + /* dependencies + * each $safeEls + */ + function exports(els) { els = $safeEls(els); @@ -2857,6 +2945,10 @@ module.exports = (function () * ``` */ + /* dependencies + * each $safeEls + */ + function exports(els) { els = $safeEls(els); @@ -2929,6 +3021,10 @@ module.exports = (function () * ``` */ + /* dependencies + * Class contain + */ + function retTrue() { return true } function retFalse() { return false } @@ -3094,6 +3190,10 @@ module.exports = (function () * ``` */ + /* dependencies + * delegate isUndef $safeEls + */ + exports = { on: eventFactory('add'), off: eventFactory('remove') @@ -3142,6 +3242,10 @@ module.exports = (function () * ``` */ + /* dependencies + * safeCb isArrLike keys + */ + function exports(obj, predicate, ctx) { predicate = safeCb(predicate, ctx); @@ -3215,6 +3319,10 @@ module.exports = (function () * ``` */ + /* dependencies + * toArr some $safeEls isStr + */ + exports = { add: function (els, name) { @@ -3280,7 +3388,7 @@ module.exports = (function () /* ------------------------------ $ ------------------------------ */ - var $ = _.$ = (function () + _.$ = (function () { /* jQuery like style dom manipulator. * @@ -3302,6 +3410,10 @@ module.exports = (function () * ``` */ + /* dependencies + * Select $offset $show $css $attr $property last $remove $data $event $class $insert isUndef isStr + */ + function exports(selector) { return new Select(selector); @@ -3324,10 +3436,10 @@ module.exports = (function () }, first: function () { - return $(this[0]); + return exports(this[0]); }, last: function () { - return $(last(this)); + return exports(last(this)); }, get: function (idx) { @@ -3335,7 +3447,7 @@ module.exports = (function () }, eq: function (idx) { - return $(this[idx]); + return exports(this[idx]); }, on: function (event, selector, handler) { @@ -3433,7 +3545,7 @@ module.exports = (function () }, parent: function () { - return $(this[0].parentNode); + return exports(this[0].parentNode); }, append: function (val) { @@ -3469,6 +3581,117 @@ module.exports = (function () return exports; })(); + /* ------------------------------ memStorage ------------------------------ */ + + var memStorage = _.memStorage = (function (exports) + { + /* Memory-backed implementation of the Web Storage API. + * + * A replacement for environments where localStorage or sessionStorage is not available. + * + * ```javascript + * var localStorage = window.localStorage || memStorage; + * localStorage.setItem('test', 'eris'); + * ``` + */ + + /* dependencies + * keys + */ + + exports = { + getItem: function (key) + { + return (API_KEYS[key] ? cloak[key] : this[key]) || null; + }, + setItem: function (key, val) + { + API_KEYS[key] ? cloak[key] = val : this[key] = val; + }, + removeItem: function (key) + { + API_KEYS[key] ? delete cloak[key] : delete this[key]; + }, + key: function (i) + { + var keys = enumerableKeys(); + + return i >= 0 && i < keys.length ? keys[i] : null; + }, + clear: function () + { + var keys = uncloakedKeys(); + + /* eslint-disable no-cond-assign */ + for (var i = 0, key; key = keys[i]; i++) delete this[key]; + + keys = cloakedKeys(); + + /* eslint-disable no-cond-assign */ + for (i = 0; key = keys[i]; i++) delete cloak[key]; + } + }; + + Object.defineProperty(exports, 'length', { + enumerable: false, + configurable: true, + get: function () + { + return enumerableKeys().length; + } + }); + + var cloak = {}; + + var API_KEYS = { + getItem: 1, + setItem: 1, + removeItem: 1, + key: 1, + clear: 1, + length: 1 + }; + + function enumerableKeys() + { + return uncloakedKeys().concat(cloakedKeys()); + } + + function uncloakedKeys() + { + return keys(exports).filter(function (key) + { + return !API_KEYS[key]; + }); + } + + function cloakedKeys() + { + return keys(cloak); + } + + return exports; + })({}); + + /* ------------------------------ now ------------------------------ */ + + _.now = (function (exports) + { + /* Gets the number of milliseconds that have elapsed since the Unix epoch. + * + * ```javascript + * now(); // -> 1468826678701 + * ``` + */ + + exports = Date.now || function () + { + return new Date().getTime(); + }; + + return exports; + })({}); + /* ------------------------------ restArgs ------------------------------ */ var restArgs = _.restArgs = (function () @@ -3538,6 +3761,10 @@ module.exports = (function () * ``` */ + /* dependencies + * restArgs toArr + */ + exports = restArgs(function (fn, partials) { return function () @@ -3573,6 +3800,10 @@ module.exports = (function () * ``` */ + /* dependencies + * partial before + */ + exports = partial(before, 2); return exports; @@ -3626,6 +3857,10 @@ module.exports = (function () * ``` */ + /* dependencies + * Class has each slice once + */ + exports = Class({ initialize: function Emitter() { @@ -3682,8 +3917,12 @@ module.exports = (function () /* ------------------------------ orientation ------------------------------ */ - var orientation = _.orientation = (function (exports) + _.orientation = (function (exports) { + /* dependencies + * Emitter + */ + Emitter.mixin(exports); window.addEventListener('orientationchange', function () @@ -3713,6 +3952,10 @@ module.exports = (function () * ``` */ + /* dependencies + * isNum isObj isFn isStr + */ + exports = function (val) { if (isNum(val)) return val; @@ -3733,8 +3976,12 @@ module.exports = (function () /* ------------------------------ pxToNum ------------------------------ */ - var pxToNum = _.pxToNum = (function () + _.pxToNum = (function () { + /* dependencies + * toNum + */ + function exports(str) { return toNum(str.replace('px', '')); @@ -3815,6 +4062,10 @@ module.exports = (function () * ``` */ + /* dependencies + * ltrim rtrim + */ + var regSpace = /^\s+|\s+$/g; function exports(str, chars) @@ -3829,8 +4080,12 @@ module.exports = (function () /* ------------------------------ getFileName ------------------------------ */ - var getFileName = _.getFileName = (function () + _.getFileName = (function () { + /* dependencies + * last trim + */ + function exports(url) { var ret = last(url.split('/')); @@ -3874,6 +4129,10 @@ module.exports = (function () * ``` */ + /* dependencies + * trim each isUndef isArr map isEmpty filter isObj + */ + exports = { parse: function (str) { @@ -3927,7 +4186,7 @@ module.exports = (function () /* ------------------------------ Url ------------------------------ */ - var Url = _.Url = (function (exports) + _.Url = (function (exports) { /* Simple url manipulator. * @@ -4001,6 +4260,10 @@ module.exports = (function () * ``` */ + /* dependencies + * Class extend trim query isEmpty each toArr + */ + exports = Class({ className: 'Url', initialize: function (url) @@ -4148,7 +4411,7 @@ module.exports = (function () /* ------------------------------ ajax ------------------------------ */ - var ajax = _.ajax = (function () + _.ajax = (function () { /* Perform an asynchronous HTTP request. * @@ -4202,6 +4465,10 @@ module.exports = (function () * ``` */ + /* dependencies + * isFn noop defaults isObj query + */ + function exports(options) { defaults(options, exports.setting); @@ -4316,8 +4583,12 @@ module.exports = (function () /* ------------------------------ safeStorage ------------------------------ */ - var safeStorage = _.safeStorage = (function () + _.safeStorage = (function () { + /* dependencies + * isUndef memStorage + */ + function exports(type, memReplacement) { if (isUndef(memReplacement)) memReplacement = true; @@ -4352,7 +4623,7 @@ module.exports = (function () /* ------------------------------ stripHtmlTag ------------------------------ */ - var stripHtmlTag = _.stripHtmlTag = (function () + _.stripHtmlTag = (function () { /* Strip html tags from a string. * @@ -4378,7 +4649,7 @@ module.exports = (function () /* ------------------------------ toInt ------------------------------ */ - var toInt = _.toInt = (function () + _.toInt = (function () { /* Convert value to an integer. * @@ -4393,6 +4664,10 @@ module.exports = (function () * ``` */ + /* dependencies + * toNum + */ + function exports(val) { if (!val) return val === 0 ? val : 0; @@ -4407,7 +4682,7 @@ module.exports = (function () /* ------------------------------ uniqId ------------------------------ */ - var uniqId = _.uniqId = (function () + _.uniqId = (function () { /* Generate a globally-unique id. * @@ -4435,7 +4710,7 @@ module.exports = (function () /* ------------------------------ unique ------------------------------ */ - var unique = _.unique = (function () + _.unique = (function () { /* Create duplicate-free version of an array. * @@ -4450,6 +4725,10 @@ module.exports = (function () * ``` */ + /* dependencies + * filter + */ + function exports(arr, compare) { compare = compare || isEqual; @@ -4477,7 +4756,7 @@ module.exports = (function () /* ------------------------------ wrap ------------------------------ */ - var wrap = _.wrap = (function () + _.wrap = (function () { /* Wrap the function inside a wrapper function, passing it as the first argument. * @@ -4496,6 +4775,10 @@ module.exports = (function () * ``` */ + /* dependencies + * partial + */ + function exports(fn, wrapper) { return partial(wrapper, fn);