UNPKG

@nikita-naredi/string-utility

Version:

This is a string utility package

1 lines 6.65 kB
var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{Go:()=>W,wZ:()=>U,yT:()=>j,aL:()=>z,rj:()=>y,y4:()=>x,WG:()=>R,Hz:()=>h,kX:()=>m,R5:()=>P,cK:()=>N,Iw:()=>k,fS:()=>K,tr:()=>f,R3:()=>O,a8:()=>b,SU:()=>v,u4:()=>S,cm:()=>A,MK:()=>w,CL:()=>L,Yv:()=>g,Nc:()=>X,Cb:()=>Z,in:()=>B,fX:()=>I,MX:()=>M,Wx:()=>T,zX:()=>D,uc:()=>G,Sn:()=>q,KC:()=>F,xv:()=>d});const n={toUpperSnakeCase:function(e){return e.toUpperCase().replace(/\s+/g,"_")},toReverseCase:function(e){return e.split("").map((e=>e===e.toUpperCase()?e.toLowerCase():e.toUpperCase())).join("")},toAlternatingCase:function(e){return e.split("").map(((e,t)=>t%2===0?e.toUpperCase():e.toLowerCase())).join("")},toCamelCase:function(e){const[t,...n]=e.split(" ");return[t.toLowerCase(),...n.map((e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()))].join("")},toPascalCase:function(e){return e.split(" ").map((e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase())).join("")},toKebabCase:function(e){return e.toLowerCase().replace(/\s+/g,"-")},toSnakeCase:function(e){return e.toLowerCase().replace(/\s+/g,"_")},toCapitalizedCase:function(e){return e.toLowerCase().split(" ").map((e=>e.length>0?e[0].toUpperCase()+e.slice(1):"")).join(" ")},toSentenceCase:function(e){return e?e.charAt(0).toUpperCase()+e.slice(1).toLowerCase():""},toTitleCase:function(e){return e.toLowerCase().split(" ").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join(" ")},caseString:function(e,t=null,n=null){let r=null;if(t&&(r={upper:()=>a.toUpperCase(),lower:()=>a.toLowerCase(),sentence:()=>a.toSentenceCase(),capitalized:()=>a.toCapitalizedCase(),reverse:()=>a.toReverseCase(),alternate:()=>a.toAlternatingCase(),camel:()=>{const[e,...t]=a;return[e.toLowerCase(),...t.map((e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()))]}}[t],!r))return e;const a=r();return n?a.join(n):a}};function r(e){return e.split("").filter((e=>"aeiouAEIOU".includes(e))).length}const a={countWords:function(e){return e.split(/\s+/).filter((e=>e.length>0)).length},countCharacters:function(e){return e.length},countVowels:r,countConsonants:function(e){return e.length-r(e)},countSentences:function(e){return e.split(/[.!?]+/).filter((e=>e.length>0)).length},countParagraphs:function(e){return e.split(/\n+/).filter((e=>e.length>0)).length},countLines:function(e){return e.split(/\r?\n/).length},countUniqueWords:function(e){const t=e.split(/\s+/);return new Set(t).size},countUniqueCharacters:function(e){const t=e.split("");return new Set(t).size},countDigits:function(e){return e.split("").filter((e=>!isNaN(parseInt(e)))).length},countOccurrences:function(e,t){return e.split(t).length-1},countSubstrings:function(e,t){return e.split(t).length-1}};const o={encodeBase64:function(e){if("function"===typeof btoa)return btoa(unescape(encodeURIComponent(e)));{let t="",n=0;for(;n<e.length;){e.charCodeAt(n++);const t=e.charCodeAt(n++),r=e.charCodeAt(n++);isNaN(t),isNaN(r)}return t}},decodeBase64:function(e){if("function"===typeof atob)return decodeURIComponent(escape(atob(e)));{const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";let n="",r=0;for(;r<e.length;){const a=t.indexOf(e.charAt(r++)),o=t.indexOf(e.charAt(r++)),s=t.indexOf(e.charAt(r++)),c=t.indexOf(e.charAt(r++)),i=a<<2|o>>4,u=(15&o)<<4|s>>2,l=(3&s)<<6|c;n+=String.fromCharCode(i),64!==s&&(n+=String.fromCharCode(u)),64!==c&&(n+=String.fromCharCode(l))}return n}}};const s={generateRandomString:function(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";for(let r=0;r<e;r++)t+=n.charAt(Math.floor(62*Math.random()));return t}};const c={removeNonAlpha:function(e){return e.replace(/[^a-zA-Z]/g,"")},removeSubstring:function(e,t){return e.split(t).join("")},removeDuplicates:function(e){return Array.from(new Set(e)).join("")}};function i(e,t,n,r){return e.split(t).reduce(((e,a,o,s)=>r===o?e+n+a:e+t+a))}const u={replaceAllOccurrences:function(e,t,n){return e.split(t).join(n)},replaceSpecificOccurence:i,replaceFirstOccurence:function(e,t,n){return i(e,t,n,0)},replaceLastOccurence:function(e,t,n){return i(e,t,n,-1)}};const l={findSubstringOccurrences:function(e,t){let n=0,r=e.indexOf(t);for(;-1!==r;)n++,r=e.indexOf(t,r+1);return n}};const p={slugify:function(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")},padString:function(e,t,n=" ",r="right"){return"left"===r?e.padStart(t,n):"right"===r?e.padEnd(t,n):void 0},truncate:function(e,t){return e.length>t?e.substring(0,t)+"...":e}};const C={isAlpha:function(e){return/^[a-zA-Z]+$/.test(e)},isPalindrome:function(e){const t=e.replace(/[^a-zA-Z0-9]/g,"").toLowerCase(),n=t.split("").reverse().join("");return t===n},isAnagram:function(e,t){const n=e.replace(/[^a-zA-Z]/g,"").toLowerCase(),r=t.replace(/[^a-zA-Z]/g,"").toLowerCase();return n.split("").sort().join("")===r.split("").sort().join("")},isPangram:function(e){const t=e.replace(/[^a-zA-Z]/g,"").toLowerCase();for(let n of"abcdefghijklmnopqrstuvwxyz")if(!t.includes(n))return!1;return!0}},{padString:f,slugify:g,truncate:d}=p,{findSubstringOccurrences:h}=l,{generateRandomString:m}=s,{replaceAllOccurrences:S,replaceFirstOccurence:A,replaceLastOccurence:w,replaceSpecificOccurence:L}=u,{removeDuplicates:O,removeNonAlpha:b,removeSubstring:v}=c,{countCharacters:U,countConsonants:j,countVowels:z,countWords:y}=a,{encodeBase64:R,decodeBase64:x}=o,{isAlpha:P,isAnagram:N,isPalindrome:k,isPangram:K}=C,{caseString:W,toAlternatingCase:X,toCamelCase:Z,toCapitalizedCase:B,toKebabCase:I,toPascalCase:M,toReverseCase:T,toSentenceCase:D,toSnakeCase:G,toTitleCase:q,toUpperSnakeCase:F}=n;var V=t.Go,E=t.wZ,H=t.yT,Y=t.aL,_=t.rj,J=t.y4,Q=t.WG,$=t.Hz,ee=t.kX,te=t.R5,ne=t.cK,re=t.Iw,ae=t.fS,oe=t.tr,se=t.R3,ce=t.a8,ie=t.SU,ue=t.u4,le=t.cm,pe=t.MK,Ce=t.CL,fe=t.Yv,ge=t.Nc,de=t.Cb,he=t.in,me=t.fX,Se=t.MX,Ae=t.Wx,we=t.zX,Le=t.uc,Oe=t.Sn,be=t.KC,ve=t.xv;export{V as caseString,E as countCharacters,H as countConsonants,Y as countVowels,_ as countWords,J as decodeBase64,Q as encodeBase64,$ as findSubstringOccurrences,ee as generateRandomString,te as isAlpha,ne as isAnagram,re as isPalindrome,ae as isPangram,oe as padString,se as removeDuplicates,ce as removeNonAlpha,ie as removeSubstring,ue as replaceAllOccurrences,le as replaceFirstOccurence,pe as replaceLastOccurence,Ce as replaceSpecificOccurence,fe as slugify,ge as toAlternatingCase,de as toCamelCase,he as toCapitalizedCase,me as toKebabCase,Se as toPascalCase,Ae as toReverseCase,we as toSentenceCase,Le as toSnakeCase,Oe as toTitleCase,be as toUpperSnakeCase,ve as truncate};