Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: simov/slugify
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.3.5
Choose a base ref
...
head repository: simov/slugify
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.3.6
Choose a head ref
  • 7 commits
  • 8 files changed
  • 3 contributors

Commits on Sep 8, 2019

  1. Update tests

    simov committed Sep 8, 2019
    Copy the full SHA
    baf64f1 View commit details
  2. Remove locale name

    simov committed Sep 8, 2019
    Copy the full SHA
    b4d7c52 View commit details

Commits on Sep 20, 2019

  1. Fix broken link in README

    roschaefer authored Sep 20, 2019
    Copy the full SHA
    1bb56e5 View commit details

Commits on Sep 22, 2019

  1. Learned how to use named links

    thanks @simov
    roschaefer authored Sep 22, 2019
    Copy the full SHA
    76cf34b View commit details

Commits on Sep 23, 2019

  1. Merge pull request #63 from roschaefer/patch-1

    Fix broken link in README
    simov authored Sep 23, 2019
    Copy the full SHA
    a2da3d7 View commit details

Commits on Nov 3, 2019

  1. Copy the full SHA
    2927f67 View commit details
  2. 1.3.6

    simov committed Nov 3, 2019
    Copy the full SHA
    ca87de4 View commit details
Showing with 110 additions and 49 deletions.
  1. +3 −2 README.md
  2. +11 −1 bin/build.js
  3. +18 −0 config/charmap.json
  4. +4 −3 config/locales.json
  5. +1 −1 package.json
  6. +2 −2 slugify.js
  7. +30 −11 test/locales.js
  8. +41 −29 test/slugify.js
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ slugify('some string', '_') // some_string

- Vanilla ES5 JavaScript
- No dependencies
- Coerces foreign symbols to their English equivalent (check out the `charMap` in [index.js][index] for more details)
- Coerces foreign symbols to their English equivalent (check out the [charMap][charmap] for more details)
- Works in the browser (window.slugify) and AMD/CommonJS-flavored module loaders

## Options
@@ -31,7 +31,7 @@ For example, to remove `*+~.()'"!:@` from the result slug, you can use `slugify(

## Extend

Out of the box `slugify` comes with support for a handful of Unicode symbols. For example the `` (radioactive) symbol is not defined in the `charMap` object in [index.js][index] and therefore it will be stripped by default:
Out of the box `slugify` comes with support for a handful of Unicode symbols. For example the `` (radioactive) symbol is not defined in the [`charMap`][charmap] and therefore it will be stripped by default:

```js
slugify('unicode ♥ is ☢') // unicode-love-is
@@ -77,3 +77,4 @@ var slugify = require('slugify')
[slug]: https://www.npmjs.com/package/slug
[unicode]: https://www.npmjs.com/package/unicode
[index]: https://github.com/simov/slugify/blob/master/index.js
[charmap]: https://github.com/simov/slugify/blob/master/config/charmap.json
12 changes: 11 additions & 1 deletion bin/build.js
Original file line number Diff line number Diff line change
@@ -14,6 +14,16 @@ var sort = (obj) =>
.sort((a, b) => a > b ? 1 : a < b ? -1 : 0)
.reduce((all, key) => (all[key] = obj[key], all), {})

var clean = (locales) =>
Object.keys(locales)
.reduce((all, locale) => (
all[locale] =
Object.keys(locales[locale])
.filter((key) => key !== 'locale')
.reduce((all, key) => (all[key] = locales[locale][key], all), {}),
all
), {})


