summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorRafi Zadanly <rafizadanly@gmail.com>2022-12-01 16:26:21 +0700
committerRafi Zadanly <rafizadanly@gmail.com>2022-12-01 16:26:21 +0700
commit0a0c497204acbac562700d80f38e74aa9ffcd94e (patch)
tree3c2387091b0733d33754fbc07d843f2deef2fa9e /src/helpers
parent9e1321f7e35a58ba8ce136401a217d835aef15f0 (diff)
dynamic filter, dynamic pagination, detail brand, to title case
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