UNPKG

@fto-consult/common

Version:

Un ensemble de bibliothèques et d'utilistaires communs pour le développement d'applications javascript

304 lines (270 loc) 18.3 kB
// Copyright 2022 @fto-consult/Boris Fouomene. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. import isDateObj from "./isDateObj"; export const ltrim = function(current,str) { if(typeof current !=="string") return ""; if (!(str) || typeof str !=="string") { return current.trim(); } var index = current.length; while(current.startsWith(str) && index >= 0) { current = current.slice(str.length); --index; } return current.toString(); }; if(typeof String.prototype.ltrim != 'function'){ String.prototype.ltrim = function(str) { return ltrim(this.toString(),str); } } export const rtrim = function(current,str) { if(typeof current !=="string") return ""; if (!(str) || typeof str !=="string") { return current.trim(); } var index = current.length; while(current.endsWith(str) && index >= 0) { current = current.slice(0,- str.length); --index; } return current.toString(); } if(typeof String.prototype.rtrim != 'function'){ String.prototype.rtrim = function(str) { return rtrim(this.toString(),str); }; } function identity(str) { return str; } /*** WRAP SPECIFIC WORD * wrap('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'); * @parm str {string} string to wrap * @param options {object|number} : { * width {number} : Default: 50, The width of the text before wrapping to a new line. * indent {string} : Default: `` (none), The string to use at the beginning of each line, example : wrap(str, {indent: ' '});* * newline {string} : Default: \n, The string to use at the end of each line. example : wrap(str, {newline: '\n\n'});* * escape {function} : Default: function(str){return str;}, An escape function to run on each line after splitting them, example : wrap(str, { escape: function(string){ return xmlescape(string); } }) trim : {boolean} : Default: false, Trim trailing whitespace from the returned string. This option is included since .trim() would also strip the leading indentation from the first line. * } * wrapWord(str,10) * wrapWord(str,{width:10}) * */ export const wrapWord = function(str, options) { if(typeof (options) === "number"){ options = {width:options} } options = options && typeof options =='object' ? options : {}; if(!str || typeof str !=='string'){ return str; } var width = typeof options.width === 'number' && options.width > 0 ? options.width : typeof options.length == 'number' && options.length > 0 ? options.length : 30; if(str.length <= width) return str; var indent = (typeof options.indent === 'string') ? options.indent : ''; var newline = options.newline || '\n' + indent; var escape = typeof options.escape === 'function' ? options.escape : identity; var regexString = '.{1,' + width + '}'; if (options.cut !== true) { regexString += '([\\s\u200B]+|$)|[^\\s\u200B]+?([\\s\u200B]+|$)'; } var re = new RegExp(regexString, 'g'); var lines = str.match(re) || []; var result = indent + lines.map(function(line) { if (line.slice(-1) === '\n') { line = line.slice(0, line.length - 1); } return escape(line); }).join(newline); if (options.trim === true) { result = result.replace(/[ \t]*$/gm, ''); } return result; }; String.prototype.wrapWord = function(opts){ return wrapWord(this.toString(),opts) } if(typeof window !=='undefined' && window){ window.wrapWord = wrapWord; } /**** substring pollyfill */ if('ab'.substr(-1) != 'b'){ /** * Get the substring of a string * @param {integer} start where to start the substring * @param {integer} length how many characters to return * @return {string} */ String.prototype.substr = function(substr) { return function(start, length) { // did we get a negative start? let str = this.toString(); if (start < 0) { // calculate how much it is from the beginning of the string start = str.length + start; // if start is still negative then set it to the beginning of // the string if (start < 0) start = 0; } // call the original function return substr.call(this, start, length); } }(String.prototype.substr); } if(typeof(String.prototype.substring) !== 'function'){ String.prototype.substring = String.prototype.substr; } if(typeof String.prototype.contains != 'function'){ String.prototype.contains = function(str){ return (this.toString().indexOf(str) !== -1); } } if (!String.prototype.includes) { String.prototype.includes = function(search, start) { if (typeof start !== 'number') { start = 0; } if (start + search.length > this.toString().length) { return false; } else { return this.toString().indexOf(search, start) !== -1; } }; } if(typeof String.prototype.startsWith != 'function') { String.prototype.startsWith = function(needle,startPositionIndex){ if(typeof startPositionIndex != 'number') startPosition = 0 return (this.toString().indexOf(needle) == startPositionIndex) } } if(typeof String.prototype.endsWith != 'function') { String.prototype.endsWith = function(suffix,endPositionIndex) { if(typeof endPositionIndex != 'number') endPosition = 0 return this.toString().indexOf(suffix, this.toString().length - suffix.length) !== -1; }; } if(typeof String.prototype.replaceAll != 'function'){ /*** replace all occurance in string * * * */ String.prototype.replaceAll = function(find, replace) { return this.toString().split(find).join(replace) } } String.prototype.trimSlashes = function (value) { if(!value) value = this.toString(); return value.replace(/[\\/]+$/, '').toString(); }; String.prototype.isNumber = function(withDecimal){ return isStringNumber(this.toString(),withDecimal); } /**** vérifie si la chaine de caractère passée en paramètre est constitué uniquement des nombres */ export const isStringNumber = (str,withDecimal)=>{ if(typeof str !=='string') return false; if(withDecimal !== false){ return /^\d*\.?\d+$/.test(str); } return /^\d+$/.test(str); } export const isNumberString = isStringNumber; export const sprintf = function(args){ args = typeof args =='object' && args ? args : Array.prototype.slice.call(arguments); let str = typeof args[0] == "string"? args[0] : ""; if(!str) return str; for(let i = 1;i<args.length;i++){ const t = typeof args[i] == "boolean" || typeof args[i] =="number" || typeof args[i] == "string"? (args[i]+"") : ""; str = str.replaceAll("{"+(i-1)+"}",t); } return str; } String.prototype.sprintf = function(){ const arg = Array.prototype.slice.call(arguments); arg.unshift(this.toString()); return sprintf(arg); } String.sprintf = sprintf; const isNonNullString = x=>x && typeof x=='string'; /*** escape les quôtes sur la chaine de caractère string * @param {string} la chaine de caractère à ecaper * @param {string} toEscape la chaine à eschaper * @param {string} replacement la chaine de remplacement */ export const escapeQuote = (string,toEscape,replacement)=>{ if(!isNonNullString(string)) return ""; if(!isNonNullString(toEscape) || !isNonNullString(replacement)){ return string; } return string.replaceAll(toEscape,replacement) } /*** escape les signle quotes sur une chaine de caractère */ export const escapeSingleQuotes = (string,withSingleQuotesClaues = true)=>{ if(!isNonNullString(string)) return ""; string = string.trim().ltrim("'").rtrim("'").trim(); const str = string.replace(/'/g, "\\'"); return withSingleQuotesClaues ? ("'"+str+"'") : str; } if(!String.prototype.escapeSingleQuotes){ String.prototype.escapeSingleQuotes = function(withSingleQuotesClaues = true){ return escapeSingleQuotes(this.toString(),withSingleQuotesClaues); } } export const escapeDoubleQuotes = (string,withDoubleQuotesClaues = true)=>{ if(!isNonNullString(string)) return ""; string = string.ltrim('"').rtrim('"').trim(); const str = string.replace(/"/g, '\\"'); return withDoubleQuotesClaues ? ('"'+str+'"') : str; } if(!String.prototype.escapeDoubleQuotes){ String.prototype.escapeDoubleQuotes = function(withDoubleQuotesClaues = true){ return escapeDoubleQuotes(this.toString(),withDoubleQuotesClaues); } } /*** escape les quôtes SQL */ export const escapeSQLQuotes = (object)=>{ if(typeof object =='string'){ object = object.trim().ltrim("'").rtrim("'"); return "'"+object.replace(/'/g, "''")+"'"; } if(typeof object =='boolean'){ return object ? 1 : 0; } if(typeof object =='number') return object; if(isDateObj(object)){ return "'"+new Date(object).toISOString().split('T').join(' ').split('Z').join('')+"'"; } return "'"+object.toString()+"'"; } export const toSQLString = escapeSQLQuotes; if(!String.prototype.escapeSingleQuotes){ String.prototype.escapeSingleQuotes = function(){ return escapeSingleQuotes(this.toString()); } } export const removeSpecialChars = function(s){ if(!isNonNullString(s)) return ""; const accentsMap ={"Á":"A","Ă":"A","Ắ":"A","Ặ":"A","Ằ":"A","Ẳ":"A","Ẵ":"A","Ǎ":"A","Â":"A","Ấ":"A","Ậ":"A","Ầ":"A","Ẩ":"A","Ẫ":"A","Ä":"A","Ǟ":"A","Ȧ":"A","Ǡ":"A","Ạ":"A","Ȁ":"A","À":"A","Ả":"A","Ȃ":"A","Ā":"A","Ą":"A","Å":"A","Ǻ":"A","Ḁ":"A","Ⱥ":"A","Ã":"A","Ꜳ":"AA","Æ":"AE","Ǽ":"AE","Ǣ":"AE","Ꜵ":"AO","Ꜷ":"AU","Ꜹ":"AV","Ꜻ":"AV","Ꜽ":"AY","Ḃ":"B","Ḅ":"B","Ɓ":"B","Ḇ":"B","Ƀ":"B","Ƃ":"B","Ć":"C","Č":"C","Ç":"C","Ḉ":"C","Ĉ":"C","Ċ":"C","Ƈ":"C","Ȼ":"C","Ď":"D","Ḑ":"D","Ḓ":"D","Ḋ":"D","Ḍ":"D","Ɗ":"D","Ḏ":"D","Dz":"D","Dž":"D","Đ":"D","Ƌ":"D","DZ":"DZ","DŽ":"DZ","É":"E","Ĕ":"E","Ě":"E","Ȩ":"E","Ḝ":"E","Ê":"E","Ế":"E","Ệ":"E","Ề":"E","Ể":"E","Ễ":"E","Ḙ":"E","Ë":"E","Ė":"E","Ẹ":"E","Ȅ":"E","È":"E","Ẻ":"E","Ȇ":"E","Ē":"E","Ḗ":"E","Ḕ":"E","Ę":"E","Ɇ":"E","Ẽ":"E","Ḛ":"E","Ꝫ":"ET","Ḟ":"F","Ƒ":"F","Ǵ":"G","Ğ":"G","Ǧ":"G","Ģ":"G","Ĝ":"G","Ġ":"G","Ɠ":"G","Ḡ":"G","Ǥ":"G","Ḫ":"H","Ȟ":"H","Ḩ":"H","Ĥ":"H","Ⱨ":"H","Ḧ":"H","Ḣ":"H","Ḥ":"H","Ħ":"H","Í":"I","Ĭ":"I","Ǐ":"I","Î":"I","Ï":"I","Ḯ":"I","İ":"I","Ị":"I","Ȉ":"I","Ì":"I","Ỉ":"I","Ȋ":"I","Ī":"I","Į":"I","Ɨ":"I","Ĩ":"I","Ḭ":"I","Ꝺ":"D","Ꝼ":"F","Ᵹ":"G","Ꞃ":"R","Ꞅ":"S","Ꞇ":"T","Ꝭ":"IS","Ĵ":"J","Ɉ":"J","Ḱ":"K","Ǩ":"K","Ķ":"K","Ⱪ":"K","Ꝃ":"K","Ḳ":"K","Ƙ":"K","Ḵ":"K","Ꝁ":"K","Ꝅ":"K","Ĺ":"L","Ƚ":"L","Ľ":"L","Ļ":"L","Ḽ":"L","Ḷ":"L","Ḹ":"L","Ⱡ":"L","Ꝉ":"L","Ḻ":"L","Ŀ":"L","Ɫ":"L","Lj":"L","Ł":"L","LJ":"LJ","Ḿ":"M","Ṁ":"M","Ṃ":"M","Ɱ":"M","Ń":"N","Ň":"N","Ņ":"N","Ṋ":"N","Ṅ":"N","Ṇ":"N","Ǹ":"N","Ɲ":"N","Ṉ":"N","Ƞ":"N","Nj":"N","Ñ":"N","NJ":"NJ","Ó":"O","Ŏ":"O","Ǒ":"O","Ô":"O","Ố":"O","Ộ":"O","Ồ":"O","Ổ":"O","Ỗ":"O","Ö":"O","Ȫ":"O","Ȯ":"O","Ȱ":"O","Ọ":"O","Ő":"O","Ȍ":"O","Ò":"O","Ỏ":"O","Ơ":"O","Ớ":"O","Ợ":"O","Ờ":"O","Ở":"O","Ỡ":"O","Ȏ":"O","Ꝋ":"O","Ꝍ":"O","Ō":"O","Ṓ":"O","Ṑ":"O","Ɵ":"O","Ǫ":"O","Ǭ":"O","Ø":"O","Ǿ":"O","Õ":"O","Ṍ":"O","Ṏ":"O","Ȭ":"O","Ƣ":"OI","Ꝏ":"OO","Ɛ":"E","Ɔ":"O","Ȣ":"OU","Ṕ":"P","Ṗ":"P","Ꝓ":"P","Ƥ":"P","Ꝕ":"P","Ᵽ":"P","Ꝑ":"P","Ꝙ":"Q","Ꝗ":"Q","Ŕ":"R","Ř":"R","Ŗ":"R","Ṙ":"R","Ṛ":"R","Ṝ":"R","Ȑ":"R","Ȓ":"R","Ṟ":"R","Ɍ":"R","Ɽ":"R","Ꜿ":"C","Ǝ":"E","Ś":"S","Ṥ":"S","Š":"S","Ṧ":"S","Ş":"S","Ŝ":"S","Ș":"S","Ṡ":"S","Ṣ":"S","Ṩ":"S","Ť":"T","Ţ":"T","Ṱ":"T","Ț":"T","Ⱦ":"T","Ṫ":"T","Ṭ":"T","Ƭ":"T","Ṯ":"T","Ʈ":"T","Ŧ":"T","Ɐ":"A","Ꞁ":"L","Ɯ":"M","Ʌ":"V","Ꜩ":"TZ","Ú":"U","Ŭ":"U","Ǔ":"U","Û":"U","Ṷ":"U","Ü":"U","Ǘ":"U","Ǚ":"U","Ǜ":"U","Ǖ":"U","Ṳ":"U","Ụ":"U","Ű":"U","Ȕ":"U","Ù":"U","Ủ":"U","Ư":"U","Ứ":"U","Ự":"U","Ừ":"U","Ử":"U","Ữ":"U","Ȗ":"U","Ū":"U","Ṻ":"U","Ų":"U","Ů":"U","Ũ":"U","Ṹ":"U","Ṵ":"U","Ꝟ":"V","Ṿ":"V","Ʋ":"V","Ṽ":"V","Ꝡ":"VY","Ẃ":"W","Ŵ":"W","Ẅ":"W","Ẇ":"W","Ẉ":"W","Ẁ":"W","Ⱳ":"W","Ẍ":"X","Ẋ":"X","Ý":"Y","Ŷ":"Y","Ÿ":"Y","Ẏ":"Y","Ỵ":"Y","Ỳ":"Y","Ƴ":"Y","Ỷ":"Y","Ỿ":"Y","Ȳ":"Y","Ɏ":"Y","Ỹ":"Y","Ź":"Z","Ž":"Z","Ẑ":"Z","Ⱬ":"Z","Ż":"Z","Ẓ":"Z","Ȥ":"Z","Ẕ":"Z","Ƶ":"Z","IJ":"IJ","Œ":"OE","ᴀ":"A","ᴁ":"AE","ʙ":"B","ᴃ":"B","ᴄ":"C","ᴅ":"D","ᴇ":"E","ꜰ":"F","ɢ":"G","ʛ":"G","ʜ":"H","ɪ":"I","ʁ":"R","ᴊ":"J","ᴋ":"K","ʟ":"L","ᴌ":"L","ᴍ":"M","ɴ":"N","ᴏ":"O","ɶ":"OE","ᴐ":"O","ᴕ":"OU","ᴘ":"P","ʀ":"R","ᴎ":"N","ᴙ":"R","ꜱ":"S","ᴛ":"T","ⱻ":"E","ᴚ":"R","ᴜ":"U","ᴠ":"V","ᴡ":"W","ʏ":"Y","ᴢ":"Z","á":"a","ă":"a","ắ":"a","ặ":"a","ằ":"a","ẳ":"a","ẵ":"a","ǎ":"a","â":"a","ấ":"a","ậ":"a","ầ":"a","ẩ":"a","ẫ":"a","ä":"a","ǟ":"a","ȧ":"a","ǡ":"a","ạ":"a","ȁ":"a","à":"a","ả":"a","ȃ":"a","ā":"a","ą":"a","ᶏ":"a","ẚ":"a","å":"a","ǻ":"a","ḁ":"a","ⱥ":"a","ã":"a","ꜳ":"aa","æ":"ae","ǽ":"ae","ǣ":"ae","ꜵ":"ao","ꜷ":"au","ꜹ":"av","ꜻ":"av","ꜽ":"ay","ḃ":"b","ḅ":"b","ɓ":"b","ḇ":"b","ᵬ":"b","ᶀ":"b","ƀ":"b","ƃ":"b","ɵ":"o","ć":"c","č":"c","ç":"c","ḉ":"c","ĉ":"c","ɕ":"c","ċ":"c","ƈ":"c","ȼ":"c","ď":"d","ḑ":"d","ḓ":"d","ȡ":"d","ḋ":"d","ḍ":"d","ɗ":"d","ᶑ":"d","ḏ":"d","ᵭ":"d","ᶁ":"d","đ":"d","ɖ":"d","ƌ":"d","ı":"i","ȷ":"j","ɟ":"j","ʄ":"j","dz":"dz","dž":"dz","é":"e","ĕ":"e","ě":"e","ȩ":"e","ḝ":"e","ê":"e","ế":"e","ệ":"e","ề":"e","ể":"e","ễ":"e","ḙ":"e","ë":"e","ė":"e","ẹ":"e","ȅ":"e","è":"e","ẻ":"e","ȇ":"e","ē":"e","ḗ":"e","ḕ":"e","ⱸ":"e","ę":"e","ᶒ":"e","ɇ":"e","ẽ":"e","ḛ":"e","ꝫ":"et","ḟ":"f","ƒ":"f","ᵮ":"f","ᶂ":"f","ǵ":"g","ğ":"g","ǧ":"g","ģ":"g","ĝ":"g","ġ":"g","ɠ":"g","ḡ":"g","ᶃ":"g","ǥ":"g","ḫ":"h","ȟ":"h","ḩ":"h","ĥ":"h","ⱨ":"h","ḧ":"h","ḣ":"h","ḥ":"h","ɦ":"h","ẖ":"h","ħ":"h","ƕ":"hv","í":"i","ĭ":"i","ǐ":"i","î":"i","ï":"i","ḯ":"i","ị":"i","ȉ":"i","ì":"i","ỉ":"i","ȋ":"i","ī":"i","į":"i","ᶖ":"i","ɨ":"i","ĩ":"i","ḭ":"i","ꝺ":"d","ꝼ":"f","ᵹ":"g","ꞃ":"r","ꞅ":"s","ꞇ":"t","ꝭ":"is","ǰ":"j","ĵ":"j","ʝ":"j","ɉ":"j","ḱ":"k","ǩ":"k","ķ":"k","ⱪ":"k","ꝃ":"k","ḳ":"k","ƙ":"k","ḵ":"k","ᶄ":"k","ꝁ":"k","ꝅ":"k","ĺ":"l","ƚ":"l","ɬ":"l","ľ":"l","ļ":"l","ḽ":"l","ȴ":"l","ḷ":"l","ḹ":"l","ⱡ":"l","ꝉ":"l","ḻ":"l","ŀ":"l","ɫ":"l","ᶅ":"l","ɭ":"l","ł":"l","lj":"lj","ſ":"s","ẜ":"s","ẛ":"s","ẝ":"s","ḿ":"m","ṁ":"m","ṃ":"m","ɱ":"m","ᵯ":"m","ᶆ":"m","ń":"n","ň":"n","ņ":"n","ṋ":"n","ȵ":"n","ṅ":"n","ṇ":"n","ǹ":"n","ɲ":"n","ṉ":"n","ƞ":"n","ᵰ":"n","ᶇ":"n","ɳ":"n","ñ":"n","nj":"nj","ó":"o","ŏ":"o","ǒ":"o","ô":"o","ố":"o","ộ":"o","ồ":"o","ổ":"o","ỗ":"o","ö":"o","ȫ":"o","ȯ":"o","ȱ":"o","ọ":"o","ő":"o","ȍ":"o","ò":"o","ỏ":"o","ơ":"o","ớ":"o","ợ":"o","ờ":"o","ở":"o","ỡ":"o","ȏ":"o","ꝋ":"o","ꝍ":"o","ⱺ":"o","ō":"o","ṓ":"o","ṑ":"o","ǫ":"o","ǭ":"o","ø":"o","ǿ":"o","õ":"o","ṍ":"o","ṏ":"o","ȭ":"o","ƣ":"oi","ꝏ":"oo","ɛ":"e","ᶓ":"e","ɔ":"o","ᶗ":"o","ȣ":"ou","ṕ":"p","ṗ":"p","ꝓ":"p","ƥ":"p","ᵱ":"p","ᶈ":"p","ꝕ":"p","ᵽ":"p","ꝑ":"p","ꝙ":"q","ʠ":"q","ɋ":"q","ꝗ":"q","ŕ":"r","ř":"r","ŗ":"r","ṙ":"r","ṛ":"r","ṝ":"r","ȑ":"r","ɾ":"r","ᵳ":"r","ȓ":"r","ṟ":"r","ɼ":"r","ᵲ":"r","ᶉ":"r","ɍ":"r","ɽ":"r","ↄ":"c","ꜿ":"c","ɘ":"e","ɿ":"r","ś":"s","ṥ":"s","š":"s","ṧ":"s","ş":"s","ŝ":"s","ș":"s","ṡ":"s","ṣ":"s","ṩ":"s","ʂ":"s","ᵴ":"s","ᶊ":"s","ȿ":"s","ɡ":"g","ᴑ":"o","ᴓ":"o","ᴝ":"u","ť":"t","ţ":"t","ṱ":"t","ț":"t","ȶ":"t","ẗ":"t","ⱦ":"t","ṫ":"t","ṭ":"t","ƭ":"t","ṯ":"t","ᵵ":"t","ƫ":"t","ʈ":"t","ŧ":"t","ᵺ":"th","ɐ":"a","ᴂ":"ae","ǝ":"e","ᵷ":"g","ɥ":"h","ʮ":"h","ʯ":"h","ᴉ":"i","ʞ":"k","ꞁ":"l","ɯ":"m","ɰ":"m","ᴔ":"oe","ɹ":"r","ɻ":"r","ɺ":"r","ⱹ":"r","ʇ":"t","ʌ":"v","ʍ":"w","ʎ":"y","ꜩ":"tz","ú":"u","ŭ":"u","ǔ":"u","û":"u","ṷ":"u","ü":"u","ǘ":"u","ǚ":"u","ǜ":"u","ǖ":"u","ṳ":"u","ụ":"u","ű":"u","ȕ":"u","ù":"u","ủ":"u","ư":"u","ứ":"u","ự":"u","ừ":"u","ử":"u","ữ":"u","ȗ":"u","ū":"u","ṻ":"u","ų":"u","ᶙ":"u","ů":"u","ũ":"u","ṹ":"u","ṵ":"u","ᵫ":"ue","ꝸ":"um","ⱴ":"v","ꝟ":"v","ṿ":"v","ʋ":"v","ᶌ":"v","ⱱ":"v","ṽ":"v","ꝡ":"vy","ẃ":"w","ŵ":"w","ẅ":"w","ẇ":"w","ẉ":"w","ẁ":"w","ⱳ":"w","ẘ":"w","ẍ":"x","ẋ":"x","ᶍ":"x","ý":"y","ŷ":"y","ÿ":"y","ẏ":"y","ỵ":"y","ỳ":"y","ƴ":"y","ỷ":"y","ỿ":"y","ȳ":"y","ẙ":"y","ɏ":"y","ỹ":"y","ź":"z","ž":"z","ẑ":"z","ʑ":"z","ⱬ":"z","ż":"z","ẓ":"z","ȥ":"z","ẕ":"z","ᵶ":"z","ᶎ":"z","ʐ":"z","ƶ":"z","ɀ":"z","ff":"ff","ffi":"ffi","ffl":"ffl","fi":"fi","fl":"fl","ij":"ij","œ":"oe","st":"st","ₐ":"a","ₑ":"e","ᵢ":"i","ⱼ":"j","ₒ":"o","ᵣ":"r","ᵤ":"u","ᵥ":"v","ₓ":"x"}; return s.replace(/[^A-Za-z0-9\[\] ]/g,function(a){return accentsMap[a]||a}); } export const removeAccents = removeSpecialChars; if(typeof String.prototype.removeSpecialChars !=="function"){ String.prototype.removeSpecialChars = function(){ return removeSpecialChars(this.toString()); } } if(typeof String.prototype.removeAccents !=='function'){ String.prototype.removeAccents = function(){ return removeSpecialChars(this.toString()); } }