Skip to content

Commit

Permalink
fix(strings): update slugifyGH() replacements (#174)
Browse files Browse the repository at this point in the history
- hard to find definitive info about GH's slugify rules
- new rules based on more manual experiments and
  studying of unicode charts
- likely not a watertight solution, but should fix most issues
  of prev impl
  • Loading branch information
postspectacular committed Jan 1, 2021
1 parent 12b1bef commit 98a9135
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/strings/src/slugify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,24 @@ export const slugify: Stringer<string> = (str: string) => {
* @example
* ```ts
* slugifyGH("Me, myself (& ëye)!")
* // "me--myself--eye"
* // "me-myself--ëye"
* ```
*
* @param str
*/
export const slugifyGH = (str: string) => {
return str
.toLowerCase()
.replace(/\s/g, "-")
.replace(re, (c) => dest[src.indexOf(c)])
.replace(/[^\w\-]+/g, "")
.replace(/(^-+)|(-+$)/g, "");
return (
str
.toLowerCase()
// remove all punctuations:
// - ascii
// - https://www.unicode.org/charts/PDF/U2000.pdf (general)
// - https://www.unicode.org/charts/PDF/U2700.pdf (dingbats)
// - https://www.unicode.org/charts/PDF/U2E00.pdf (supplemental)
.replace(
/[!"#$%&'()*+,./:;<=>?@\[\\\]^`{|}~\u0000-\u001f\u2000-\u206f\u2700-\u27bf\u2e00-\u2e7f]/g,
""
)
.replace(/\s/g, "-")
);
};

0 comments on commit 98a9135

Please sign in to comment.