UNPKG

@rr0/data

Version:
29 lines (28 loc) 1.05 kB
export class StringUtil { static capitalizeFirstLetter(s) { return s.charAt(0).toUpperCase() + s.slice(1); } static withoutDots(str) { return str.replace(".", ""); } static withoutPunctuation(str) { return str.replace(/[ .:;,()\-+=*/#°@$€£%!&?"'’]/g, ""); } static withoutAccents(str) { return str.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); } static textToCamel(text) { return StringUtil.withoutAccents(StringUtil.withoutPunctuation(text.trim() .replace(/ [^ ]+/g, (substring, args) => substring.charAt(1).toUpperCase() + substring.substring(2)))); } static camelToText(camel) { const text = camel.trim() .replace(/([A-Z]+)/g, " $1") .replace(/([0-9]+)/g, " $1") .replace(/( [A-Z] )/g, " $1. ") .replace(/( [A-Z]$)/g, " $1.") // .replace(/([A-Z])([A-Z])/g, " $1. $2.") .replace(/ {2}/g, " "); return StringUtil.capitalizeFirstLetter(text).trim(); } }