Skip to content

Commit

Permalink
Add docs, types and credit for separateApostrophes
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Jul 8, 2020
1 parent a3696aa commit 556ed5e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ options:
* `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 `false`
* `separateApostrophes`: Boolean, separate apostrophes 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 @@ -70,6 +71,10 @@ const wuYin = slug('弄堂里的菜品赤醬', {tone: false}); // nong-tang-li-d
const numbersInWord = slug('hello2world'); // hello2world
const numbersSeparated = slug('hello2world', { separateNumbers: true }); // hello-2-world

// separateApostrophes example
const apostrophesInWord = slug('j\'aime'); // jaime
const apostrophesSeparated = slug('j\'aime', { separateApostrophes: true }); // j-aime

// maintainCase example
const caseNotMaintained = slug('HelloWorld'); // helloworld
const caseMaintained = slug('HelloWorld', { maintainCase: true }); // HelloWorld
Expand Down Expand Up @@ -99,7 +104,7 @@ Pull requests with mappings and tests for further scripts and languages are more

## Licence

Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019 Lovell Fuller and contributors.
Copyright 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Lovell Fuller and contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type Options = {
replacement?: string;
separator?: string;
separateNumbers?: boolean;
separateApostrophes?: boolean;
tone?: boolean;
} | string;

Expand Down
10 changes: 4 additions & 6 deletions lib/limax.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ module.exports = function (text, opt) {
? { separator: opt }
: opt || {};

if (options.separateApostrophes === true) {
text = text.replace(/(\S)['\u2018\u2019\u201A\u201B\u2032\u2035\u0301](\S)/g, '$1 $2'); // eslint-disable-line no-misleading-character-class
} else {
// Remove apostrophes contained within a word
text = text.replace(/(\S)['\u2018\u2019\u201A\u201B\u2032\u2035\u0301](\S)/g, '$1$2'); // eslint-disable-line no-misleading-character-class
}
text = text.replace(
/(\S)['\u2018\u2019\u201A\u201B\u2032\u2035\u0301](\S)/g, // eslint-disable-line no-misleading-character-class
options.separateApostrophes === true ? '$1 $2' : '$1$2'
);

// Break out any numbers contained within a word
if (options.separateNumbers === true) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"Daryl Chan <[email protected]>",
"Arjan Frans <[email protected]>",
"Fabrice Labbe <[email protected]>",
"Lukas Spieß <[email protected]>"
"Lukas Spieß <[email protected]>",
"David Dijan <[email protected]>"
],
"license": "Apache-2.0",
"dependencies": {
Expand Down

0 comments on commit 556ed5e

Please sign in to comment.