0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-24 18:07:17 +01:00
posthog/playwright/helpers/storybook.ts

13 lines
476 B
TypeScript

// Remove punctuation and illegal characters
const sanitize = (string: string): string => {
return string
.toLowerCase()
.replace(/[ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '-')
.replace(/-+/g, '-')
.replace(/^-+/, '')
.replace(/-+$/, '')
}
// Generate a story id from a story kind and name
export const toId = (kind: string, name?: string): string => `${sanitize(kind)}${name ? `--${sanitize(name)}` : ''}`