UNPKG

@buession/prototype

Version:

A native object extension framework for Javascript.

12 lines (11 loc) 16.6 kB
/*! * Buession prototype v4.1.8 * * @link https://prototype.buession.com/ * @source https://github.com/buession/buession-prototype * @copyright @ 2020-2025 Buession.com Inc. * @license MIT * @Build Time Wed, 16 Apr 2025 15:22:35 GMT */ define((function(){"use strict";window.Prototype={version:"v4.1.8",emptyFunction:function(){},K:function(t){return t}};const t={these:function(){let t;for(let e=0;e<arguments.length;e++){const n=arguments[e];if(Object.isFunction(n))try{t=n();break}catch(t){console.error(t)}}return t}};window.Try=t;class e{constructor(t){this.value=t}static of(t){return new e(t)}static ofNullable(t){return Object.isUndefinedOrNull(t)?e.empty():new e(t)}static empty(){return new e(null)}get(){if(null===this.value||void 0===this.value)throw"No value present";return this.value}orElse(t){return Object.isUndefinedOrNull(this.value)?t:this.value}isPresent(){return!1===Object.isUndefinedOrNull(this.value)}}var n;window.Optional=e,Object.type=function(t){return typeof t},Object.rawType=function(t){return Object.prototype.toString.call(t).slice(8,-1)},Object.isObject=function(t){return null!==t&&"object"==typeof t},Object.isPlainObject=function(t){return"[object Object]"===Object.prototype.toString.call(t)},Object.isMap=function(t){return"[object Map]"===Object.prototype.toString.call(t)},Object.isSet=function(t){return"[object Set]"===Object.prototype.toString.call(t)},Object.isFunction=function(t){return"function"===Object.type(t)},Object.isSymbol=function(t){if("symbol"==typeof t)return!0;try{const e=Symbol.prototype.toString;return"symbol"==typeof t.valueOf()&&/^Symbol\(.*\)$/.test(e.call(t))}catch(t){return!1}},Object.isPromise=function(t){return!1===Object.isUndefinedOrNull(t)&&!0===Object.isFunction(t.then)&&!0===Object.isFunction(t.catch)},Object.isPrimitive=function(t){return!0===Object.isBoolean(t)||!0===Object.isString(t)||!0===Object.isNumber(t)},Object.isArray=function(t){return!0===Array.isArray(t)},Object.isString=function(t){return"string"===Object.type(t)},Object.isNumber=function(t){return"number"===Object.type(t)},Object.isBoolean=function(t){return"boolean"===Object.type(t)},Object.isRegExp=function(t){return"RegExp"===Object.rawType(t)},Object.isFile=function(t){return t instanceof File},Object.isWindow=function(t){return Object.isUndefinedOrNull(t)&&t==t.window},Object.isElement=function(t){return!Object.isUndefinedOrNull(t)&&!(1!=t.nodeType)},Object.isEvent=function(t){return t instanceof Event},Object.isNull=function(t){return null===t},Object.isUndefined=function(t){return void 0===t},Object.isUndefinedOrNull=function(t){return!0===Object.isUndefined(t)||!0===Object.isNull(t)},Object.equals=function(t,e){if(t===e)return!0;if(!(t instanceof Object&&e instanceof Object))return!1;if(t.constructor!==e.constructor)return!1;if(Object.isArray(t)&&Object.isArray(e)&&t.length===e.length){for(let n=0;n<t.length;n++)if(!1===Object.equals(t[n],e[n]))return!1}else{if(!Object.isObject(t)||!Object.isObject(e)||Object.keys(t).length!==Object.keys(e).length)return!1;for(const n in t)if(t.hasOwnProperty.call(n)&&!1===Object.equals(t[n],e[n]))return!1}return!0},Object.clone=function(t){if(Object.isString(t))return String(t);if(Object.isArray(t))return Array.prototype.slice.apply(t);if(Object.isPlainObject(t)){const e=Object.create(null);return Object.keys(t).forEach((n=>{e[n]=Object.clone(t[n])})),e}return t},Object.omit=function(t,...e){const n=Object.clone(t);for(let t=0;t<e.length;t++){delete n[e[t]]}return n},Object.pick=function(t,...e){const n=Object.create(null);return e.forEach((e=>{n[e]=Object.clone(t[e])})),n},Array.prototype.isEmpty=function(){return 0===this.length},Array.prototype.exists=function(t){return-1!==this.indexOf(t)},Array.prototype.first=function(){if(0===this.length)throw"Array index out of range: 0";return this[0]},Array.prototype.last=function(){if(0===this.length)throw"Array index out of range: 0";return this[this.length-1]},Array.prototype.each=Array.prototype.forEach,Array.prototype.size=function(){return this.length},Array.prototype.merge=Array.prototype.concat,Array.prototype.compact=function(){return this.filter((t=>!1===Object.isUndefinedOrNull(t)))},Array.prototype.unique=function(){return Array.from(new Set(this))},Array.prototype.without=function(...t){return this.filter((e=>!1===t.includes(e)))},Array.prototype.clone=function(){return this.slice(0)},Array.prototype.clear=function(){return this.length=0,this},Date.prototype.isLeapYear=function(){const t=this.getFullYear();return t%4==0&&(t%100!=0||t%400==0)},Date.prototype.getSeason=function(){const t=this.getMonth();return t>=3&&t<=5?0:t>=6&&t<=8?1:t>=9&&t<=11?2:t>=12||t<=2?3:0},Date.prototype.getDayOfYear=function(){const t=[31,this.isLeapYear()?29:28,31,30,31,30,31,31,30,31,30,31];let e=0;for(let n=0,r=this.getMonth();n<r;n++)e+=t[n];return e},Date.prototype.getDaysOfYear=function(){return this.isLeapYear()?366:365},Date.prototype.format=function(t){if(!1===Object.isString(t))throw"Invalid argument format";const e={N:["Spring","Summer","Autumn","Winter"],A:["春","夏","秋","冬"]},n={f:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],F:["January","February","March","April","May","June","July","August","September","October","November","December"],C:["一","二","三","四","五","六","七","八","九","十","十一","十二"]},r={W:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],WW:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],WC:["日","一","二","三","四","五","六"]},i=()=>{const t=this.getMonth();return 11===t||t>=0&&t<=1?1:t>=2&&t<=4?2:t>=5&&t<=7?3:t>=8&&t<=10?4:0},o={y:t=>(this.getFullYear()+"").substring(4-t.length),n:()=>i(),N:()=>e.N[i()-1],A:()=>e.A[i()-1],M:t=>{const e=this.getMonth()+1;return(e<10?"0"+e:""+e).substring(2-t.length)},f:()=>{const t=this.getMonth();return n.f[t]},F:()=>{const t=this.getMonth();return n.F[t]},C:()=>{const t=this.getMonth();return n.C[t]},e:()=>this.getDay(),E:()=>this.getDay()+1,l:()=>{const t=this.getDay();return r.W[t]},L:()=>{const t=this.getDay();return r.WC[t]},w:()=>{const t=this.getDay();return r.WC[t]},d:t=>{const e=this.getDate();return(e<10?"0"+e:""+e).substring(2-t.length)},h:t=>{const e=this.getHours();let n=e%12==0?"12":e%12;return n=e<10?"0"+e:""+e,n.substring(2-t.length)},H:t=>{const e=this.getHours();return(e<10?"0"+e:""+e).substring(2-t.length)},m:t=>{const e=this.getMinutes();return(e<10?"0"+e:""+e).substring(2-t.length)},s:t=>{const e=this.getSeconds();return(e<10?"0"+e:""+e).substring(2-t.length)},S:t=>{const e=this.getMilliseconds();return(e<10?"0"+e:""+e).substring(2-t.length)}};return t.replace(/([ynNAMfFCdYTjeElLwWiohHmsSaOPZ])+/g,((t,e)=>{const n=o[e];return Object.isFunction(n)?n(t):t}))},function(t){t.NONE="None",t.LAX="Lax",t.STRICT="Strict"}(n||(n={}));Object.defineProperty(document,"fullScreen",{value:!1===Object.isUndefined(document.fullscreen)?document.fullscreen:!1===Object.isUndefined(document.mozFullScreen)?document.mozFullScreen:!1===Object.isUndefined(document.webkitIsFullScreen)?document.webkitIsFullScreen:!1===Object.isUndefined(document.msFullScreen)?document.msFullScreen:!1===Object.isUndefined(document.fullscreenElement)?null!==document.fullscreenElement:!1===Object.isUndefined(document.mozFullScreenElement)?null!==document.mozFullScreenElement:!1===Object.isUndefined(document.webkitFullscreenElement)?null!==document.webkitFullscreenElement:!1===Object.isUndefined(document.msFullscreenElement)&&null!==document.msFullscreenElement,configurable:!0,writable:!1}),Object.defineProperty(document,"fullScreenEnabled",{value:!1===Object.isUndefined(document.mozFullScreenEnabled)?document.mozFullScreenEnabled:!1===Object.isUndefined(document.webkitFullscreenEnabled)?document.webkitFullscreenEnabled:!1===Object.isUndefined(document.msFullscreenEnabled)?document.msFullscreenEnabled:!1===Object.isUndefined(document.fullscreenEnabled)&&document.fullscreenEnabled,configurable:!0,writable:!1}),Object.defineProperty(document,"fullScreenElement",{value:!1===Object.isUndefined(document.mozFullScreenElement)?document.mozFullScreenElement:!1===Object.isUndefined(document.webkitFullscreenElement)?document.webkitFullscreenElement:!1===Object.isUndefined(document.msFullscreenElement)?document.msFullscreenElement:!1===Object.isUndefined(document.fullscreenElement)?document.fullscreenElement:null,configurable:!0,writable:!1}),Object.defineProperty(document,"httpCookie",{value:new class{constructor(){}set(t,e,n){const r=t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent),i=e?encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent):"";let o="";if(n){if(o+=n.domain?"; domain="+n.domain:"",o+=n.path?"; path="+n.path:"",n.expires){o+="; expires="+(n.expires instanceof Date?n.expires:new Date(Date.now()+864e5*n.expires)).toUTCString()}!1===Object.isUndefinedOrNull(n.sameSite)&&(o+="; sameSite="+n.sameSite),Object.isBoolean(n.secure)&&!0===n.secure&&(o+="; secure"),Object.isBoolean(n.httpOnly)&&!0===n.httpOnly&&(o+="; httpOnly")}return document.cookie=r+"="+i+o}get(t){const e=document.cookie?document.cookie.split("; "):[];for(let n=0;n<e.length;n++){const r=e[n].split("="),i=decodeURIComponent(r[0]);let o=r.slice(1).join("=");if(i===t)return'"'===o[0]&&(o=o.slice(1,-1)),o.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)}return null}delete(t,e){const n=e||{};n.expires=-1,this.set(t,"",n)}},configurable:!0,writable:!1}),Document.prototype.requestFullscreen=function(){const t=document.documentElement;return Object.isFunction(t.mozRequestFullScreen)?t.mozRequestFullScreen():Object.isFunction(t.webkitRequestFullscreen)?t.webkitRequestFullscreen():Object.isFunction(t.msRequestFullscreen)?t.msRequestFullscreen():t.requestFullscreen()},Document.prototype.exitFullscreen=function(){return Object.isFunction(document.mozCancelFullScreen)?document.mozCancelFullScreen():Object.isFunction(document.mozExitFullScreen)?document.mozExitFullScreen():Object.isFunction(document.webkitCancelFullScreen)?document.webkitCancelFullScreen():Object.isFunction(document.webkitExitFullscreen)?document.webkitExitFullscreen():Object.isFunction(document.msExitFullscreen)?document.msExitFullscreen():document.exitFullscreen()},Function.prototype.argumentNames=function(){const t=this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/);if(null===t)return null;const e=t[1].replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g,"").replace(/\s+/g,"").split(", ");return 1!==e.length||e[0]?e:[]},Function.prototype.delay=function(t){const e=Array.prototype.slice.call(arguments,1);return setTimeout(this.apply(this,e),1e3*t)},Math.rand=function(t,e){t=t||0,e=e||Number.MAX_SAFE_INTEGER;const n=Math.random()*(e-t+1)+t,r=Math.round(n);return r<t?t:r>e?e:r},Number.prototype.toPaddedString=function(t,e){const n=this.toString(e||10);return"0".repeat(t-n.length)+n},Number.isOdd=function(t){return t%2==1},Number.isEven=function(t){return t%2==0},Number.isBetween=function(t,e,n,r=!1){return(e=e||0)>(n=n||0)&&(e^=n,e^=n^=e),1==r?t>=e&&t<=n:t>e&&t<n},String.prototype.exists=function(t){return this.indexOf(t)>=0},String.prototype.equals=function(t){return!1===Object.isUndefinedOrNull(t)&&this===t},String.prototype.equalsIgnoreCase=function(t){return null!=t&&this.toLowerCase()===t.toLowerCase()},String.prototype.isEmpty=function(){return 0===this.length},String.prototype.isNotEmpty=function(){return this.length>0},String.prototype.isBlank=function(){return 0===this.length||0===this.trim().length},String.prototype.isNotBlank=function(){return!1===this.isBlank()},String.prototype.repeat=function(t){if(t<1)return"";{const e=this.toString();let n=e;for(let r=0;r<t;r++)n+=e;return n}},String.prototype.left=function(t){return this.substring(0,t)},String.prototype.right=function(t){return this.substring(this.length-t,this.length)},String.prototype.truncation=function(t,e){return e=e||"...",this.length>t?this.slice(0,t<=e.length?t:t-e.length)+e:String(this)},String.prototype.ltrim=function(){return Object.isFunction(this.trimStart)?this.trimStart():this.replace(/^\s*/g,"")},String.prototype.rtrim=function(){return Object.isFunction(this.trimEnd)?this.trimEnd():this.replace(/\s*$/g,"")},String.prototype.startsWith=function(t){return 0===this.indexOf(t)},String.prototype.endsWith=function(t){const e=this.length-t.length;return e>=0&&this.lastIndexOf(t)===e},String.prototype.lcfirst=function(){return this.charAt(0).toLowerCase()+this.substring(1)},String.prototype.ucfirst=function(){return this.charAt(0).toUpperCase()+this.substring(1)},String.prototype.escapeHTML=function(){return this.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},String.prototype.unescapeHTML=function(){return this.replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&")},String.prototype.stripTag=function(t){return this.replace(new RegExp("<"+t+"(\\s+(\"[^\"]*\"|'[^']*'|[^>])+)?(/)?>|</"+t+">","gi"),"")},String.prototype.stripTags=function(t){if("string"==typeof t)return this.stripTag(t);if(Array.isArray(t)){let e=this.toString();for(let n=0;n<t.length;n++)e=e.stripTag(t[n]);return e}return this.toString()},String.prototype.stripScripts=function(){return this.replace(/<script[^>]*>([\S\s]*?)<\/script>/gim,"")},String.prototype.toArray=function(t){return this.split(t||"")},String.prototype.inspect=function(t){const e={"\b":"\\b","\t":"\\t","\r":"\\r","\n":"\\n","\f":"\\f","\\":"\\\\"},n=this.replace(/[\x00-\x1f\\]/g,(t=>t in e?e[t]:"\\u00"+t.charCodeAt(0).toPaddedString(2,16)));return t?'"'+n.replace(/"/g,'\\"')+'"':"'"+n.replace(/'/g,"\\'")+"'"},String.prototype.hashCode=function(){let t=0;if(0===t&&this.length>0)for(let e=0;e<this.length;e++)t=31*t+this.charCodeAt(e);return t},String.random=function(t,e="LETTER_NUMERIC"){let n="";if("CHINESE"===e){for(let e=0;e<t;e++)n+=String.fromCharCode(Math.rand(19968,40891));return n}const r="0123456789",i="abcdefghijklmnopqrstuvwxyz";let o,c;if("NUMERIC"===e)o=r;else if("LETTER"===e)o=i+i.toUpperCase();else if("LETTER_NUMERIC"===e||Object.isUndefinedOrNull(e))o=r+i+i.toUpperCase();else{if(!Object.isString(e))throw"Invalid argument type value, must be: NUMERIC, LETTER, LETTER_NUMERIC, CHINESE or String Characters";o=e}for(let e=0;e<t;e++)c=Math.rand(0,o.length-1),n+=o[c];return n},String.guid=function(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return t()+t()+"-"+t()+"-"+t()+"-"+t()+"-"+t()+t()+t()};const r=["Android","iPhone","iPod","Windows Phone","Mobile","Coolpad","mmp","SmartPhone","midp","wap","xoom","Symbian","J2ME","Blackberry","Wince"].some((t=>navigator.userAgent.exists(t))),i=/\(KHTML, like Gecko\) Chrome\//.test(navigator.userAgent),o=navigator.userAgent.exists("Firefox"),c=navigator.userAgent.exists("Mozilla"),s=navigator.userAgent.exists("Edge"),u=navigator.userAgent.exists("MSIE")&&navigator.userAgent.exists("compatible"),l=navigator.userAgent.exists("Opera"),a=navigator.userAgent.exists("Safari"),p=/Netscape([\d]*)\/([^\s]+)/i.test(navigator.userAgent);Object.defineProperty(window,"browser",{value:{userAgent:navigator.userAgent,name:navigator.appName,version:navigator.appVersion,cookieEnabled:navigator.cookieEnabled,language:navigator.language,languages:navigator.languages,isMobile:r,isChrome:i,isFirefox:o,isMozilla:c,isEdge:s,isMSIE:u,isOpera:l,isSafari:a,isNetscape:p},configurable:!0,writable:!1}),Window.prototype.copy=function(t){try{if(!0===Object.isObject(this.clipboardData))this.clipboardData.setData("text",t);else{const e=document.createElement("textarea");e.style.border="none",e.style.margin="0",e.style.padding="0",e.style.position="absolute",e.style.top="-9999px",e.style.left="-9999px",e.value=t,e.setAttribute("readonly",""),document.body.appendChild(e),e.setSelectionRange(0,t.length),e.select(),document.execCommand("copy"),e.remove()}}catch(t){console.error(t)}},Window.prototype.delay=function(t,e,...n){return((t,e,...n)=>{if("function"!=typeof t)throw new TypeError("Expected a function");return setTimeout((function(){t.apply(void 0,n)}),e)})(t,e||0,n)},Location.prototype.getParameters=function(){let t=this.search;const e={};if(-1!==t.indexOf("?")){t=t.substring(1);const n=t.split("&");for(let t=0;t<n.length;t++){const r=n[t].split("="),i=2==r.length?encodeURIComponent(r[1]):"";if(Object.isUndefined(e[r[0]]))e[r[0]]=i;else{if(!1===Object.isArray(e[r[0]])){const t=e[r[0]];delete e[r[0]],e[r[0]]=[t]}e[r[0]].push(i)}}}return e},Location.prototype.getParameter=function(t){return this.getParameters()[t]}})); //# sourceMappingURL=prototype.amd.min.js.map