21
common/resources/client/utils/string/slugify-string.ts
Executable file
21
common/resources/client/utils/string/slugify-string.ts
Executable file
@@ -0,0 +1,21 @@
|
||||
import slugify from 'slugify';
|
||||
|
||||
export function slugifyString(
|
||||
text: string,
|
||||
replacement = '-',
|
||||
strict = false,
|
||||
): string {
|
||||
if (!text) return text;
|
||||
let slugified = slugify(text, {
|
||||
lower: true,
|
||||
replacement,
|
||||
strict,
|
||||
remove: /[*+~.()'"!:@?\|/\\#]/g,
|
||||
});
|
||||
// some chinese text might not get slugified properly,
|
||||
// just replace whitespace with dash in that case
|
||||
if (!slugified) {
|
||||
slugified = text.replace(/\s+/g, '-').toLowerCase();
|
||||
}
|
||||
return slugified;
|
||||
}
|
||||
Reference in New Issue
Block a user