File tree Expand file tree Collapse file tree 4 files changed +36
-8
lines changed
packages/@vuepress/shared-utils Expand file tree Collapse file tree 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 3131 },
3232 "dependencies" : {
3333 "chalk" : " ^2.3.2" ,
34- "diacritics" : " ^1.3.0" ,
3534 "escape-html" : " ^1.0.3" ,
3635 "fs-extra" : " ^7.0.1" ,
3736 "globby" : " ^9.2.0" ,
Original file line number Diff line number Diff line change 11// string.js slugify drops non ascii chars so we have to
22// use a custom implementation here
3- import { remove as removeDiacritics } from 'diacritics'
43
54// eslint-disable-next-line no-control-regex
65const rControl = / [ \u0000 - \u001f ] / g
76const rSpecial = / [ \s ~ ` ! @ # $ % ^ & * ( ) \- _ + = [ \] { } | \\ ; : " ' “ ” ‘ ’ – — < > , . ? / ] + / g
7+ const rCombining = / [ \u0300 - \u036F ] / g
88
99export = 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
1215 . replace ( rControl , '' )
1316 // Replace special characters
1417 . replace ( rSpecial , '-' )
Original file line number Diff line number Diff line change @@ -5125,10 +5125,6 @@ dezalgo@^1.0.0:
51255125 asap "^2.0.0"
51265126 wrappy "1"
51275127
5128- diacritics@^1.3.0:
5129- version "1.3.0"
5130- resolved "https://registry.yarnpkg.com/diacritics/-/diacritics-1.3.0.tgz#3efa87323ebb863e6696cebb0082d48ff3d6f7a1"
5131-
51325128didyoumean@^1.2.1:
51335129 version "1.2.1"
51345130 resolved "https://registry.yarnpkg.com/didyoumean/-/didyoumean-1.2.1.tgz#e92edfdada6537d484d73c0172fd1eba0c4976ff"
You can’t perform that action at this time.
0 commit comments