Skip to content

Commit e16980f

Browse files
committed
fix(-utils): use String.normalize to generate slugs (vuejs#1815)
1 parent c82cc10 commit e16980f

File tree

4 files changed

+59
-24
lines changed

4 files changed

+59
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
})

packages/@vuepress/shared-utils/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
],
2828
"dependencies": {
2929
"chalk": "^2.3.2",
30-
"diacritics": "^1.3.0",
3130
"escape-html": "^1.0.3",
3231
"fs-extra": "^5.0.0",
3332
"globby": "^8.0.1",

packages/@vuepress/shared-utils/src/slugify.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
// string.js slugify drops non ascii chars so we have to
22
// use a custom implementation here
33
// @ts-ignore
4-
import { remove as removeDiacritics } from 'diacritics'
54

65
// eslint-disable-next-line no-control-regex
76
const rControl = /[\u0000-\u001f]/g
87
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g
8+
const rCombining = /[\u0300-\u036F]/g;
99

1010
export = function slugify (str: string): string {
11-
return removeDiacritics(str)
12-
// Remove control characters
11+
// Split accented characters into components
12+
return str.normalize('NFKD')
13+
// Remove accents
14+
.replace(rCombining, "")
15+
// Remove control characters
1316
.replace(rControl, '')
1417
// Replace special characters
1518
.replace(rSpecial, '-')

yarn.lock

+31-20
Original file line numberDiff line numberDiff line change
@@ -1837,15 +1837,16 @@ autoprefixer@^6.3.1:
18371837
postcss "^5.2.16"
18381838
postcss-value-parser "^3.2.3"
18391839

1840-
autoprefixer@^8.2.0:
1841-
version "8.6.5"
1842-
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-8.6.5.tgz#343f3d193ed568b3208e00117a1b96eb691d4ee9"
1840+
autoprefixer@^7.1.2:
1841+
version "7.2.6"
1842+
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-7.2.6.tgz#256672f86f7c735da849c4f07d008abb056067dc"
1843+
integrity sha512-Iq8TRIB+/9eQ8rbGhcP7ct5cYb/3qjNYAR2SnzLCEcwF6rvVOax8+9+fccgXk4bEhQGjOZd5TLhsksmAdsbGqQ==
18431844
dependencies:
1844-
browserslist "^3.2.8"
1845-
caniuse-lite "^1.0.30000864"
1845+
browserslist "^2.11.3"
1846+
caniuse-lite "^1.0.30000805"
18461847
normalize-range "^0.1.2"
18471848
num2fraction "^1.2.2"
1848-
postcss "^6.0.23"
1849+
postcss "^6.0.17"
18491850
postcss-value-parser "^3.2.3"
18501851

18511852
aws-sign2@~0.7.0:
@@ -2247,12 +2248,13 @@ browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6:
22472248
caniuse-db "^1.0.30000639"
22482249
electron-to-chromium "^1.2.7"
22492250

2250-
browserslist@^3.2.8:
2251-
version "3.2.8"
2252-
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-3.2.8.tgz#b0005361d6471f0f5952797a76fc985f1f978fc6"
2251+
browserslist@^2.11.3:
2252+
version "2.11.3"
2253+
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-2.11.3.tgz#fe36167aed1bbcde4827ebfe71347a2cc70b99b2"
2254+
integrity sha512-yWu5cXT7Av6mVwzWc8lMsJMHWn4xyjSuGYi4IozbVTLUOEYPSagUB8kiMDUHA1fS3zjr8nkxkn9jdvug4BBRmA==
22532255
dependencies:
2254-
caniuse-lite "^1.0.30000844"
2255-
electron-to-chromium "^1.3.47"
2256+
caniuse-lite "^1.0.30000792"
2257+
electron-to-chromium "^1.3.30"
22562258

22572259
browserslist@^4.1.0:
22582260
version "4.3.4"
@@ -2447,9 +2449,10 @@ caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634, caniuse-db@^1.0.30000639:
24472449
version "1.0.30000864"
24482450
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000864.tgz#35a4b2325a8d4553a46b516dbc233bf391d75555"
24492451

2450-
caniuse-lite@^1.0.30000844, caniuse-lite@^1.0.30000864:
2451-
version "1.0.30000864"
2452-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000864.tgz#7a08c78da670f23c06f11aa918831b8f2dd60ddc"
2452+
caniuse-lite@^1.0.30000792, caniuse-lite@^1.0.30000805:
2453+
version "1.0.30000989"
2454+
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000989.tgz#b9193e293ccf7e4426c5245134b8f2a56c0ac4b9"
2455+
integrity sha512-vrMcvSuMz16YY6GSVZ0dWDTJP8jqk3iFQ/Aq5iqblPwxSVVZI+zxDyTX0VPqtQsDnfdrBDcsmhgTEOh5R8Lbpw==
24532456

24542457
caniuse-lite@^1.0.30000899:
24552458
version "1.0.30000906"
@@ -3514,10 +3517,6 @@ dezalgo@^1.0.0:
35143517
asap "^2.0.0"
35153518
wrappy "1"
35163519

3517-
diacritics@^1.3.0:
3518-
version "1.3.0"
3519-
resolved "https://registry.yarnpkg.com/diacritics/-/diacritics-1.3.0.tgz#3efa87323ebb863e6696cebb0082d48ff3d6f7a1"
3520-
35213520
diff@^3.2.0:
35223521
version "3.5.0"
35233522
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
@@ -3655,10 +3654,15 @@ [email protected]:
36553654
version "1.1.1"
36563655
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
36573656

3658-
electron-to-chromium@^1.2.7, electron-to-chromium@^1.3.47:
3657+
electron-to-chromium@^1.2.7:
36593658
version "1.3.51"
36603659
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.51.tgz#6a42b49daaf7f22a5b37b991daf949f34dbdb9b5"
36613660

3661+
electron-to-chromium@^1.3.30:
3662+
version "1.3.256"
3663+
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.256.tgz#7f680d5f04df8e2bd9cb9758026d70f5ff1808a9"
3664+
integrity sha512-GHY1r2mO56BRMng6rkxxJvsWKtqy9k/IlSBrAV/VKwZKpTydVUJnOwajTNnl5uutJpthHgZy+HeofK5K6PqEgQ==
3665+
36623666
electron-to-chromium@^1.3.82:
36633667
version "1.3.83"
36643668
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.83.tgz#74584eb0972bb6777811c5d68d988c722f5e6666"
@@ -6498,6 +6502,13 @@ lru-cache@^4.1.3:
64986502
pseudomap "^1.0.2"
64996503
yallist "^2.1.2"
65006504

6505+
lru-cache@^5.1.1:
6506+
version "5.1.1"
6507+
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920"
6508+
integrity sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==
6509+
dependencies:
6510+
yallist "^3.0.2"
6511+
65016512
make-dir@^1.0.0:
65026513
version "1.3.0"
65036514
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.3.0.tgz#79c1033b80515bd6d24ec9933e860ca75ee27f0c"
@@ -7999,7 +8010,7 @@ postcss@^5.0.10, postcss@^5.0.11, postcss@^5.0.12, postcss@^5.0.13, postcss@^5.0
79998010
source-map "^0.5.6"
80008011
supports-color "^3.2.3"
80018012

8002-
postcss@^6.0.0, postcss@^6.0.20, postcss@^6.0.23:
8013+
postcss@^6.0.0, postcss@^6.0.17, postcss@^6.0.20:
80038014
version "6.0.23"
80048015
resolved "https://registry.yarnpkg.com/postcss/-/postcss-6.0.23.tgz#61c82cc328ac60e677645f979054eb98bc0e3324"
80058016
dependencies:

0 commit comments

Comments
 (0)