feat: strings

This commit is contained in:
TrèsAbhi committed 2025-05-25 15:18:22 -05:00
1 parent a2f1593a0e
commit 179ce62a55
17 files changed
+400 -35

No files matched your search

+1
View File
@@ -46,4 +46,5 @@ export * from './gallery';
export * from './metaSortTank';
export * from './popularTanks';
export * from './romanize';
export * from './slugify';
export * from './youtubers';
+16
View File
@@ -0,0 +1,16 @@
import { deburr } from 'lodash-es';
const nonAlphanumericRegex = /[^a-z0-9]/g;
const multipleDashesRegex = /--+/g;
const trailingDashRegex = /-$/g;
const leadingDashRegex = /^-/g;
export function slugify(name: string) {
let slug = deburr(name).toLowerCase();
slug = slug.replaceAll(nonAlphanumericRegex, '-');
slug = slug.replaceAll(multipleDashesRegex, '-');
slug = slug.replaceAll(trailingDashRegex, '');
slug = slug.replaceAll(leadingDashRegex, '');
return slug;
}