Skip to content

Commit

Permalink
feat: support simple token
Browse files Browse the repository at this point in the history
  • Loading branch information
yarastqt committed Apr 21, 2020
1 parent 3e397d9 commit dc76a6d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/core/flat-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ export function flatTokens(tokens: TokensMap, __prefix__?: string): Shape<Flatte
for (const key in tokens) {
const transformedKey = withPrefix(key, __prefix__)
const maybeToken = tokens[key]
if (maybeToken.value === undefined) {
if (typeof maybeToken === 'string') {
result[transformedKey] = {
value: maybeToken,
type: 'unknown',
name: transformedKey,
}
}
else if (maybeToken.value === undefined) {
Object.assign(result, flatTokens(maybeToken as TokensMap, transformedKey))
} else {
result[transformedKey] = {
Expand Down
4 changes: 2 additions & 2 deletions src/core/token.h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export type Shape<T> = { [key: string]: T }

export type Token = {
value: string | number
type: 'color' | 'size'
type: 'color' | 'size' | 'unknown'
comment?: string
}

Expand All @@ -11,5 +11,5 @@ export type FlattenToken = Token & {
}

export type TokensMap = {
[key: string]: Token | TokensMap
[key: string]: TokensMap | Token | string
}

0 comments on commit dc76a6d

Please sign in to comment.