Skip to content

Commit d736833

Browse files
authored
feat: generate slug from text
1 parent d2bb5ce commit d736833

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# ServiceNow JavaScript Helper
2+
3+
## String Helper
4+
5+
- `toSlug("Hello World!")``"hello-world"`
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Converts string to lowercase, removes symbols, replaces spaces with dashes
2+
function toSlug(text) {
3+
let str = text.toLowerCase();
4+
str = str.replace(/[^a-z0-9_\s-]/g, "");
5+
str = str.replace(/[\s-]+/g, " ");
6+
str = str.replace(/[\s_]/g, "-");
7+
return str;
8+
};

0 commit comments

Comments
 (0)