-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (30 loc) · 835 Bytes
/
index.js
File metadata and controls
35 lines (30 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const tck = require('tck')
module.exports = (str, options) => {
if (!str) return
str = str.toLowerCase()
const replaces = {
'[<$+%>!¡`*‘’\'|{¿?“”=}/:\\/"]': '',
'[\\s,&.]': '-',
'[àáâãäå]': 'a',
æ: 'ae',
'[èéêë]': 'e',
'[ìíîï]': 'i',
'[òóôõö]': 'o',
'[ùúûü]': 'u',
'[ỳýŷÿ]': 'y',
'-+': '-',
'^-+': '',
'-+$': ''
}
if (tck.isEmpty(options) || tck.isEmpty(options.spanish) || options.spanish === false) {
replaces['ñ'] = 'n'
replaces['ç'] = 'c'
}
if (tck.isEmpty(options) || tck.isEmpty(options.social) || options.social === false) {
replaces['[#@]'] = ''
}
Object.keys(replaces).forEach(key => {
str = str.replace(new RegExp(key, 'gi'), replaces[key])
})
return str.replace(new RegExp('-', 'gi'), ' ')
}