1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00
joplin/packages/lib/string-utils-common.js

60 lines
1.3 KiB
JavaScript
Raw Normal View History

// Leave this file as JavaScript -- our current TypeScript configuration
// generates code that tries to access modules/exports, which is incompatible
// with browser environments.
function pregQuote(str, delimiter = '') {
2019-09-19 23:51:18 +02:00
return (`${str}`).replace(new RegExp(`[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\${delimiter || ''}-]`, 'g'), '\\$&');
}
function replaceRegexDiacritics(regexString) {
if (!regexString) return '';
const diacriticReplacements = {
2019-07-29 15:43:53 +02:00
a: '[aàáâãäåāą]',
A: '[AÀÁÂÃÄÅĀĄ]',
c: '[cçćč]',
C: '[CÇĆČ]',
d: '[dđď]',
D: '[DĐĎ]',
e: '[eèéêëěēę]',
E: '[EÈÉÊËĚĒĘ]',
i: '[iìíîïī]',
I: '[IÌÍÎÏĪ]',
l: '[lł]',
L: '[LŁ]',
n: '[nñňń]',
N: '[NÑŇŃ]',
o: '[oòóôõöøō]',
O: '[OÒÓÔÕÖØŌ]',
r: '[rř]',
R: '[RŘ]',
s: '[sšś]',
S: '[SŠŚ]',
t: '[tť]',
T: '[TŤ]',
u: '[uùúûüůū]',
U: '[UÙÚÛÜŮŪ]',
y: '[yÿý]',
Y: '[YŸÝ]',
z: '[zžżź]',
Z: '[ZŽŻŹ]',
};
let output = '';
for (let i = 0; i < regexString.length; i++) {
const c = regexString[i];
const r = diacriticReplacements[c];
if (r) {
output += r;
} else {
output += c;
}
}
return output;
}
if (typeof module !== 'undefined') {
module.exports = { pregQuote, replaceRegexDiacritics };
}