Skip to content

Commit

Permalink
chore: remove symbols
Browse files Browse the repository at this point in the history
Too much magic, and a localization nightmare.

BREAKING CHANGE: symbols are removed
  • Loading branch information
Trott committed Oct 21, 2020
1 parent 8848610 commit 853ad52
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 174 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ npm install slug
var slug = require('slug')
var print = console.log.bind(console, '>')

print(slug('i unicode'))
print(slug('i love unicode'))
// > i-love-unicode

print(slug('i unicode', '_')) // If you prefer something else than `-` as separator
print(slug('i love unicode', '_')) // If you prefer something else than `-` as separator
// > i_love_unicode

slug.charmap[''] = 'freaking love' // change default charmap or use option {charmap:{…}} as 2. argument
Expand All @@ -34,9 +34,6 @@ print(slug('Telephone-Number')) // lower case by default
print(slug('Telephone-Number', {lower: false})) // If you want to preserve case
// > Telephone-Number

print(slug('i <3 unicode'))
// > i-love-unicode

// We try to provide sensible defaults.
// So Cyrillic text will be transliterated as if it were Russian:
print(slug('компютъра'))
Expand Down
62 changes: 1 addition & 61 deletions slug.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,6 @@
}

const initialMulticharmap = {
'<3': 'love',
'&&': 'and',
'||': 'or',
'w/': 'with',
// multibyte devanagari characters (hindi, sanskrit, etc.)
फ़: 'Fi',
ग़: 'Ghi',
Expand Down Expand Up @@ -852,63 +848,7 @@
ק: 'k',
ר: 'r',
תּ: 't',
ת: 't',
// currency
'€': 'euro',
'₢': 'cruzeiro',
'₣': 'french franc',
'£': 'pound',
'₤': 'lira',
'₥': 'mill',
'₦': 'naira',
'₧': 'peseta',
'₨': 'rupee',
'₩': 'won',
'₪': 'new shequel',
'₫': 'dong',
'₭': 'kip',
'₮': 'tugrik',
'₯': 'drachma',
'₰': 'penny',
'₱': 'peso',
'₲': 'guarani',
'₳': 'austral',
'₴': 'hryvnia',
'₵': 'cedi',
'¢': 'cent',
'¥': 'yen',
: 'yuan',
: 'yen',
'﷼': 'rial',
'₠': 'ecu',
'¤': 'currency',
'฿': 'baht',
$: 'dollar',
'₹': 'indian rupee',
'₽': 'russian ruble',
'₿': 'bitcoin',
'₸': 'kazakhstani tenge',
// symbols
'©': 'c',
œ: 'oe',
Œ: 'OE',
'∑': 'sum',
'®': 'r',
'∂': 'd',
ƒ: 'f',
'™': 'tm',
'℠': 'sm',
'…': '...',
'˚': 'o',
º: 'o',
ª: 'a',
'∆': 'delta',
'∞': 'infinity',
'♥': 'love',
'&': 'and',
'|': 'or',
'<': 'less',
'>': 'greater'
ת: 't'
}

slug.charmap = Object.assign({}, initialCharmap)
Expand Down
110 changes: 2 additions & 108 deletions test/slug.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,110 +826,6 @@ describe('slug', function () {
}
})

it('should replace currencies', function () {
const charMap = {
'€': 'euro',
'₢': 'cruzeiro',
'₣': 'french franc',
'£': 'pound',
'₤': 'lira',
'₥': 'mill',
'₦': 'naira',
'₧': 'peseta',
'₨': 'rupee',
'₹': 'indian rupee',
'₩': 'won',
'₪': 'new shequel',
'₫': 'dong',
'₭': 'kip',
'₮': 'tugrik',
'₯': 'drachma',
'₰': 'penny',
'₱': 'peso',
'₲': 'guarani',
'₳': 'austral',
'₴': 'hryvnia',
'₵': 'cedi',
'¢': 'cent',
'¥': 'yen',
: 'yuan',
: 'yen',
'﷼': 'rial',
'₠': 'ecu',
'¤': 'currency',
'฿': 'baht',
$: 'dollar',
'₽': 'russian ruble',
'₿': 'bitcoin',
'₸': 'kazakhstani tenge'
}
for (let char in charMap) { // eslint-disable-line prefer-const
let replacement = charMap[char]
replacement = replacement.replace(' ', '-')
assert.strictEqual(slug('foo ' + char + ' bar baz'), 'foo-' + replacement + '-bar-baz', 'replacing \'' + char + '\'')
}
})

it('should replace symbols in rfc3986 mode', function () {
const charMap = {
'©': 'c',
œ: 'oe',
Œ: 'OE',
'∑': 'sum',
'®': 'r',
'∂': 'd',
ƒ: 'f',
'™': 'tm',
'℠': 'sm',
'…': '...',
'˚': 'o',
º: 'o',
ª: 'a',
'∆': 'delta',
'∞': 'infinity',
'♥': 'love',
'&': 'and',
'|': 'or',
'<': 'less',
'>': 'greater'
}
for (let char in charMap) { // eslint-disable-line prefer-const
const replacement = charMap[char]
assert.strictEqual(
slug('foo ' + char + ' bar baz', { mode: 'rfc3986' }),
'foo-' + replacement.toLowerCase() + '-bar-baz', 'replacing \'' + char + '\''
)
}
})

it('should replace symbols in pretty mode', function () {
const charMap = {
'©': 'c',
œ: 'oe',
Œ: 'OE',
'∑': 'sum',
'®': 'r',
'∂': 'd',
ƒ: 'f',
'™': 'tm',
'℠': 'sm',
'˚': 'o',
º: 'o',
ª: 'a',
'∆': 'delta',
'∞': 'infinity',
'♥': 'love',
'&': 'and',
'|': 'or',
'<': 'less',
'>': 'greater'
}
for (let char in charMap) { // eslint-disable-line prefer-const
const replacement = charMap[char]
assert.strictEqual(slug('foo ' + char + ' bar baz'), 'foo-' + replacement.toLowerCase() + '-bar-baz', 'replacing \'' + char + '\'')
}
})

it('should remove ellipsis in pretty mode', function () {
const charMap = {
'…': '...'
Expand Down Expand Up @@ -966,8 +862,6 @@ describe('slug', function () {

it('should replace lithuanian characters', function () { assert.strictEqual(slug('ąčęėįšųūžĄČĘĖĮŠŲŪŽ'), 'aceeisuuzaceeisuuz') })

it('should replace multichars', function () { assert.strictEqual(slug('w/ <3 && sugar || cinnamon'), 'with-love-and-sugar-or-cinnamon') })

it('should be flavourable', function () {
const text = "It's your journey ... we guide you through."
const expected = 'its-your-journey-we-guide-you-through'
Expand Down Expand Up @@ -1029,12 +923,12 @@ describe('slug', function () {
it('should replace zh characters', function () { assert.strictEqual(slug('鳄梨'), '6boe5qko') })

it('should permit replacing custom characters using .extend()', function () {
slug.extend({ '☢': 'radioactive' })
slug.extend({ '♥': 'love', '☢': 'radioactive' })
assert.strictEqual(slug('unicode ♥ is ☢'), 'unicode-love-is-radioactive')
})

it('should ignore symbols if they are not in the charmap', function () {
assert.strictEqual(slug('unicode ♥ is ☢'), 'unicode-love-is')
assert.strictEqual(slug('unicode ♥ is ☢'), 'unicode-is')
})

it('should ignore lone surrogates', function () {
Expand Down

0 comments on commit 853ad52

Please sign in to comment.