@backs/utils
Version:
A set of utils to help you with random tasks
11 lines (10 loc) • 3.7 kB
JavaScript
import{v4 as u}from"uuid";import f from"pluralize";import c from"crypto";import H from"bytes";import q from"moment";import J from"is-even";import W from"is-odd";import D from"is-number";var p=Symbol.for("ts-node.register.instance")in process,x=e=>c.createHash("sha256").update(s(e)).digest().toString("hex"),l=e=>c.createHash("md5").update(s(e)).digest().toString("hex"),d=e=>Buffer.from(s(e)).toString("hex"),m=e=>Buffer.from(s(e)).toString("base64"),b=e=>Buffer.from(s(e)).toString("binary"),g=e=>Buffer.from(s(e)).toString("ascii"),h=e=>Buffer.from(s(e)).toString("latin1"),y=(e,t)=>Buffer.from(e.toString(),t).toString("utf-8"),k=f,w=(e,t=!1)=>{if(t){let r=e.split(/ +/g),n=[];for(let o of r){let a=o.charAt(0).toUpperCase();n.push(a+o.slice(1))}return n.join(" ")}else return e.charAt(0).toUpperCase()+e.slice(1)},T=(e,t)=>`${e.substring(0,t-3)}${e.length>t?"...":""}`,C=(e,...t)=>{let r=e;for(let n of t)r=e.replace(n,"");return r},B=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),S=(e,t=1)=>t===1?[e[0]]:e.filter((r,n)=>n<t),L=(e,t=1)=>t===1?[e.at(-1)]:e.filter((r,n)=>e.length-n<=t),$=e=>e[Math.floor(Math.random()*e.length)],A=(e,t)=>e.map(r=>r[t]),v=(e,t)=>e.reduce((r,n)=>{let o=n[t];return{...r,[o]:[...r[o]??[],n]}},{}),z=(e,t)=>{let r=[];for(let n=0,o=0;n<e.length;n++)n>=t&&n%t===0&&o++,r[o]=r[o]||[],r[o].push(e[n]);return r},s=e=>{if(e instanceof Error){let t=`${e.name}: ${e.message}`;return e.stack&&(t+=`
${e.stack.replace(`${e.toString()}
`,"")}`),e.cause&&(t+=`
Caused by: ${s(e.cause)}`),t}return typeof e=="object"?JSON.stringify(e,null,4):Array.isArray(e)?e.map(t=>s(t)).join(", "):e.toString()},U={amethyst:10053324,aqua:1752220,blue:3447003,blurple:5793266,darkAqua:1146986,darkBlue:2123412,darkButNotBlack:2895667,darkGold:12745742,darkGreen:2067276,darkGrey:9936031,darkNavy:2899536,darkOrange:11027200,darkPurple:7419530,darkRed:10038562,darkVividPink:11342935,darkerGrey:8359053,default:0,fuchsia:15418782,gold:15844367,green:5763719,grey:9807270,greyple:10070709,lightGrey:12370112,luminousVividPink:15277667,navy:3426654,notQuiteBlack:2303786,orange:15105570,purple:10181046,red:15548997,white:16777215,yellow:16705372},G=u,M=(e,t="both")=>{let r="ABCDEFGHIJKLMNOPQRSTUVWXYZ",n="0123456789",o="",a="";switch(t){case"letters":o=r+r.toLowerCase();break;case"lettersLowerCase":o=r.toLowerCase();break;case"lettersUppercase":o=r;break;case"numbers":o=n;break;case"both":o=r+r.toLowerCase()+n;break;case"bothUpperCase":o=r+n;break;case"bothLowerCase":o=r.toLowerCase()+n;break;default:o=t;break}for(let i=0;i<e;i++)a+=o.charAt(Math.floor(Math.random()*o.length));return a},j=(e,t)=>{for(let r of e.match(/(\[[^[{}\]]*\]|\([^()]*\)|^[A-Z\d\s]+:|(?:https?:\/\/)[a-z0-9_\-\.]*[a-z0-9_\-]{1,}\.[a-z]{2,}(?:\?(?:\w+=\w+&?)*)?|(?:[a-z-.+]+?:\/\/)(?:[^/:@?&\\](?::[^\/:@?&\\])?@)?[^/:@?&\\]+\.[a-z]{2,})(?:\?(?:\w+=\w+&?)*)?/img)??[])e=e.replace(r,t(r));return e};var F={isTypescript:p,sha256:x,md5:l,hex:d,base64:m,binary:b,ascii:g,latin1:h,decode:y,plural:k,capitalize:w,crop:T,remove:C,escape:B,first:S,last:L,random:$,get:A,groupBy:v,group:z,stringify:s,colors:U,uuid:G,randomId:M,highlight:j};export{g as ascii,m as base64,b as binary,H as bytes,w as capitalize,U as colors,T as crop,y as decode,F as default,B as escape,S as first,A as get,z as group,v as groupBy,d as hex,j as highlight,J as isEven,D as isNumber,W as isOdd,p as isTypescript,L as last,h as latin1,l as md5,q as moment,k as plural,$ as random,M as randomId,C as remove,x as sha256,s as stringify,G as uuid};
if (module.exports.default) {
Object.assign(module.exports.default, module.exports);
module.exports = module.exports.default;
delete module.exports.default;
}
//# sourceMappingURL=index.mjs.map