UNPKG

missing-native-js-functions

Version:

mnJSf that should be the base library for every JS project

3 lines (2 loc) 9.49 kB
var mnjsf=function(){"use strict";var a=Math.floor;function b(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a["default"]:a}function c(a,b){return b={exports:{}},a(b,b.exports),b.exports}var d="undefined"==typeof globalThis?"undefined"==typeof window?"undefined"==typeof global?"undefined"==typeof self?{}:self:global:window:globalThis,e=c(function(a,b){Object.defineProperty(b,"__esModule",{value:!0}),b.define=void 0,b.define=function(a,b){Object.keys(b).forEach(function(c){try{a[c]||Object.defineProperty(a,c,{enumerable:!1,writable:!0,configurable:!0,value:b[c]})}catch(a){}})}});b(e),e.define;var f=c(function(b,c){var f=d&&d.__read||function(a,b){var c="function"==typeof Symbol&&a[Symbol.iterator];if(!c)return a;var d,f,g=c.call(a),h=[];try{for(;(void 0===b||0<b--)&&!(d=g.next()).done;)h.push(d.value)}catch(a){f={error:a}}finally{try{d&&!d.done&&(c=g["return"])&&c.call(g)}finally{if(f)throw f.error}}return h},g=d&&d.__spreadArray||function(a,b,c){if(c||2===arguments.length)for(var d,e=0,f=b.length;e<f;e++)(d||!(e in b))&&(d||(d=Array.prototype.slice.call(b,0,e)),d[e]=b[e]);return a.concat(d||Array.prototype.slice.call(b))};Object.defineProperty(c,"__esModule",{value:!0}),(0,e.define)(Array.prototype,{remove:function(a){var b=this.indexOf(a);return-1===b?this:(this.splice(b,1),this)},insert:function(a,b){return null==b&&(b=this.length),this.splice(b,0,a),this},flat:function(a){return void 0===a&&(a=1),this.reduce(function(b,c){return Array.isArray(c)&&1<=a||-1===a?b.push.apply(b,g([],f(c.flat(a--)),!1)):b.push(c)},[])},last:function(){return this[this.length-1]},first:function(){return this[0]},unique:function(a){return"function"==typeof a?g([],f(new Map(this.map(function(b,c,d){return[a(b,c,d),b]})).values()),!1):g([],f(new Set(this)),!1)},random:function(){return this[a(Math.random()*this.length)]},randomIndex:function(){return a(Math.random()*this.length)},insertRandom:function(a){this.insert(a,this.randomIndex())},shuffle:function(){for(var b,c,d=this.length-1;0<d;d--)c=a(Math.random()*(d+1)),b=f([this[c],this[d]],2),this[d]=b[0],this[c]=b[1];return this},findMap:function(a){if("function"==typeof a)for(var b,c=0;c<this.length;c++)if(b=a(this[c],c,this),b)return b},findLast:function(a){if("function"==typeof a){for(var b=this.length;0<=b;b--)if(a(this[b],b,this))return this[b];return null}},findLastIndex:function(a){if("function"!=typeof a)return-1;for(var b=this.length-1;0<=b;b--)if(a(this[b],b,this))return b;return-1},count:function(a){var b=["string","number","object","array"],c=0;return this.forEach(function(d){if(d===a)return void c++;if("function"==typeof a){var e=a.name.toLowerCase();if(b.includes(e)&&typeof d===e)return void c++;if(d instanceof a)return void c++}"string"==typeof d&&d.match(a)&&c++}),c},missing:function(a){return this.filter(function(b){return!a.includes(b)})},similarities:function(a){return this.filter(function(b){return a.includes(b)})}})});b(f);var g=c(function(a,b){var c=d&&d.__read||function(a,b){var c="function"==typeof Symbol&&a[Symbol.iterator];if(!c)return a;var d,f,g=c.call(a),h=[];try{for(;(void 0===b||0<b--)&&!(d=g.next()).done;)h.push(d.value)}catch(a){f={error:a}}finally{try{d&&!d.done&&(c=g["return"])&&c.call(g)}finally{if(f)throw f.error}}return h},e=d&&d.__spreadArray||function(a,b,c){if(c||2===arguments.length)for(var d,e=0,f=b.length;e<f;e++)(d||!(e in b))&&(d||(d=Array.prototype.slice.call(b,0,e)),d[e]=b[e]);return a.concat(d||Array.prototype.slice.call(b))};Object.defineProperty(b,"__esModule",{value:!0});try{globalThis.atob||(globalThis.atob=function(a){return Buffer.from(a,"base64").toString("utf8")}),globalThis.btoa||(globalThis.btoa=function(a){return Buffer.from(a.toString(),"utf8").toString("base64")}),globalThis.setIntervalNow||(globalThis.setIntervalNow=function(a,b){for(var d=[],f=2;f<arguments.length;f++)d[f-2]=arguments[f];if("function"==typeof a){var g=a.bind.apply(a,e([this],c(d),!1));return g(),setInterval(g,b)}}),globalThis.sleep||(globalThis.sleep=function(a){return new Promise(function(b){return setTimeout(b,a)})})}catch(a){}});b(g);var h=c(function(a,b){Object.defineProperty(b,"__esModule",{value:!0}),(0,e.define)(Math,{randomBetween:function(a,b){return Math.random()*(b-a)+a},randomIntBetween:function(a,b){return Math.round(Math.randomBetween(a,b))}})});b(h);var i=c(function(b,c){Object.defineProperty(c,"__esModule",{value:!0}),(0,e.define)(Number.prototype,{toInt:function(){return a(this)}})});b(i);var j=c(function(a,b){Object.defineProperty(b,"__esModule",{value:!0}),(0,e.define)(Promise.prototype,{caught:function(){return this.catch(console.error),this}})});b(j);var k=c(function(a,b){function c(a){return a.replace(/[.*+\-?^${}()|[\]\\]/g,"\\$&")}Object.defineProperty(b,"__esModule",{value:!0}),(0,e.define)(String.prototype,{capitalize:function(){return this.slice(0,1).toUpperCase()+this.slice(1)},title:function(){return this.split(" ").map(function(a){return a.capitalize()}).join(" ")},replaceAll:function(a,b){return this.replace(new RegExp(c(a),"g"),b)},similarity:function(a){var b=Math.min,c=this.toLowerCase();a=a.toLowerCase(),c.length<a.length&&(c=a,a=this);var d=c.length;if(0==d)return 1;for(var e,f=[],g=0;g<=c.length;g++){e=g;for(var h=0;h<=a.length;h++)if(0==g)f[h]=h;else if(0<h){var k=f[h-1];c.charAt(g-1)!=a.charAt(h-1)&&(k=b(b(k,e),f[h])+1),f[h-1]=e,e=k}0<g&&(f[a.length]=e)}return(d-f[a.length])/parseFloat(d)},join:function(a){return"string"==typeof a?a:a.join(this)},partition:function(a){if(!this.includes(a))return[this];for(var b=[],c=this.split(a),d=0;d<c.length;d++)b.push(c[d]),d!=c.length-1&&b.push(a);return b},toNumber:function(){return+this},toBigInt:function(){try{return BigInt(this)}catch(a){return NaN}},equalsIgnoreCase:function(a){return this.toLowerCase()===a.toLowerCase()},count:function(a){return this.split(a).length-1},swapcase:function(){return this.split("").map(function(a){return a===a.toUpperCase()?a.toLowerCase():a.toUpperCase()}).join("")},toObject:function(){return JSON.parse(this)},toBoolean:function(){switch(this.toLowerCase().trim()){case"true":case"yes":case"1":return!0;case"false":case"no":case"0":case null:return!1;default:return!!this;}}})});b(k);var l=c(function(b,c){var f=d&&d.__assign||function(){return f=Object.assign||function(a){for(var b,c=1,d=arguments.length;c<d;c++)for(var e in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,e)&&(a[e]=b[e]);return a},f.apply(this,arguments)};Object.defineProperty(c,"__esModule",{value:!0}),(0,e.define)(Date,{nowSeconds:function(){return a(Date.now()/1e3)}}),(0,e.define)(Date.prototype,{setTimezone:function(a){return this.setTime(new Date(this.toLocaleString("en-US",{timeZone:a})).getTime()),this},isInPast:function(){var a=new Date;return a.setHours(0,0,0,0),this<a},set:function(a){return a.timezone?this.setTimezone(a.timezone).set(f(f({},a),{timezone:void 0})):(null!=a.time&&this.setTime(a.time),null==a.utc?(null!=a.year&&this.setFullYear(a.year),null!=a.month&&this.setMonth(a.month),null!=a.date&&this.setDate(a.date),null!=a.hours&&this.setHours(a.hours),null!=a.minutes&&this.setMinutes(a.minutes),null!=a.seconds&&this.setSeconds(a.seconds),null!=a.milliseconds&&this.setMilliseconds(a.milliseconds)):(null!=a.year&&this.setUTCFullYear(a.year),null!=a.month&&this.setUTCMonth(a.month),null!=a.date&&this.setUTCDate(a.date),null!=a.hours&&this.setUTCHours(a.hours),null!=a.minutes&&this.setUTCMinutes(a.minutes),null!=a.seconds&&this.setUTCSeconds(a.seconds),null!=a.milliseconds&&this.setUTCMilliseconds(a.milliseconds)),this)},add:function(a){return a.timezone?this.setTimezone(a.timezone).set(f(f({},a),{timezone:void 0})):(a.utc&&delete a.utc,null!=a.time&&(a.time+=this.getTime()),null!=a.year&&(a.year+=this.getFullYear()),null!=a.month&&(a.month+=this.getMonth()),null!=a.date&&(a.date+=this.getDate()),null!=a.hours&&(a.hours+=this.getHours()),null!=a.minutes&&(a.minutes+=this.getMinutes()),null!=a.seconds&&(a.seconds+=this.getSeconds()),null!=a.milliseconds&&(a.milliseconds+=this.getMilliseconds()),this.set(a))},addYear:function(a,b,c){return void 0===b&&(b=0),void 0===c&&(c=0),this.setFullYear(this.getFullYear()+a,this.getMonth()+b,this.getDate()+c)},addMonth:function(a,b){return void 0===b&&(b=0),this.setMonth(this.getMonth()+a,this.getDate()+b)},addDate:function(a){return this.setDate(this.getDate()+a)},addHours:function(a,b,c,d){return void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=0),this.setHours(this.getHours()+a,this.getMinutes()+b,this.getSeconds()+c,this.getMilliseconds()+d)},addMinutes:function(a,b,c){return void 0===b&&(b=0),void 0===c&&(c=0),this.setMinutes(this.getMinutes()+a,this.getSeconds()+b,this.getMilliseconds()+c)},addSeconds:function(a,b){return void 0===b&&(b=0),this.setSeconds(this.getSeconds()+a,this.getMilliseconds()+b)},addMilliseconds:function(a){return this.setMilliseconds(this.getMilliseconds()+a)}})});b(l);var m=c(function(a,b){var c=d&&d.__createBinding||(Object.create?function(a,b,c,d){d===void 0&&(d=c);var e=Object.getOwnPropertyDescriptor(b,c);(!e||("get"in e?!b.__esModule:e.writable||e.configurable))&&(e={enumerable:!0,get:function(){return b[c]}}),Object.defineProperty(a,d,e)}:function(a,b,c,d){d===void 0&&(d=c),a[d]=b[c]}),e=d&&d.__exportStar||function(a,b){for(var d in a)"default"==d||Object.prototype.hasOwnProperty.call(b,d)||c(b,a,d)};Object.defineProperty(b,"__esModule",{value:!0}),e(f,b),e(g,b),e(h,b),e(i,b),e(j,b),e(k,b),e(l,b)}),n=b(m);return n}(); //# sourceMappingURL=mnjsf.min.js.map