File tree 2 files changed +36
-3
lines changed
packages/@vuepress/shared-utils
2 files changed +36
-3
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 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 , '-' )
You can’t perform that action at this time.
0 commit comments