1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | const escape_diacritic_1 = __importDefault(require("./escape_diacritic"));
|
6 | const escape_regexp_1 = __importDefault(require("./escape_regexp"));
|
7 |
|
8 | const rControl = /[\u0000-\u001f]/g;
|
9 | const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g;
|
10 | function slugize(str, options = {}) {
|
11 | if (typeof str !== 'string')
|
12 | throw new TypeError('str must be a string!');
|
13 | const separator = options.separator || '-';
|
14 | const escapedSep = (0, escape_regexp_1.default)(separator);
|
15 | const result = (0, escape_diacritic_1.default)(str)
|
16 |
|
17 | .replace(rControl, '')
|
18 |
|
19 | .replace(rSpecial, separator)
|
20 |
|
21 | .replace(new RegExp(`${escapedSep}{2,}`, 'g'), separator)
|
22 |
|
23 | .replace(new RegExp(`^${escapedSep}+|${escapedSep}+$`, 'g'), '');
|
24 | switch (options.transform) {
|
25 | case 1:
|
26 | return result.toLowerCase();
|
27 | case 2:
|
28 | return result.toUpperCase();
|
29 | default:
|
30 | return result;
|
31 | }
|
32 | }
|
33 | module.exports = slugize;
|
34 |
|
\ | No newline at end of file |