aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/examples/with-changesets/packages/acme-utils/src/toSlug.ts
diff options
context:
space:
mode:
Diffstat (limited to 'examples/with-changesets/packages/acme-utils/src/toSlug.ts')
-rw-r--r--examples/with-changesets/packages/acme-utils/src/toSlug.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/examples/with-changesets/packages/acme-utils/src/toSlug.ts b/examples/with-changesets/packages/acme-utils/src/toSlug.ts
new file mode 100644
index 0000000..6aec61c
--- /dev/null
+++ b/examples/with-changesets/packages/acme-utils/src/toSlug.ts
@@ -0,0 +1,18 @@
+/**
+ * Return a slugified copy of a string.
+ *
+ * @param {string} str The string to be slugified
+ * @return {string} The slugified string.
+ */
+export function toSlug(str: string): string {
+ let s = str;
+ if (!s) {
+ return "";
+ }
+ s = s.toLowerCase().trim();
+ s = s.replace(/ & /g, " and ");
+ s = s.replace(/[ ]+/g, "-");
+ s = s.replace(/[-]+/g, "-");
+ s = s.replace(/[^a-z0-9-]+/g, "");
+ return s;
+}