Skip to content

Commit

Permalink
feat: add dynamic calc for token type
Browse files Browse the repository at this point in the history
  • Loading branch information
yarastqt committed Apr 21, 2020
1 parent 4be9cce commit 30c9ddc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/core/flat-tokens.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { withPrefix } from './with-prefix'
import { Shape, FlattenToken, Token, TokensMap } from './token.h'

function getTokenType(value: string): Token['type'] {
// TODO: Order is necessary, cuz color maybe has percent.
if (value.match(/#|rgb|hsl/) !== null) {
return 'color'
}
if (value.match(/px|%|em|rem/) !== null) {
return 'size'
}
return 'unknown'
}

/**
* Returns flatten shape with tokens.
*
Expand All @@ -14,7 +25,7 @@ export function flatTokens(tokens: TokensMap, __prefix__?: string): Shape<Flatte
if (typeof maybeToken === 'string') {
result[transformedKey] = {
value: maybeToken,
type: 'unknown',
type: getTokenType(maybeToken),
name: transformedKey,
}
}
Expand Down

0 comments on commit 30c9ddc

Please sign in to comment.