summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/slug.js13
-rw-r--r--src/helpers/toTitleCase.js8
2 files changed, 19 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
diff --git a/src/helpers/toTitleCase.js b/src/helpers/toTitleCase.js
new file mode 100644
index 00000000..5cfd70d0
--- /dev/null
+++ b/src/helpers/toTitleCase.js
@@ -0,0 +1,8 @@
+export default function toTitleCase(str) {
+ return str.replace(
+ /\w\S*/g,
+ function(txt) {
+ return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
+ }
+ );
+} \ No newline at end of file