beyond-lib
Version:
beyond lib cookie storage dateformat htmlencode htmldecode datediff eventbus
3 lines • 12.9 kB
JavaScript
/*! beyondlib.js v2.1.1 2022.11.28 17:55:0 */
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.beyondlib=n():t.beyondlib=n()}(window,(function(){return function(t){var n={};function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(r,o,function(n){return t[n]}.bind(null,o));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=0)}([function(t,n,e){"use strict";e.r(n),e.d(n,"parseBrowser",(function(){return s})),e.d(n,"dateDiff",(function(){return j})),e.d(n,"dateFormat",(function(){return C})),e.d(n,"EventBus",(function(){return h})),e.d(n,"htmlHelper",(function(){return r})),e.d(n,"storage",(function(){return o})),e.d(n,"parseUrl",(function(){return tt})),e.d(n,"utilities",(function(){return i})),e.d(n,"delay",(function(){return k})),e.d(n,"lock",(function(){return U})),e.d(n,"createStore",(function(){return g})),e.d(n,"memory",(function(){return _})),e.d(n,"createProxy",(function(){return y}));var r={};e.r(r),e.d(r,"encodeHTML",(function(){return F})),e.d(r,"decodeHTML",(function(){return R}));var o={};e.r(o),e.d(o,"getCookie",(function(){return B})),e.d(o,"getRawCookie",(function(){return J})),e.d(o,"setCookie",(function(){return W})),e.d(o,"setRawCookie",(function(){return z})),e.d(o,"removeCookie",(function(){return $})),e.d(o,"set",(function(){return G})),e.d(o,"get",(function(){return K})),e.d(o,"remove",(function(){return Q})),e.d(o,"clear",(function(){return V}));var i={};e.r(i),e.d(i,"each",(function(){return rt})),e.d(i,"inArray",(function(){return ot})),e.d(i,"isArray",(function(){return et})),e.d(i,"isDate",(function(){return m})),e.d(i,"mergeFuncs",(function(){return ut})),e.d(i,"toArray",(function(){return ft})),e.d(i,"serialize",(function(){return H})),e.d(i,"isObject",(function(){return L}));var u=function(){this.name="unknow",this.version="unknow",this.device="unknow",this.platform="unknow",this.isIE=!1,this.isIE6=!1,this.isIE7=!1,this.isIE8=!1,this.isIE678=!1,this.isIE9=!1,this.isIE10=!1,this.isIE11=!1,this.isChrome=!1,this.isFirefox=!1,this.isMicroMessenger=!1,this.isOpera=!1,this.isSafari=!1,this.isEdge=!1,this.isWindows=!1,this.isMac=!1,this.isiPhone=!1,this.isiPad=!1,this.isiPod=!1,this.isAndriod=!1,this.isLinux=!1},a=[{name:"oIE",test:/msie ([\d.]+)/},{name:"IE",test:/trident.+rv:([\d.]+)/},{name:"Edge",test:/edge\/([\d.]+)/},{name:"MicroMessenger",test:/micromessenger.([\d.]+)/},{name:"Chrome",test:/chrome\/([\d.]+)/},{name:"Firefox",test:/firefox\/([\d.]+)/},{name:"Opera",test:/opera.([\d.]+)/},{name:"Safari",test:/version\/([\d.]+).*safari/}],f={Windows:/windows nt/,Mac:/macintosh/,iPhone:/iphone/,iPad:/ipad/,iPod:/ipod/,Android:/android/,Linux:/linux/},c=[6,7,8,9,10,11];function s(t){var n=new u;return t?function(t,n){for(var e in f)t["is"+e]=f[e].test(n);return t}(function(t,n){var e,r;for(e=0,r=a.length;e<r;e++){var o=a[e].test.exec(n);if(o){t.name="oIE"===a[e].name?"IE":a[e].name,t.version=o[1];break}}for(e=0,r=a.length;e<r;e++){var i=a[e].name;"oIE"===i&&(i="IE"),t["is"+i]=t.name===i}for(e=c.length-1;e>=0;e--)t["isIE"+c[e]]="IE"===t.name&&parseInt(t.version,10)===c[e];return t.isIE678=t.isIE6||t.isIE7||t.isIE8,t}(n,t=t.toLowerCase()),t):n}var l=function(){return(l=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)},h=function(){function t(){this.key=0,this.handlers={}}return t.prototype.on=function(t,n,e){var r=this;if(!t)throw new TypeError("type is null");var o,i,u=++this.key;return this.handlers[t]=this.handlers[t]||[],this.handlers[t].push({handler:n,key:u,once:null==e?void 0:e.once}),o=t,i=u,function(){return r.off(o,i)}},t.prototype.once=function(t,n){return this.on(t,n,{once:!0})},t.prototype.off=function(t,n){t&&this.handlers[t]&&(this.handlers[t]=this.handlers[t].filter((function(t){return t.key!==n})))},t.prototype.trigger=function(t,n,e,r){t&&this.handlers[t]&&(this.handlers[t].forEach((function(o){var i;"function"==typeof o.handler&&(i=o.handler(l({type:t,data:n},e)),(null==r?void 0:r.returnAsData)&&(n=i))})),this.handlers[t]=this.handlers[t].filter((function(t){return!t.once})))},t}(),p="clearCache",d="updateCache",g=function(t,n){var e;if(t){var r=new h,o=function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];return e||(e=t.apply(null,r).then((function(t){return"function"==typeof n?n(t):t})).catch((function(t){throw t})))};return o.updateCache=function(t){e=Promise.resolve(t),r.trigger(d)},o.hasCache=function(){return null!=e},o.clearCache=function(){e=null,r.trigger(p)},o.onUpdateCache=function(t){return r.on(d,t)},o.onClearCache=function(t){return r.on(p,t)},o}},y=function(t,n){return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return t.apply(null,e).then((function(t){return n?n(t):t})).catch((function(t){throw t}))}};function m(t){return"[object Date]"===Object.prototype.toString.call(t)}function v(t){return"number"==typeof t&&t==t}function w(t){if(m(t))return t;if(!v(t))throw new TypeError("The first argument must be a number");return new Date(t)}function b(t){if(v(t))return t;if(!m(t))throw new TypeError("The first argument must be a number");return t.valueOf()}function E(t,n){var e=w(t),r=w(n);return e.getFullYear()-r.getFullYear()}var O,j={years:E,months:function(t,n){var e=w(t),r=w(n);return 12*E(e,r)+(e.getMonth()-r.getMonth())},days:function(t,n){var e=w(t),r=w(n);return e=new Date(e.getFullYear(),e.getMonth(),e.getDate()),r=new Date(r.getFullYear(),r.getMonth(),r.getDate()),(e.valueOf()-r.valueOf())/864e5},hours:function(t,n){var e=b(t),r=b(n);return Math.floor(e/36e5)-Math.floor(r/36e5)},minutes:function(t,n){var e=b(t),r=b(n);return Math.floor(e/6e4)-Math.floor(r/6e4)},seconds:function(t,n){var e=b(t),r=b(n);return Math.floor(e/1e3)-Math.floor(r/1e3)}},I={y:function(t,n){var e=""+n.getFullYear();return t.length<=2?e.slice(2):t.length>2&&t.length<=4?e:M(e,t.length)},M:function(t,n){return M(n.getMonth()+1,t.length)},d:"getDate",H:"getHours",h:function(t,n){return M(n.getHours()%12,t.length)},m:"getMinutes",s:"getSeconds",S:function(t,n){return n.getMilliseconds()+""},u:"getDay"},T=[];for(var x in I)T.push(x+"+");function M(t,n){var e=String(t),r=e.length;return r<n?Array(n-r+1).join("0")+e:e}function S(t,n){var e=I[t.charAt(0)];return e?"function"==typeof e?e(t,n):M(n[e](),t.length):t}function C(t,n){var e=arguments.length;if(e<2)throw new TypeError("dateFormat must have two arguments");if(!m(t))throw new TypeError("date must be an instance of Date");if("string"!=typeof n)throw new TypeError("formatStr must be string");return n.replace(O,(function(n){return S(n,t)}))}function k(t,n,e){void 0===n&&(n=1);var r=null;return function(){for(var o=this,i=[],u=0;u<arguments.length;u++)i[u]=arguments[u];r&&(clearTimeout(r),r=null),r=window.setTimeout((function(){t.apply(e||o,i),r=null}),1e3*n)}}O=new RegExp(T.join("|"),"g");var A={"&":"&","<":"<",">":">",'"':""","'":"'"},P={};for(var D in A)P[A[D]]=D;var F=function(t){return(t=""+t).replace(/(&|<|>|'|")/g,(function(t){return A[t]||t}))},R=function(t){return(t=""+t).replace(/&|<|>|"|'/g,(function(t){return P[t]||t}))};function U(t,n,e){void 0===n&&(n=1);var r=!1;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];r||(r=!0,t.apply(e||this,o),setTimeout((function(){r=!1}),1e3*n))}}function L(t){if(null==t)return!1;if(Object.getPrototypeOf){var n=Object.getPrototypeOf(t);return!(!t||"object"!=typeof t||null!==n&&n!==Object.prototype)}return t&&"[object Object]"===Object.prototype.toString.call(t)}function H(t){var n,e=typeof t;if(null==t)return"";if("symbol"===e)return t;if("string"===e||"number"===e||"boolean"===e||(n=t,"[object RegExp]"===Object.prototype.toString.call(n)))return t+"";if("bigint"===e)return t+"n";if(function(t){return"[object Date]"===Object.prototype.toString.call(t)}(t))return t.valueOf()+"";if(Array.isArray(t))return"["+t.map((function(t){return H(t)})).join(",")+"]";if(L(t)){var r=Object.keys(t);return r.sort(),"{"+r.map((function(n){return n+"="+H(t[n])})).join("&")+"}"}return"function"==typeof t.valueOf?H(t.valueOf()):t+""}function _(t,n){var e={};return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];var i=n?n.apply(null,r):H(r);return i in e||(e[i]=t.apply(this,r)),e[i]}}var q=30,Y="/";function N(){if(!window||!window.localStorage)throw new TypeError("localStorage is undefined")}function B(t,n){void 0===n&&(n=!1);for(var e,r=document.cookie?document.cookie.split("; "):[],o=0,i=r.length;o<i;o++)if((e=r[o].split("="))[0]===encodeURIComponent(t))return n?e[1]:decodeURIComponent(e[1]);return null}function J(t){return B(t,!0)}function W(t,n,e,r,o,i,u){void 0===u&&(u=!1),e=null==e?q:Number(e),r=r||Y,t=encodeURIComponent(t),u||(n=encodeURIComponent(n)),document.cookie=t+"="+n+function(t,n,e,r){var o=[];if("number"==typeof t&&0!==t&&t==t){var i=new Date;i.setTime(i.getTime()+864e5*t),o.push("; expires="+i.toUTCString())}return o.push(n?"; path="+n:""),o.push(e?"; domain="+e:""),o.push(null!=r?"; "+r:""),o.join("")}(e,r,o,i)}function z(t,n,e,r,o,i){return W(t,n,e,r,o,i,!0)}function $(t){W(t,"",-30)}function G(t,n){var e;N();try{e=JSON.stringify(n)}catch(t){e=n+""}return window.localStorage.setItem(t,e)}function K(t){N();var n=window.localStorage.getItem(t);if(null==n)return n;try{return JSON.parse(n)}catch(t){return n}}function Q(t){return N(),window.localStorage.removeItem(t)}function V(){return N(),window.localStorage.clear()}var X={https:443,http:80},Z=function(){this.protocol="",this.auth="",this.user="",this.pass="",this.host="",this.port=-1,this.hostname="",this.hash="",this.search="",this.query={},this.pathname="",this.url="",this.origin=""};function tt(t){var n,e,r,o,i,u,a,f,c,s=new Z;if(!t)return s;if(s.url=t,"undefined"!=typeof window&&(0===t.indexOf("//")?t=window.location.href.split("/")[0]+t:t.indexOf("://")<0&&(t=window.location.href.split("://")[0]+"://"+t)),0<=(c=t.indexOf("#"))&&(s.hash=t.slice(c+1),t=t.slice(0,c)),0<=(u=t.indexOf("?"))&&(s.search=t.slice(u+1),t=t.slice(0,u),s.search))for(o=(a=s.search.split("&")).length-1;o>=0;o--)f=a[o].split("="),s.query[decodeURIComponent(f[0])]=decodeURIComponent(f[1]||"");return n=t.split("/"),s.protocol=n[0].toLowerCase().replace(/:$/,""),1===(e=n[2].split("@")).length?s.host=e[0]:(s.auth=e[0],r=s.auth.split(":"),s.user=r[0],s.pass=r[1]||"",s.host=e[1]),(e=s.host.split(":")).length>1?(s.hostname=e[0],s.port=+e[1]):(s.hostname=s.host,s.port=X[s.protocol]||s.port),s.pathname="",(i=n.slice(3)).length>0&&(s.pathname="/"+i.join("/")),s.origin=s.host,s.protocol&&(s.origin=s.protocol+"://"+s.origin),s}var nt=Object.prototype.toString,et="function"==typeof Array.isArray?Array.isArray:function(t){return!!t&&"[object Array]"===nt.call(t)},rt=function(t,n){var e=et(t);if(!e&&"number"!=typeof t)throw new TypeError("The first parameter must be array or number");if("function"!=typeof n)throw new TypeError("The second parameter must be function");for(var r=e?t.length:t,o=0;o<r;o++){var i=e?t[o]:o+1;if(!1===n.call(t,i,o,t))break}};function ot(t,n){if(arguments.length<2)throw new TypeError("2 arguments must be required");if(!et(n)||null==n.length)throw new TypeError("The second argument must be an Array or Array Like");if("function"==typeof n.includes)return n.includes(t);if("function"==typeof n.indexOf)return n.indexOf(t)>=0;for(var e=0,r=n.length;e<r;e++)if(n[e]===t)return!0;return!1}function it(t){return"function"==typeof t}function ut(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];if(!it(t))throw new TypeError("sourceFn must be a function");return arguments.length>1?function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];for(var o=t.apply(this,e),i=n.length,u=0;u<i;u++)it(n[u])&&n[u].apply(this,e);return o}:t}var at=Array.prototype.slice;function ft(t){if(!t||!("length"in t))throw new TypeError("Can not convert the argument to Array");try{return at.call(t,0)}catch(o){for(var n=t.length,e=Array(n),r=0;r<n;r++)e[r]=t[r];return e}}}])}));
//# sourceMappingURL=beyondlib.min.js.map