From ae17973618c5ad5500ae69738da222187a09b019 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 21 Dec 2021 15:05:04 +0100 Subject: chore: add a hook to build headings tree --- src/utils/helpers/slugify.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/utils/helpers/slugify.ts (limited to 'src/utils/helpers') diff --git a/src/utils/helpers/slugify.ts b/src/utils/helpers/slugify.ts new file mode 100644 index 0000000..37619bc --- /dev/null +++ b/src/utils/helpers/slugify.ts @@ -0,0 +1,18 @@ +/** + * Convert a text into a slug or id. + * https://gist.github.com/codeguy/6684588#gistcomment-3332719 + * + * @param {string} text Text to slugify. + */ +export const slugify = (text: string) => { + return text + .toString() + .normalize('NFD') + .replace(/[\u0300-\u036f]/g, '') + .toLowerCase() + .trim() + .replace(/\s+/g, '-') + .replace(/[^\w\-]+/g, '-') + .replace(/\-\-+/g, '-') + .replace(/^-|-$/g, ''); +}; -- cgit v1.2.3