Permalink
Browse files

Trim dashes after slugification

  • Loading branch information...
Laurens Claessen
Laurens Claessen committed Oct 30, 2017
1 parent a592ca3 commit a459d34c06f68879b6a172dfc3d7f794f829fe90
Showing with 4 additions and 3 deletions.
  1. +3 −2 src/slugify.js
  2. +1 −1 test/slugify.test.js
View
@@ -35,6 +35,7 @@ export default (value) => {
const valueWithoutSpaces = removeSpaces(trimValue, '-')
const valueWithE = replace(valueWithoutSpaces, '&', '-and-')
const transliterateValue = transliterate(valueWithE)
const replaceValue = replace(transliterateValue, '[^\\w\\-]+', '')
return replace(replaceValue, '-+', '-')
const wordsOnlyValue = replace(transliterateValue, '[^\\w\\-]+', '')
const singleDashesValue = replace(wordsOnlyValue, '-+', '-')
return trim(singleDashesValue, '-')
}
View
@@ -2,7 +2,7 @@ import slugify from '../src/slugify'
describe('strman.slugfiy', () => {
test('should be foo-bar', () => {
const fixtures = ['foo bar', 'foo bar.', 'foo bar ', ' foo bar', ' foo bar ', 'foo------bar', 'fóõ bár', 'foo ! bar', 'foo ~~ bar', 'foo bar', 'FOO bar']
const fixtures = ['foo bar', 'foo bar.', 'foo bar ', 'foo bar .', ' foo bar', ' foo bar ', 'foo------bar', 'fóõ bár', 'foo ! bar', 'foo ~~ bar', 'foo bar', 'FOO bar']
fixtures.forEach((el) => {
expect(slugify(el)).toBe('foo-bar')

0 comments on commit a459d34

Please sign in to comment.