Skip to content

Commit

Permalink
The separateNumbers option now defaults to false #24
Browse files Browse the repository at this point in the history
Breaking API change, requires major version bump
  • Loading branch information
lovell committed Sep 27, 2019
1 parent 3f5f3b5 commit 3ad7480
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ options:
* `separator`: String, equivalent to `replacement` (provides API compatibility with the `speakingurl` module)
* `lang`: String, ISO 639-1 two-letter language code, defaults to auto-detected language
* `tone`: Boolean, add tone numbers to Pinyin transliteration of Chinese, defaults to `true`
* `separateNumbers`: Boolean, separate numbers that are within a word, defaults to `true`
* `separateNumbers`: Boolean, separate numbers that are within a word, defaults to `false`
* `maintainCase`: Boolean, maintain the original string's casing, defaults to `false`
* `custom`:
- Object, custom map for translation, overwrites all i.e. `{ '&': '#', '*': ' star ' }`
Expand All @@ -67,12 +67,12 @@ const unterstreichen2 = slug('Ich ♥ Deutsch', {lang: 'de', separator: '_'}); /
const wuYin = slug('弄堂里的菜品赤醬', {tone: false}); // nong-tang-li-di-cai-pin-chi-jiang

// separateNumbers example
const numbersInWord = slug('hello2world', {separateNumbers: false}); // hello2world
const numbersSeparated = slug('hello2world'); // hello-2-world
const numbersInWord = slug('hello2world'); // hello2world
const numbersSeparated = slug('hello2world', { separateNumbers: true }); // hello-2-world

// maintainCase example
const caseNotMaintained = slug('Hello2World'); // hello-2-world
const caseMaintained = slug('Hello2World', { maintainCase: true }); // Hello-2-World
const caseNotMaintained = slug('HelloWorld'); // helloworld
const caseMaintained = slug('HelloWorld', { maintainCase: true }); // HelloWorld

// custom example
const custom1 = slug('hello.world', { custom: ['.'] }); // hello.world
Expand Down
2 changes: 1 addition & 1 deletion lib/limax.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function (text, opt) {
text = text.replace(/(\S)['\u2018\u2019\u201A\u201B\u2032\u2035\u0301](\S)/g, '$1$2'); // eslint-disable-line no-misleading-character-class

// Break out any numbers contained within a word
if (options.separateNumbers !== false) {
if (options.separateNumbers === true) {
text = text.replace(/([^\d\s])([0-9]+)([^\d\s])/g, '$1 $2 $3');
}

Expand Down
6 changes: 3 additions & 3 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const tests = {
'Я люблю русский': 'ya-lyublyu-russkii',
'私は ひらがな が大好き': 'ha-hiragana-gaki',
我爱官话: 'wo3-ai4-guan1-hua4',
one2three: 'one-2-three',
one2three: 'one2three',
'The User\'s Guide': 'the-users-guide',
'The User’s Guide': 'the-users-guide',
弄堂里的菜品赤醬: 'nong4-tang2-li3-de-cai4-pin3-chi4-jiang4',
Expand Down Expand Up @@ -97,10 +97,10 @@ ava('Set separateNumbers via options', function (t) {
ava('Set maintainCase via options', function (t) {
t.plan(2);
t.true(
limax('Hello2World', { maintainCase: false }) === 'hello-2-world'
limax('HelloWorld', { maintainCase: false }) === 'helloworld'
);
t.true(
limax('Hello2World', { maintainCase: true }) === 'Hello-2-World'
limax('HelloWorld', { maintainCase: true }) === 'HelloWorld'
);
});

Expand Down

0 comments on commit 3ad7480

Please sign in to comment.