Skip to content

Commit

Permalink
fix(-utils): use String.normalize to generate slugs (vuejs#1815)
Browse files Browse the repository at this point in the history
  • Loading branch information
larionov committed Sep 12, 2019
1 parent c82cc10 commit 9f1f758
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 24 deletions.
22 changes: 22 additions & 0 deletions packages/@vuepress/shared-utils/__tests__/slugify.spec.ts
@@ -0,0 +1,22 @@
import slugify from '../src/slugify'

describe('slugify', () => {
test('should slugify', () => {
const asserts: Record<string, string> = {
'Привет': 'привет',
'Лед üäöß': 'лед-uaoß',
'Iлtèrnåtïonɑlíƶatï߀ԉ': 'iлternationɑliƶati߀ԉ',
'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òлɢùê.':
'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',
'ᴎᴑᴅᴇȷʂ': 'ᴎᴑᴅᴇȷʂ',
'hambúrguer': 'hamburguer',
'hŒllœ': 'hœllœ',
'Fußball': 'fußball',
'ABCDEFGHIJKLMNOPQRSTUVWXYZé': 'abcdefghijklmnopqrstuvwxyze',
}

Object.keys(asserts).forEach(input => {
expect(slugify(input)).toBe(asserts[input])
})
})
})
1 change: 0 additions & 1 deletion packages/@vuepress/shared-utils/package.json
Expand Up @@ -27,7 +27,6 @@
],
"dependencies": {
"chalk": "^2.3.2",
"diacritics": "^1.3.0",
"escape-html": "^1.0.3",
"fs-extra": "^5.0.0",
"globby": "^8.0.1",
Expand Down
9 changes: 6 additions & 3 deletions packages/@vuepress/shared-utils/src/slugify.ts
@@ -1,15 +1,18 @@
// string.js slugify drops non ascii chars so we have to
// use a custom implementation here
// @ts-ignore
import { remove as removeDiacritics } from 'diacritics'

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

export = function slugify (str: string): string {
return removeDiacritics(str)
// Remove control characters
// Split accented characters into components
return str.normalize('NFKD')
// Remove accents
.replace(combining, "")
// Remove control characters
.replace(rControl, '')
// Replace special characters
.replace(rSpecial, '-')
Expand Down
51 changes: 31 additions & 20 deletions yarn.lock
Expand Up @@ -1837,15 +1837,16 @@ autoprefixer@^6.3.1:
postcss "^5.2.16"
postcss-value-parser "^3.2.3"

autoprefixer@^8.2.0:
version "8.6.5"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-8.6.5.tgz#343f3d193ed568b3208e00117a1b96eb691d4ee9"
autoprefixer@^7.1.2:
version "7.2.6"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-7.2.6.tgz#256672f86f7c735da849c4f07d008abb056067dc"
integrity sha512-Iq8TRIB+/9eQ8rbGhcP7ct5cYb/3qjNYAR2SnzLCEcwF6rvVOax8+9+fccgXk4bEhQGjOZd5TLhsksmAdsbGqQ==
dependencies:
browserslist "^3.2.8"
caniuse-lite "^1.0.30000864"
browserslist "^2.11.3"
caniuse-lite "^1.0.30000805"
normalize-range "^0.1.2"
num2fraction "^1.2.2"
postcss "^6.0.23"
postcss "^6.0.17"
postcss-value-parser "^3.2.3"

aws-sign2@~0.7.0:
Expand Down Expand Up @@ -2247,12 +2248,13 @@ browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6:
caniuse-db "^1.0.30000639"
electron-to-chromium "^1.2.7"

browserslist@^3.2.8:
version "3.2.8"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-3.2.8.tgz#b0005361d6471f0f5952797a76fc985f1f978fc6"
browserslist@^2.11.3:
version "2.11.3"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-2.11.3.tgz#fe36167aed1bbcde4827ebfe71347a2cc70b99b2"
integrity sha512-yWu5cXT7Av6mVwzWc8lMsJMHWn4xyjSuGYi4IozbVTLUOEYPSagUB8kiMDUHA1fS3zjr8nkxkn9jdvug4BBRmA==
dependencies:
caniuse-lite "^1.0.30000844"
electron-to-chromium "^1.3.47"
caniuse-lite "^1.0.30000792"
electron-to-chromium "^1.3.30"

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

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

caniuse-lite@^1.0.30000899:
version "1.0.30000906"
Expand Down Expand Up @@ -3514,10 +3517,6 @@ dezalgo@^1.0.0:
asap "^2.0.0"
wrappy "1"

diacritics@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/diacritics/-/diacritics-1.3.0.tgz#3efa87323ebb863e6696cebb0082d48ff3d6f7a1"

diff@^3.2.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
Expand Down Expand Up @@ -3655,10 +3654,15 @@ ee-first@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"

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

electron-to-chromium@^1.3.30:
version "1.3.256"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.256.tgz#7f680d5f04df8e2bd9cb9758026d70f5ff1808a9"
integrity sha512-GHY1r2mO56BRMng6rkxxJvsWKtqy9k/IlSBrAV/VKwZKpTydVUJnOwajTNnl5uutJpthHgZy+HeofK5K6PqEgQ==

electron-to-chromium@^1.3.82:
version "1.3.83"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.83.tgz#74584eb0972bb6777811c5d68d988c722f5e6666"
Expand Down Expand Up @@ -6498,6 +6502,13 @@ lru-cache@^4.1.3:
pseudomap "^1.0.2"
yallist "^2.1.2"

lru-cache@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920"
integrity sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==
dependencies:
yallist "^3.0.2"

make-dir@^1.0.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.3.0.tgz#79c1033b80515bd6d24ec9933e860ca75ee27f0c"
Expand Down Expand Up @@ -7999,7 +8010,7 @@ postcss@^5.0.10, postcss@^5.0.11, postcss@^5.0.12, postcss@^5.0.13, postcss@^5.0
source-map "^0.5.6"
supports-color "^3.2.3"

postcss@^6.0.0, postcss@^6.0.20, postcss@^6.0.23:
postcss@^6.0.0, postcss@^6.0.17, postcss@^6.0.20:
version "6.0.23"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-6.0.23.tgz#61c82cc328ac60e677645f979054eb98bc0e3324"
dependencies:
Expand Down

0 comments on commit 9f1f758

Please sign in to comment.