summaryrefslogtreecommitdiff
path: root/src2/core/utils/slug.js
diff options
context:
space:
mode:
Diffstat (limited to 'src2/core/utils/slug.js')
-rw-r--r--src2/core/utils/slug.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/src2/core/utils/slug.js b/src2/core/utils/slug.js
new file mode 100644
index 00000000..0a7d30fc
--- /dev/null
+++ b/src2/core/utils/slug.js
@@ -0,0 +1,25 @@
+import toTitleCase from './toTitleCase';
+
+const createSlug = (name, id) => {
+ let slug = name?.trim().replace(new RegExp(/[^A-Za-z0-9]/, 'g'), '-').toLowerCase() + '-' + id;
+ let splitSlug = slug.split('-');
+ let filterSlugFromEmptyChar = splitSlug.filter(x => x != '');
+ return filterSlugFromEmptyChar.join('-');
+}
+
+const getIdFromSlug = (slug) => {
+ let id = slug.split('-');
+ return id[id.length-1];
+}
+
+const getNameFromSlug = (slug) => {
+ let name = slug.split('-');
+ name.pop();
+ return toTitleCase(name.join(' '));
+}
+
+export {
+ createSlug,
+ getIdFromSlug,
+ getNameFromSlug
+}; \ No newline at end of file