var build = () => {
// update charmap - remove duplicates and sort
@@ -32,7 +42,7 @@ var build = () => {
)
.replace(
/var locales = JSON\.parse\(.*\)/,
`var locales = JSON.parse('${JSON.stringify(locales)}')`
`var locales = JSON.parse('${JSON.stringify(clean(locales))}')`
)
fs.writeFileSync(path.resolve(__dirname, '../slugify.js'), source, 'utf8')
}
18 changes: 18 additions & 0 deletions config/charmap.json
Original file line number Diff line number Diff line change
@@ -328,9 +328,26 @@
"љ": "lj",
"њ": "nj",
"ћ": "c",
"ѝ": "u",
"џ": "dz",
"Ґ": "G",
"ґ": "g",
"Ғ": "GH",
"ғ": "gh",
"Қ": "KH",
"қ": "kh",
"Ң": "NG",
"ң": "ng",
"Ү": "UE",
"ү": "ue",
"Ұ": "U",
"ұ": "u",
"Һ": "H",
"һ": "h",
"Ә": "AE",
"ә": "ae",
"Ө": "OE",
"ө": "oe",
"฿": "baht",
"ა": "a",
"ბ": "b",
@@ -490,6 +507,7 @@
"₳": "austral",
"₴": "hryvnia",
"₵": "cedi",
"₸": "kazakhstani tenge",
"₹": "indian rupee",
"₽": "russian ruble",
"₿": "bitcoin",
7 changes: 4 additions & 3 deletions config/locales.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"bg": {
"locale": "Bulgarian",
"ѝ": "u"
"vi": {
"locale": "Vietnamese",
"Đ": "D",
"đ": "d"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slugify",
"version": "1.3.5",
"version": "1.3.6",
"description": "Slugifies a String",
"keywords": [
"slugify",
4 changes: 2 additions & 2 deletions slugify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 30 additions & 11 deletions test/locales.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@

var t = require('assert')
var slugify = require('../')


describe('locale', function () {
it('bg - bulgarian', function () {
describe('locale', () => {
it('bg - bulgarian', () => {
var alphabet =
'А а, Б б, В в, Г г, Д д, Е е, Ж ж, З з, И и, Й й, ' +
'К к, Л л, М м, Н н, О о, П п, Р р, С с, Т т, У у, ' +
'Ф ф, Х х, Ц ц, Ч ч, Ш ш, Щ щ, Ъ ъ, ѝ ь, Ю ю, Я я'

t.equal(slugify(alphabet, {locale: 'bg'}),
t.equal(slugify(alphabet),
'A-a-B-b-V-v-G-g-D-d-E-e-Zh-zh-Z-z-I-i-J-j-K-k-L-l-M-m-N-n-O-o-P-p-R-r-S-s-T-t-U-u-F-f-H-h-C-c-Ch-ch-Sh-sh-Sh-sh-U-u-u-Yu-yu-Ya-ya'
)
})

it('sr-c - serbian cyrillic', function () {
it('sr-c - serbian cyrillic', () => {
var alphabet =
'А а, Б б, В в, Г г, Д д, Ђ ђ, Е е, Ж ж, З з, И и, ' +
'Ј ј, К к, Л л, Љ љ, М м, Н н, Њ њ, О о, П п, Р р, ' +
'С с, Т т, Ћ ћ, У у, Ф ф, Х х, Ц ц, Ч ч, Џ џ, Ш ш'

t.equal(slugify(alphabet, {locale: 'sr-c'}),
t.equal(slugify(alphabet),
'A-a-B-b-V-v-G-g-D-d-DJ-dj-E-e-Zh-zh-Z-z-I-i-J-j-K-k-L-l-LJ-lj-M-m-N-n-NJ-nj-O-o-P-p-R-r-S-s-T-t-C-c-U-u-F-f-H-h-C-c-Ch-ch-DZ-dz-Sh-sh'
)
})

it('sr-l - serbian latin', function () {
it('sr-l - serbian latin', () => {
var alphabet =
'A a, B b, V v, G g, D d, Đ đ, E e, Ž ž, Z z, I i, ' +
'J j, K k, L l, Lj lj, M m, N n, Nj nj, O o, P p, R r, ' +
'S s, T t, Ć ć, U u, F f, H h, C c, Č č, Dž dž, Š š'

t.equal(slugify(alphabet, {locale: 'sr-l'}),
t.equal(slugify(alphabet),
'A-a-B-b-V-v-G-g-D-d-DJ-dj-E-e-Z-z-Z-z-I-i-J-j-K-k-L-l-Lj-lj-M-m-N-n-Nj-nj-O-o-P-p-R-r-S-s-T-t-C-c-U-u-F-f-H-h-C-c-C-c-Dz-dz-S-s'
)
})

it('tr - turkish', function () {
it('tr - turkish', () => {
var alphabet =
'A a, B b, C c, Ç ç, D d, E e, F f, G g, Ğ ğ, H h, ' +
'I ı, İ i, J j, K k, L l, M m, N n, O o, Ö ö, P p, ' +
'R r, S s, Ş ş, T t, U u, Ü ü, V v, Y y, Z z'

t.equal(slugify(alphabet, {locale: 'tr'}),
t.equal(slugify(alphabet),
'A-a-B-b-C-c-C-c-D-d-E-e-F-f-G-g-G-g-H-h-I-i-I-i-J-j-K-k-L-l-M-m-N-n-O-o-O-o-P-p-R-r-S-s-S-s-T-t-U-u-U-u-V-v-Y-y-Z-z'
)
})

it('ka - georgian', function () {
it('ka - georgian', () => {
var alphabet =
'ა, ბ, გ, დ, ე, ვ, ზ, თ, ი, კ, ლ, ' +
'მ, ნ, ო, პ, ჟ, რ, ს, ტ, უ, ფ, ქ, ' +
@@ -58,4 +57,24 @@ describe('locale', function () {
'a-b-g-d-e-v-z-t-i-k-l-m-n-o-p-zh-r-s-t-u-f-k-gh-q-sh-ch-ts-dz-ts-ch-kh-j-h'
)
})

it('kk - kazakh cyrillic', () => {
var alphabet =
'Ә ә, Ғ ғ, Қ қ, Ң ң, Ү ү, Ұ ұ, Һ һ, Ө ө'

t.equal(slugify(alphabet), 'AE-ae-GH-gh-KH-kh-NG-ng-UE-ue-U-u-H-h-OE-oe')
})

it('vi - vietnamese', () => {
var alphabet =
'Đ đ'

t.equal(slugify(alphabet),
'DJ-dj'
)

t.equal(slugify(alphabet, {locale: 'vi'}),
'D-d'
)
})
})
Loading