blob: b1e67cdf03ac9cd354ea2e022e3f6f66fc957714 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import toTitleCase from './toTitleCase';
const createSlug = (name, id) => {
return name?.trim().replace(new RegExp(/[^A-Za-z0-9]/, 'g'), '-').toLowerCase() + '-' + id;
}
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
};
|