UNPKG

@utilify/string

Version:

The string utility functions provide a variety of methods for text manipulation, such as transforming, counting words, sanitizing, and formatting strings.

2 lines (1 loc) 1.37 kB
function e(e){return/^(?!.*[A-Z]).*[a-z].*$/.test(e.replace(/\s+/g,""))}function t(e){return/^(?!.*[a-z]).*[A-Z].*$/.test(e.replace(/\s+/g,""))}function r(r){return r.split("").map((r=>e(r)?r.toUpperCase():t(r)?r.toLowerCase():r)).join("")}function n(e,t,r,n){n=Math.min(n,e.length-r);const c=e.slice(0,r),o=e.slice(r+n);return c+t.repeat(n)+o}function c(e){return e.trim().replace(/[!@#$%^&*()\-=+[\]{}|\\~;:'",.<>?\/]/g,"").toLowerCase().replace(/\s+/g,"-").normalize("NFD").replace(/[\u0300-\u036f]/g,"")}function o(e){return e.trim().toLowerCase().split(" ").map(((e,t)=>0===t?e:e[0].toUpperCase().concat(e.slice(1)))).join(" ").replace(/\s+/g,"")}function i(e){return e.trim().toLowerCase().replace(/\s+/g,"-")}function a(e){return e.trim().split(" ").map((e=>e[0].toUpperCase().concat(e.slice(1)))).join(" ").replace(/\s+/g,"")}function s(e){return e.trim().toLowerCase().replace(/\s+/g,"_")}function u(e,t){return e.slice(0,t).concat("...")}function p(e){return e.trim().replace(/\s+/g," ").split(" ").length}function l(e){return e.charAt(0).toUpperCase().concat(e.slice(1))}function f(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")}export{l as capitalize,r as invertCase,e as isLowerCase,t as isUpperCase,n as maskString,f as removeAccents,c as slugify,o as toCamelCase,i as toKebabCase,a as toPascalCase,s as toSnakeCase,u as truncate,p as wordCount};