Skip to content

Commit

Permalink
strip quotation marks & apostrophe (#4)
Browse files Browse the repository at this point in the history
Resolves #3
  • Loading branch information
cometkim authored Dec 2, 2021
1 parent e55c4c0 commit 4f6e3f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ const cjkSlug: CjkSlug = (
} = {},
) => {
let slug = normalize(title)
// strip quotation marks
// - 0022: quotation mark (")
// - 0027: apostrophe (')
// - ff07: full-width apostrophe
// - 02bc: modifier letter apostrophe
// - 0060: grave accent
// - 00b4: acute accent
// - 2018: left single quotation mark
// - 2019: right single quotation mark
// - 201c: left double quotation mark
// - 201d: right double quotation mark
.replace(/[\u0022\u0027\uff07\u02bc\u0060\u00b4\u2018\u2019\u201c\u201d]/g, '')
// replace all whitespaces with a dash
.replace(/[\s_]+/g, '-')
// replace non-allowed sequences with a dash
Expand Down
5 changes: 4 additions & 1 deletion test/cjkSlug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ const cases: Array<[input: string, output: string]> = [
['당근마켓 - 대한민국 1등 동네 커뮤니티', '당근마켓-대한민국-1등-동네-커뮤니티'],
['PM/기획', 'pm-기획'],
['개발 (iOS / 안드로이드)', '개발-ios-안드로이드'],
['자바스크립트도 \"당근\"이세요?', '자바스크립트도-당근이세요'],
['ホロライブプロダクション Hororaibu Purodakushon', 'ホロライブプロダクション-hororaibu-purodakushon'],
['Parse, don’t validate', 'parse-don-t-validate'],
['------title------', 'title'],
['Parse, don’t validate', 'parse-dont-validate'],
['Alexis King said "Parse, don\'t validate"', 'alexis-king-said-parse-dont-validate'],
['Someone shout "help, help!", but no one care', 'someone-shout-help-help-but-no-one-care'],
];

for (const [input, output] of cases) {
Expand Down

0 comments on commit 4f6e3f3

Please sign in to comment.