UNPKG

libs-js

Version:

零散的工具函数,无依赖

2 lines (1 loc) 12.1 kB
"use strict";var _isObject=function(e){return"object"==typeof e?null!==e:"function"==typeof e},_anObject=function(e){if(!_isObject(e))throw TypeError(e+" is not an object!");return e},_defined=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e},_toObject=function(e){return Object(_defined(e))},ceil=Math.ceil,floor=Math.floor,_toInteger=function(e){return isNaN(e=+e)?0:(0<e?floor:ceil)(e)},min=Math.min,_toLength=function(e){return 0<e?min(_toInteger(e),9007199254740991):0},_stringAt=function(u){return function(e,t){var n,r,o=String(_defined(e)),i=_toInteger(t),c=o.length;return i<0||c<=i?u?"":void 0:(n=o.charCodeAt(i))<55296||56319<n||i+1===c||(r=o.charCodeAt(i+1))<56320||57343<r?u?o.charAt(i):n:u?o.slice(i,i+2):r-56320+(n-55296<<10)+65536}},at=_stringAt(!0),_advanceStringIndex=function(e,t,n){return t+(n?at(e,t).length:1)},toString={}.toString,_cof=function(e){return toString.call(e).slice(8,-1)};function createCommonjsModule(e,t){return e(t={exports:{}},t.exports),t.exports}var _core=createCommonjsModule(function(e){var t=e.exports={version:"2.6.11"};"number"==typeof __e&&(__e=t)}),_core_1=_core.version,_global=createCommonjsModule(function(e){var t=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=t)}),_shared=createCommonjsModule(function(e){var t="__core-js_shared__",n=_global[t]||(_global[t]={});(e.exports=function(e,t){return n[e]||(n[e]=void 0!==t?t:{})})("versions",[]).push({version:_core.version,mode:"global",copyright:"© 2019 Denis Pushkarev (zloirock.ru)"})}),id=0,px=Math.random(),_uid=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++id+px).toString(36))},_wks=createCommonjsModule(function(e){var t=_shared("wks"),n=_global.Symbol,r="function"==typeof n;(e.exports=function(e){return t[e]||(t[e]=r&&n[e]||(r?n:_uid)("Symbol."+e))}).store=t}),TAG=_wks("toStringTag"),ARG="Arguments"==_cof(function(){return arguments}()),tryGet=function(e,t){try{return e[t]}catch(e){}},_classof=function(e){var t,n,r;return void 0===e?"Undefined":null===e?"Null":"string"==typeof(n=tryGet(t=Object(e),TAG))?n:ARG?_cof(t):"Object"==(r=_cof(t))&&"function"==typeof t.callee?"Arguments":r},builtinExec=RegExp.prototype.exec,_regexpExecAbstract=function(e,t){var n=e.exec;if("function"==typeof n){var r=n.call(e,t);if("object"!=typeof r)throw new TypeError("RegExp exec method returned something other than an Object or null");return r}if("RegExp"!==_classof(e))throw new TypeError("RegExp#exec called on incompatible receiver");return builtinExec.call(e,t)},_flags=function(){var e=_anObject(this),t="";return e.global&&(t+="g"),e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),e.unicode&&(t+="u"),e.sticky&&(t+="y"),t},nativeExec=RegExp.prototype.exec,nativeReplace=String.prototype.replace,patchedExec=nativeExec,LAST_INDEX="lastIndex",UPDATES_LAST_INDEX_WRONG=function(){var e=/a/,t=/b*/g;return nativeExec.call(e,"a"),nativeExec.call(t,"a"),0!==e[LAST_INDEX]||0!==t[LAST_INDEX]}(),NPCG_INCLUDED=void 0!==/()??/.exec("")[1],PATCH=UPDATES_LAST_INDEX_WRONG||NPCG_INCLUDED;PATCH&&(patchedExec=function(e){var t,n,r,o,i=this;return NPCG_INCLUDED&&(n=new RegExp("^"+i.source+"$(?!\\s)",_flags.call(i))),UPDATES_LAST_INDEX_WRONG&&(t=i[LAST_INDEX]),r=nativeExec.call(i,e),UPDATES_LAST_INDEX_WRONG&&r&&(i[LAST_INDEX]=i.global?r.index+r[0].length:t),NPCG_INCLUDED&&r&&1<r.length&&nativeReplace.call(r[0],n,function(){for(o=1;o<arguments.length-2;o++)void 0===arguments[o]&&(r[o]=void 0)}),r});var _regexpExec=patchedExec,_fails=function(e){try{return!!e()}catch(e){return!0}},_descriptors=!_fails(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a}),document$1=_global.document,is=_isObject(document$1)&&_isObject(document$1.createElement),_domCreate=function(e){return is?document$1.createElement(e):{}},_ie8DomDefine=!_descriptors&&!_fails(function(){return 7!=Object.defineProperty(_domCreate("div"),"a",{get:function(){return 7}}).a}),_toPrimitive=function(e,t){if(!_isObject(e))return e;var n,r;if(t&&"function"==typeof(n=e.toString)&&!_isObject(r=n.call(e)))return r;if("function"==typeof(n=e.valueOf)&&!_isObject(r=n.call(e)))return r;if(!t&&"function"==typeof(n=e.toString)&&!_isObject(r=n.call(e)))return r;throw TypeError("Can't convert object to primitive value")},dP=Object.defineProperty,f=_descriptors?Object.defineProperty:function(e,t,n){if(_anObject(e),t=_toPrimitive(t,!0),_anObject(n),_ie8DomDefine)try{return dP(e,t,n)}catch(e){}if("get"in n||"set"in n)throw TypeError("Accessors not supported!");return"value"in n&&(e[t]=n.value),e},_objectDp={f:f},_propertyDesc=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}},_hide=_descriptors?function(e,t,n){return _objectDp.f(e,t,_propertyDesc(1,n))}:function(e,t,n){return e[t]=n,e},hasOwnProperty={}.hasOwnProperty,_has=function(e,t){return hasOwnProperty.call(e,t)},_functionToString=_shared("native-function-to-string",Function.toString),_redefine=createCommonjsModule(function(e){var i=_uid("src"),t="toString",c=(""+_functionToString).split(t);_core.inspectSource=function(e){return _functionToString.call(e)},(e.exports=function(e,t,n,r){var o="function"==typeof n;o&&(_has(n,"name")||_hide(n,"name",t)),e[t]!==n&&(o&&(_has(n,i)||_hide(n,i,e[t]?""+e[t]:c.join(String(t)))),e===_global?e[t]=n:r?e[t]?e[t]=n:_hide(e,t,n):(delete e[t],_hide(e,t,n)))})(Function.prototype,t,function(){return"function"==typeof this&&this[i]||_functionToString.call(this)})}),_aFunction=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e},_ctx=function(r,o,e){if(_aFunction(r),void 0===o)return r;switch(e){case 1:return function(e){return r.call(o,e)};case 2:return function(e,t){return r.call(o,e,t)};case 3:return function(e,t,n){return r.call(o,e,t,n)}}return function(){return r.apply(o,arguments)}},PROTOTYPE="prototype",$export=function(e,t,n){var r,o,i,c,u=e&$export.F,a=e&$export.G,l=e&$export.S,s=e&$export.P,_=e&$export.B,f=a?_global:l?_global[t]||(_global[t]={}):(_global[t]||{})[PROTOTYPE],p=a?_core:_core[t]||(_core[t]={}),d=p[PROTOTYPE]||(p[PROTOTYPE]={});for(r in a&&(n=t),n)i=((o=!u&&f&&void 0!==f[r])?f:n)[r],c=_&&o?_ctx(i,_global):s&&"function"==typeof i?_ctx(Function.call,i):i,f&&_redefine(f,r,i,e&$export.U),p[r]!=i&&_hide(p,r,c),s&&d[r]!=i&&(d[r]=i)};_global.core=_core,$export.F=1,$export.G=2,$export.S=4,$export.P=8,$export.B=16,$export.W=32,$export.U=64,$export.R=128;var _export=$export;_export({target:"RegExp",proto:!0,forced:_regexpExec!==/./.exec},{exec:_regexpExec});var SPECIES=_wks("species"),REPLACE_SUPPORTS_NAMED_GROUPS=!_fails(function(){var e=/./;return e.exec=function(){var e=[];return e.groups={a:"7"},e},"7"!=="".replace(e,"$<a>")}),SPLIT_WORKS_WITH_OVERWRITTEN_EXEC=function(){var e=/(?:)/,t=e.exec;e.exec=function(){return t.apply(this,arguments)};var n="ab".split(e);return 2===n.length&&"a"===n[0]&&"b"===n[1]}(),_fixReWks=function(n,e,t){var r=_wks(n),i=!_fails(function(){var e={};return e[r]=function(){return 7},7!=""[n](e)}),o=i?!_fails(function(){var e=!1,t=/a/;return t.exec=function(){return e=!0,null},"split"===n&&(t.constructor={},t.constructor[SPECIES]=function(){return t}),t[r](""),!e}):void 0;if(!i||!o||"replace"===n&&!REPLACE_SUPPORTS_NAMED_GROUPS||"split"===n&&!SPLIT_WORKS_WITH_OVERWRITTEN_EXEC){var c=/./[r],u=t(_defined,r,""[n],function(e,t,n,r,o){return t.exec===_regexpExec?i&&!o?{done:!0,value:c.call(t,n,r)}:{done:!0,value:e.call(n,t,r)}:{done:!1}}),a=u[0],l=u[1];_redefine(String.prototype,n,a),_hide(RegExp.prototype,r,2==e?function(e,t){return l.call(e,this,t)}:function(e){return l.call(e,this)})}},max=Math.max,min$1=Math.min,floor$1=Math.floor,SUBSTITUTION_SYMBOLS=/\$([$&`']|\d\d?|<[^>]*>)/g,SUBSTITUTION_SYMBOLS_NO_NAMED=/\$([$&`']|\d\d?)/g,maybeToString=function(e){return void 0===e?e:String(e)};_fixReWks("replace",2,function(o,i,E,T){return[function(e,t){var n=o(this),r=null==e?void 0:e[i];return void 0!==r?r.call(e,n,t):E.call(String(n),e,t)},function(e,t){var n=T(E,e,this,t);if(n.done)return n.value;var r=_anObject(e),o=String(this),i="function"==typeof t;i||(t=String(t));var c=r.global;if(c){var u=r.unicode;r.lastIndex=0}for(var a=[];;){var l=_regexpExecAbstract(r,o);if(null===l)break;if(a.push(l),!c)break;""===String(l[0])&&(r.lastIndex=_advanceStringIndex(o,_toLength(r.lastIndex),u))}for(var s="",_=0,f=0;f<a.length;f++){l=a[f];for(var p=String(l[0]),d=max(min$1(_toInteger(l.index),o.length),0),g=[],v=1;v<l.length;v++)g.push(maybeToString(l[v]));var h=l.groups;if(i){var S=[p].concat(g,d,o);void 0!==h&&S.push(h);var x=String(t.apply(void 0,S))}else x=b(p,o,d,g,h,t);_<=d&&(s+=o.slice(_,d)+x,_=d+p.length)}return s+o.slice(_)}];function b(i,c,u,a,l,e){var s=u+i.length,_=a.length,t=SUBSTITUTION_SYMBOLS_NO_NAMED;return void 0!==l&&(l=_toObject(l),t=SUBSTITUTION_SYMBOLS),E.call(e,t,function(e,t){var n;switch(t.charAt(0)){case"$":return"$";case"&":return i;case"`":return c.slice(0,u);case"'":return c.slice(s);case"<":n=l[t.slice(1,-1)];break;default:var r=+t;if(0==r)return e;if(_<r){var o=floor$1(r/10);return 0===o?e:o<=_?void 0===a[o-1]?t.charAt(1):a[o-1]+t.charAt(1):e}n=a[r-1]}return void 0===n?"":n})}});var MATCH=_wks("match"),_isRegexp=function(e){var t;return _isObject(e)&&(void 0!==(t=e[MATCH])?!!t:"RegExp"==_cof(e))},SPECIES$1=_wks("species"),_speciesConstructor=function(e,t){var n,r=_anObject(e).constructor;return void 0===r||null==(n=_anObject(r)[SPECIES$1])?t:_aFunction(n)},$min=Math.min,$push=[].push,$SPLIT="split",LENGTH="length",LAST_INDEX$1="lastIndex",MAX_UINT32=4294967295,SUPPORTS_Y=!_fails(function(){RegExp(MAX_UINT32,"y")});_fixReWks("split",2,function(o,i,v,h){var S;return S="c"=="abbc"[$SPLIT](/(b)*/)[1]||4!="test"[$SPLIT](/(?:)/,-1)[LENGTH]||2!="ab"[$SPLIT](/(?:ab)*/)[LENGTH]||4!="."[$SPLIT](/(.?)(.?)/)[LENGTH]||1<"."[$SPLIT](/()()/)[LENGTH]||""[$SPLIT](/.?/)[LENGTH]?function(e,t){var n=String(this);if(void 0===e&&0===t)return[];if(!_isRegexp(e))return v.call(n,e,t);for(var r,o,i,c=[],u=(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.unicode?"u":"")+(e.sticky?"y":""),a=0,l=void 0===t?MAX_UINT32:t>>>0,s=new RegExp(e.source,u+"g");(r=_regexpExec.call(s,n))&&!(a<(o=s[LAST_INDEX$1])&&(c.push(n.slice(a,r.index)),1<r[LENGTH]&&r.index<n[LENGTH]&&$push.apply(c,r.slice(1)),i=r[0][LENGTH],a=o,c[LENGTH]>=l));)s[LAST_INDEX$1]===r.index&&s[LAST_INDEX$1]++;return a===n[LENGTH]?!i&&s.test("")||c.push(""):c.push(n.slice(a)),c[LENGTH]>l?c.slice(0,l):c}:"0"[$SPLIT](void 0,0)[LENGTH]?function(e,t){return void 0===e&&0===t?[]:v.call(this,e,t)}:v,[function(e,t){var n=o(this),r=null==e?void 0:e[i];return void 0!==r?r.call(e,n,t):S.call(String(n),e,t)},function(e,t){var n=h(S,e,this,t,S!==v);if(n.done)return n.value;var r=_anObject(e),o=String(this),i=_speciesConstructor(r,RegExp),c=r.unicode,u=(r.ignoreCase?"i":"")+(r.multiline?"m":"")+(r.unicode?"u":"")+(SUPPORTS_Y?"y":"g"),a=new i(SUPPORTS_Y?r:"^(?:"+r.source+")",u),l=void 0===t?MAX_UINT32:t>>>0;if(0===l)return[];if(0===o.length)return null===_regexpExecAbstract(a,o)?[o]:[];for(var s=0,_=0,f=[];_<o.length;){a.lastIndex=SUPPORTS_Y?_:0;var p,d=_regexpExecAbstract(a,SUPPORTS_Y?o:o.slice(_));if(null===d||(p=$min(_toLength(a.lastIndex+(SUPPORTS_Y?0:_)),o.length))===s)_=_advanceStringIndex(o,_,c);else{if(f.push(o.slice(s,_)),f.length===l)return f;for(var g=1;g<=d.length-1;g++)if(f.push(d[g]),f.length===l)return f;_=s=p}}return f.push(o.slice(s)),f}]});var cookie=function(e,t){var n,r,o=e instanceof Array,i={},c=new Date;if(c.setTime(c.getTime()+2592e5),t||""===t)return document.cookie=encodeURIComponent(e)+"="+encodeURIComponent(t)+";path=/;expires="+c.toGMTString(),encodeURIComponent(t);if(n=document.cookie.split(";"),o){for(var u in r={},n){var a=n[u].split("=");a[0]=a[0].replace(/^( |[\s ])+|( |[\s ])+$/g,""),r[a[0]]=a[1]}for(var l in e)i[e[l]]=r[encodeURIComponent(e[l])];return i}for(var s in n){var _=n[s].split("=");if(_[0]=_[0].replace(/^( |[\s ])+|( |[\s ])+$/g,""),_[0]==encodeURIComponent(e))return decodeURIComponent(_[1])}return null};module.exports=cookie;