File tree 4 files changed +36
-8
lines changed
packages/@vuepress/shared-utils
4 files changed +36
-8
lines changed Original file line number Diff line number Diff line change
1
+ import slugify from '../src/slugify'
2
+
3
+ describe ( 'slugify' , ( ) => {
4
+ test ( 'should slugify' , ( ) => {
5
+ const asserts : Record < string , string > = {
6
+ 'Привет' : 'привет' ,
7
+ 'Лед üäöß' : 'лед-uaoß' ,
8
+ 'hangul 가' : 'hangul-가' ,
9
+ 'ع' : 'ع' ,
10
+ 'džℍΩ' : 'dzhω' ,
11
+ 'カi⁹' : 'カi9' ,
12
+ // ㌀ -> アパート'
13
+ '㌀' : decodeURIComponent ( '%E3%82%A2%E3%83%8F%E3%82%9A%E3%83%BC%E3%83%88' ) ,
14
+ '¼' : '_1⁄4' ,
15
+ 'džℍΩカi⁹¼' : 'dzhωカi91⁄4' ,
16
+ 'Iлtèrnåtïonɑlíƶatï߀ԉ' : 'iлternationɑliƶati߀ԉ' ,
17
+ 'Båcòл ípѕùm ðoɭ߀r ѕït aϻèt âùþê aԉᏧ߀üïlɭê ƃëéf culρá fïlèt ϻiǥnòn cuρiᏧatat ut êлim tòлɢùê.' :
18
+ 'bacoл-ipѕum-ðoɭ߀r-ѕit-aϻet-auþe-aԉꮷ߀uilɭe-ƃeef-culρa-filet-ϻiǥnon-cuρiꮷatat-ut-eлim-toлɢue' ,
19
+ 'ᴎᴑᴅᴇȷʂ' : 'ᴎᴑᴅᴇȷʂ' ,
20
+ 'hambúrguer' : 'hamburguer' ,
21
+ 'hŒllœ' : 'hœllœ' ,
22
+ 'Fußball' : 'fußball' ,
23
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZé' : 'abcdefghijklmnopqrstuvwxyze'
24
+ }
25
+
26
+ Object . keys ( asserts ) . forEach ( input => {
27
+ expect ( slugify ( input ) ) . toBe ( asserts [ input ] )
28
+ } )
29
+ } )
30
+ } )
Original file line number Diff line number Diff line change 31
31
},
32
32
"dependencies" : {
33
33
"chalk" : " ^2.3.2" ,
34
- "diacritics" : " ^1.3.0" ,
35
34
"escape-html" : " ^1.0.3" ,
36
35
"fs-extra" : " ^7.0.1" ,
37
36
"globby" : " ^9.2.0" ,
Original file line number Diff line number Diff line change 1
1
// string.js slugify drops non ascii chars so we have to
2
2
// use a custom implementation here
3
- import { remove as removeDiacritics } from 'diacritics'
4
3
5
4
// eslint-disable-next-line no-control-regex
6
5
const rControl = / [ \u0000 - \u001f ] / g
7
6
const rSpecial = / [ \s ~ ` ! @ # $ % ^ & * ( ) \- _ + = [ \] { } | \\ ; : " ' “ ” ‘ ’ – — < > , . ? / ] + / g
7
+ const rCombining = / [ \u0300 - \u036F ] / g
8
8
9
9
export = function slugify ( str : string ) : string {
10
- return removeDiacritics ( str )
11
- // Remove control characters
10
+ // Split accented characters into components
11
+ return str . normalize ( 'NFKD' )
12
+ // Remove accents
13
+ . replace ( rCombining , '' )
14
+ // Remove control characters
12
15
. replace ( rControl , '' )
13
16
// Replace special characters
14
17
. replace ( rSpecial , '-' )
Original file line number Diff line number Diff line change @@ -5125,10 +5125,6 @@ dezalgo@^1.0.0:
5125
5125
asap "^2.0.0"
5126
5126
wrappy "1"
5127
5127
5128
- diacritics@^1.3.0:
5129
- version "1.3.0"
5130
- resolved "https://registry.yarnpkg.com/diacritics/-/diacritics-1.3.0.tgz#3efa87323ebb863e6696cebb0082d48ff3d6f7a1"
5131
-
5132
5128
didyoumean@^1.2.1:
5133
5129
version "1.2.1"
5134
5130
resolved "https://registry.yarnpkg.com/didyoumean/-/didyoumean-1.2.1.tgz#e92edfdada6537d484d73c0172fd1eba0c4976ff"
You can’t perform that action at this time.
0 commit comments