Files
web/packages/design-system/generate/utils.ts
Rasmus Langvad d0546926a9 Merged in fix/3697-prettier-configs (pull request #3396)
fix(SW-3691): Setup one prettier config for whole repo

* Setup prettierrc in root and remove other configs


Approved-by: Joakim Jäderberg
Approved-by: Linus Flood
2026-01-07 12:45:50 +00:00

48 lines
1.4 KiB
TypeScript

export function kebabify(str: string) {
return str.replace(/\/|\s/g, "-").replace(/\(|\)|\[|\]/g, "")
}
export function ignoreStyles(mode: { name: string }) {
if (mode.name === "Style") {
// Ignore Figma Styles, we only want to process variables.
// But the exported variables.json includes Figma Styles too.
return false
}
return true
}
// Some tokens are the same for all themes. Group them into this theme.
export const FALLBACK_THEME = "base"
// The variables exported from Figma are not grouped by theme.
// We used this function to help us group by theme.
// Returns the theme the given token belongs to by matching theme names inside
// the token name.
export function getThemeForToken(
token: string | { name: string },
mode: { name: string },
themes: Map<string, unknown>
) {
// If the given value is an object and has a name property, use that as comparison value.
const compare = typeof token === "string" ? token : token.name
const theme = Array.from(themes.keys()).find((theme) => {
// Match against "theme/", use that if it matches
if (compare.indexOf(theme + "/") >= 0) {
return theme
}
// Match against mode, use that if it matches
if (mode.name === theme) {
return theme
}
})
// If a theme was found, use that
if (theme) {
return theme
}
// If no theme was found, return the fallback
return FALLBACK_THEME
}