1 | import unidecode from 'unidecode';
|
2 |
|
3 | function slugy(string, { separator = '-', lower = true } = {}) {
|
4 | let slug = unidecode(string)
|
5 | .replace(/[:/?#[\]@!$&'()*+,;=\\%<>|^~£"]/g, '')
|
6 | .replace(/(\s|\.)/g, separator)
|
7 | .replace(/-+/g, separator);
|
8 |
|
9 | if (lower) {
|
10 | slug = slug.toLowerCase();
|
11 | }
|
12 |
|
13 | if (slug.substring(slug.length - 1) === '-') {
|
14 | slug = slug.substring(0, slug.length - 1);
|
15 | }
|
16 |
|
17 | return slug;
|
18 | }
|
19 |
|
20 | export { slugy };
|