summaryrefslogtreecommitdiff
path: root/src/core/utils/slug.js
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2023-03-01 09:18:52 +0000
committerIT Fixcomart <it@fixcomart.co.id>2023-03-01 09:18:52 +0000
commita7abbf4ddc70068620e9f44b74dc162ce2e16ee2 (patch)
tree74f66253717515d364ce74bd8275015c1f829cbc /src/core/utils/slug.js
parent90e1edab9b6a8ccc09a49fed3addbec2cbc4e4c3 (diff)
parenta1b9b647a6c4bda1f5db63879639d44543f9557e (diff)
Merged in refactor (pull request #1)
Refactor
Diffstat (limited to 'src/core/utils/slug.js')
-rw-r--r--src/core/utils/slug.js34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/core/utils/slug.js b/src/core/utils/slug.js
index 0a7d30fc..7010008a 100644
--- a/src/core/utils/slug.js
+++ b/src/core/utils/slug.js
@@ -1,25 +1,27 @@
-import toTitleCase from './toTitleCase';
+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 createSlug = (prefix, 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 prefix + filterSlugFromEmptyChar.join('-')
}
const getIdFromSlug = (slug) => {
- let id = slug.split('-');
- return id[id.length-1];
+ let id = slug.split('-')
+ return id[id.length - 1]
}
const getNameFromSlug = (slug) => {
- let name = slug.split('-');
- name.pop();
- return toTitleCase(name.join(' '));
+ let name = slug.split('-')
+ name.pop()
+ return toTitleCase(name.join(' '))
}
-export {
- createSlug,
- getIdFromSlug,
- getNameFromSlug
-}; \ No newline at end of file
+export { createSlug, getIdFromSlug, getNameFromSlug }