File tree 4 files changed +28
-9
lines changed
packages/@vuepress/shared-utils
4 files changed +28
-9
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
+ 'Iлtèrnåtïonɑlíƶatï߀ԉ' : 'iлternationɑliƶati߀ԉ' ,
9
+ '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òлɢùê.' :
10
+ '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' ,
11
+ 'ᴎᴑᴅᴇȷʂ' : 'ᴎᴑᴅᴇȷʂ' ,
12
+ 'hambúrguer' : 'hamburguer' ,
13
+ 'hŒllœ' : 'hœllœ' ,
14
+ 'Fußball' : 'fußball' ,
15
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZé' : 'abcdefghijklmnopqrstuvwxyze' ,
16
+ }
17
+
18
+ Object . keys ( asserts ) . forEach ( input => {
19
+ expect ( slugify ( input ) ) . toBe ( asserts [ input ] )
20
+ } )
21
+ } )
22
+ } )
Original file line number Diff line number Diff line change 28
28
],
29
29
"dependencies" : {
30
30
"chalk" : " ^2.3.2" ,
31
- "diacritics" : " ^1.3.0" ,
32
31
"escape-html" : " ^1.0.3" ,
33
32
"fs-extra" : " ^7.0.1" ,
34
33
"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
- // @ts -ignore
4
- import { remove as removeDiacritics } from 'diacritics'
5
3
6
4
// eslint-disable-next-line no-control-regex
7
5
const rControl = / [ \u0000 - \u001f ] / g
8
6
const rSpecial = / [ \s ~ ` ! @ # $ % ^ & * ( ) \- _ + = [ \] { } | \\ ; : " ' < > , . ? / ] + / g
7
+ const rCombining = / [ \u0300 - \u036F ] / g;
9
8
10
9
export = function slugify ( str : string ) : string {
11
- return removeDiacritics ( str )
12
- // Remove control characters
10
+ // Split accented characters into components
11
+ return str . normalize ( 'NFKD' )
12
+ // Remove accents
13
+ . replace ( rCombining , '' )
14
+ // Remove control characters
13
15
. replace ( rControl , '' )
14
16
// Replace special characters
15
17
. replace ( rSpecial , '-' )
Original file line number Diff line number Diff line change @@ -4174,10 +4174,6 @@ dezalgo@^1.0.0:
4174
4174
asap "^2.0.0"
4175
4175
wrappy "1"
4176
4176
4177
- diacritics@^1.3.0 :
4178
- version "1.3.0"
4179
- resolved "https://registry.yarnpkg.com/diacritics/-/diacritics-1.3.0.tgz#3efa87323ebb863e6696cebb0082d48ff3d6f7a1"
4180
-
4181
4177
didyoumean@^1.2.1 :
4182
4178
version "1.2.1"
4183
4179
resolved "https://registry.yarnpkg.com/didyoumean/-/didyoumean-1.2.1.tgz#e92edfdada6537d484d73c0172fd1eba0c4976ff"
You can’t perform that action at this time.
0 commit comments