From 12c85abc5b89c0423e83f6ab3415e755257938b6 Mon Sep 17 00:00:00 2001 From: Eugene Date: Sat, 9 May 2020 03:55:30 +0300 Subject: [PATCH] fix: cast token to string --- src/core/flat-tokens.ts | 12 ++++++------ src/core/types.ts | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/core/flat-tokens.ts b/src/core/flat-tokens.ts index 7f578d0..54f03c1 100644 --- a/src/core/flat-tokens.ts +++ b/src/core/flat-tokens.ts @@ -1,18 +1,18 @@ import { withPrefix } from './with-prefix' -import { Shape, FlattenToken, Token, TokensMap } from './types' +import { Shape, FlattenToken, Token, TokensMap, TokenType } from './types' -function getTokenType(value: string): Token['type'] { +function getTokenType(value: string | number): TokenType { // TODO: Order is necessary, cuz color maybe has percent. - if (value.match(/#|rgb|hsl/) !== null) { + if (value.toString().match(/#|rgb|hsl/) !== null) { return 'color' } - if (value.match(/px|%|em|rem/) !== null) { + if (value.toString().match(/px|%|em|rem/) !== null) { return 'size' } return 'unknown' } -function isTokensMap(token: Token | TokensMap): token is TokensMap { +function isTokensMap(token: TokensMap | Token): token is TokensMap { return token.value === undefined } @@ -26,7 +26,7 @@ export function flatTokens(tokens: TokensMap, prefix?: string): Shape = { export type Primitive = string | number +export type TokenType = 'color' | 'size' | 'unknown' + export type Token = { value: Primitive - type: 'color' | 'size' | 'unknown' + type: TokenType comment?: string }