summaryrefslogtreecommitdiff
path: root/src/helpers/slug.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers/slug.js')
-rw-r--r--src/helpers/slug.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/helpers/slug.js b/src/helpers/slug.js
index ed1a5b6a..b1e67cdf 100644
--- a/src/helpers/slug.js
+++ b/src/helpers/slug.js
@@ -1,13 +1,22 @@
+import toTitleCase from './toTitleCase';
+
const createSlug = (name, id) => {
return name?.trim().replace(new RegExp(/[^A-Za-z0-9]/, 'g'), '-').toLowerCase() + '-' + id;
}
-const getId = (slug) => {
+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,
- getId
+ getIdFromSlug,
+ getNameFromSlug
}; \ No newline at end of file