UNPKG

@veracity/vui

Version:

Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.

23 lines (22 loc) 753 B
//#region src/utils/string.ts /** * Normalizes a string to be used as an identifier * - Converts to lowercase * - Replaces spaces and special characters with hyphens * - Removes consecutive hyphens * - Trims leading/trailing hyphens */ const normalizeToId = (str) => { return str.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-+|-+$/g, ""); }; /** * Generates a menu item ID from title and level */ const generateMenuItemId = (title, level = 0) => { const normalizedTitle = normalizeToId(title); return normalizedTitle ? `${normalizedTitle}-${level}` : `item-${level}`; }; //#endregion export { generateMenuItemId, normalizeToId }; globalThis.__vuiVersion__ = "5.3.1" //# sourceMappingURL=string.js.map