UNPKG

2.59 kBJavaScriptView Raw
1"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=["string","bigint","number","boolean"];function e(t){return!("object"!=typeof t||!t)&&t.constructor===Object}function r(e){return t.includes(typeof e)}function n(t,e){return Math.floor(Math.random()*(e-t+1)+t)}function o(t,e){return Math.random()*(e-t)+t}exports.calcPercentOfNum=function(t,e){return t*e/100},exports.calcWhatPercent=function(t,e){return 100*t/e},exports.chunk=function(t,e){if(e<1)throw new RangeError("chunkSize must be 1 or greater.");if(!Number.isInteger(e))throw new TypeError("chunkSize must be an integer.");const r=t.slice(),n=[];for(;r.length;)n.push(r.splice(0,e));return n},exports.clamp=function(t,e,r){return Math.min(r,Math.max(e,t))},exports.debounce=(t,e)=>{let r=null;return(...n)=>{null!==r&&(clearTimeout(r),r=null),r=setTimeout(()=>t(...n),e)}},exports.deepClone=function t(n){if(null===n||r(n))return n;if(Array.isArray(n)){const e=[];for(const r of n)e.push(t(r));return e}if(e(n)){const e={};for(const[r,o]of Object.entries(n))e[r]=t(o);return e}if(n instanceof Map){const e=new n.constructor;for(const[r,o]of n.entries())e.set(r,t(o));return e}if(n instanceof Set){const e=new n.constructor;for(const r of n.values())e.add(t(r));return e}return n},exports.increaseNumByPercent=function(t,e){return e<=0?t:t+t*(e/100)},exports.isFunction=function(t){return"function"==typeof t},exports.isObject=e,exports.isPrimitive=r,exports.noOp=function(){},exports.notEmpty=function(t){return null!=t},exports.objectEntries=function(t){return Object.entries(t)},exports.objectKeys=function(t){return Object.keys(t)},exports.objectValues=function(t){return Object.values(t)},exports.partition=function(t,e){const r=[],n=[];for(const o of t)(e(o)?r:n).push(o);return[r,n]},exports.percentChance=function(t){return o(0,100)<t},exports.primitiveTypes=t,exports.randArrItem=function(t){return t[Math.floor(Math.random()*t.length)]},exports.randFloat=o,exports.randInt=n,exports.reduceNumByPercent=function(t,e){return e<=0?t:t-t*(e/100)},exports.roll=function(t){return 1===n(1,t)},exports.round=function(t,e=1){const r=Math.pow(10,e||0);return Math.round(t*r)/r},exports.scaleNumber=function(t,e,r,n,o){return(t-e)*(o-n)/(r-e)+n},exports.shuffleArr=function(t){let e=[...t];for(let t=e.length-1;t>0;t--){const r=Math.floor(Math.random()*(t+1));[e[t],e[r]]=[e[r],e[t]]}return e},exports.sleep=function(t){return new Promise(e=>setTimeout(e,t))},exports.sumArr=function(t){return t.reduce((t,e)=>t+e,0)},exports.uniqueArr=function(t){return[...new Set(t)]};
2//# sourceMappingURL=index.js.map