Skip to content

Commit bcacdcc

Browse files
authored
Update index.ts
1 parent 2a5815d commit bcacdcc

File tree

1 file changed

+8
-85
lines changed

1 file changed

+8
-85
lines changed

src/index.ts

Lines changed: 8 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,11 @@
11
export function slugify(input: string): string {
2-
if (typeof input !== 'string' || input.trim() === '')
3-
return ''
4-
5-
const accentMapping = new Map<string, string>([
6-
['á', 'a'],
7-
['à', 'a'],
8-
['ă', 'a'],
9-
['ắ', 'a'],
10-
['ằ', 'a'],
11-
['ẵ', 'a'],
12-
['ẳ', 'a'],
13-
['â', 'a'],
14-
['ấ', 'a'],
15-
['ầ', 'a'],
16-
['ẫ', 'a'],
17-
['ẩ', 'a'],
18-
['ã', 'a'],
19-
['ả', 'a'],
20-
['ạ', 'a'],
21-
['ặ', 'a'],
22-
['ậ', 'a'],
23-
['đ', 'd'],
24-
['é', 'e'],
25-
['è', 'e'],
26-
['ê', 'e'],
27-
['ế', 'e'],
28-
['ề', 'e'],
29-
['ễ', 'e'],
30-
['ể', 'e'],
31-
['ẽ', 'e'],
32-
['ẻ', 'e'],
33-
['ẹ', 'e'],
34-
['ệ', 'e'],
35-
['í', 'i'],
36-
['ì', 'i'],
37-
['ĩ', 'i'],
38-
['ỉ', 'i'],
39-
['ị', 'i'],
40-
['ó', 'o'],
41-
['ò', 'o'],
42-
['ô', 'o'],
43-
['ố', 'o'],
44-
['ồ', 'o'],
45-
['ỗ', 'o'],
46-
['ổ', 'o'],
47-
['õ', 'o'],
48-
['ỏ', 'o'],
49-
['ơ', 'o'],
50-
['ớ', 'o'],
51-
['ờ', 'o'],
52-
['ỡ', 'o'],
53-
['ở', 'o'],
54-
['ợ', 'o'],
55-
['ọ', 'o'],
56-
['ộ', 'o'],
57-
['ú', 'u'],
58-
['ù', 'u'],
59-
['ũ', 'u'],
60-
['ủ', 'u'],
61-
['ư', 'u'],
62-
['ứ', 'u'],
63-
['ừ', 'u'],
64-
['ữ', 'u'],
65-
['ử', 'u'],
66-
['ự', 'u'],
67-
['ụ', 'u'],
68-
['ý', 'y'],
69-
['ỳ', 'y'],
70-
['ỹ', 'y'],
71-
['ỷ', 'y'],
72-
['ỵ', 'y'],
73-
])
74-
75-
let slug = input.toLowerCase()
76-
77-
slug = slug
78-
.split('')
79-
.map(char => accentMapping.get(char) || char)
80-
.join('')
81-
82-
slug = slug
83-
.replace(/[^0-9a-z]+/g, '-')
84-
.replace(/-+/g, '-')
2+
if (!input || typeof input !== 'string') return ''
3+
return input
4+
.toLowerCase()
5+
.normalize('NFD')
6+
.replace(/[\u0300-\u036f]/g, '')
7+
.replace(/đ/g, 'd')
8+
.replace(/[^a-z0-9]+/g, '-')
859
.replace(/^-+|-+$/g, '')
86-
87-
return slug
10+
.replace(/-+/g, '-')
8811
}

0 commit comments

Comments
 (0)