From 556ed5e701efd3dd3e2228492eade7769e43b8f4 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Wed, 8 Jul 2020 19:19:06 +0100 Subject: [PATCH] Add docs, types and credit for separateApostrophes --- README.md | 7 ++++++- index.d.ts | 1 + lib/limax.js | 10 ++++------ package.json | 3 ++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d3d28e8..9ed6125 100644 --- a/README.md +++ b/README.md @@ -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 ' }` @@ -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 @@ -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. diff --git a/index.d.ts b/index.d.ts index aa00e6b..e9d5957 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,6 +5,7 @@ type Options = { replacement?: string; separator?: string; separateNumbers?: boolean; + separateApostrophes?: boolean; tone?: boolean; } | string; diff --git a/lib/limax.js b/lib/limax.js index 81ac4bb..fdeceff 100644 --- a/lib/limax.js +++ b/lib/limax.js @@ -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) { diff --git a/package.json b/package.json index 4099e2a..a1d7aac 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "Daryl Chan ", "Arjan Frans ", "Fabrice Labbe ", - "Lukas Spieß " + "Lukas Spieß ", + "David Dijan " ], "license": "Apache-2.0", "dependencies": {