diff --git a/index.ts b/index.ts deleted file mode 100644 index 429f3c9..0000000 --- a/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import tokens from "./src"; - -export {tokens}; diff --git a/package.json b/package.json index 061e908..e5fc1ec 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@zerogachis/smartway-design-token", "version": "0.0.1", "description": "Smartway design tokens", - "main": "tokens.json", + "main": "src/index.ts", "scripts": { "type:check": "tsc", "tsc": "tsc --project tsconfig.build.json" diff --git a/src/Tokens.ts b/src/Tokens.ts index b06967d..226a568 100644 --- a/src/Tokens.ts +++ b/src/Tokens.ts @@ -1,169 +1,169 @@ import * as tokensJson from "../tokens.json"; import { - BoxShadows, - BoxShadow, - Font, - Fonts, - Typography, - FontSize, - FontWeight, - FontFamily, - Spacings, - BorderRadius, - LineHeight, - Color, + BoxShadows, + BoxShadow, + Font, + Fonts, + Typography, + FontSize, + FontWeight, + FontFamily, + Spacings, + BorderRadius, + LineHeight, + Color, } from "./TokensType"; const parseShadow = (value: any): BoxShadow | void => { - if (typeof value !== "string") - return { - color: value.color, - type: value.type, - x: value.x, - y: value.y, - blur: value.blur, - spread: value.spread, - }; + if (typeof value !== "string") + return { + color: value.color, + type: value.type, + x: value.x, + y: value.y, + blur: value.blur, + spread: value.spread, + }; }; const parseAliasShadow = - (shadow: BoxShadows) => - (value: any): BoxShadow | void => { - if (typeof value === "string") { - const key = value.replace(/\D/g, ""); - return shadow[key as keyof BoxShadows]; - } - }; + (shadow: BoxShadows) => + (value: any): BoxShadow | void => { + if (typeof value === "string") { + const key = value.replace(/\D/g, ""); + return shadow[key as keyof BoxShadows]; + } + }; const parseTypography = - (font: Fonts) => - (value: any): Font => { - return { - fontWeight: - font.fontWeight[ - value["fontWeight"] - .replace("}", "") - .split(".") - .slice(-1)[0] as keyof FontWeight - ], - fontSize: - font.fontSize[ - value["fontSize"] - .replace("}", "") - .split(".") - .slice(-1)[0] as keyof FontSize - ], - fontFamily: - font.fontFamily[ - value["fontFamily"] - .replace("{", "") - .replace("}", "") as keyof FontFamily - ], - }; - }; + (font: Fonts) => + (value: any): Font => { + return { + fontWeight: + font.fontWeight[ + value["fontWeight"] + .replace("}", "") + .split(".") + .slice(-1)[0] as keyof FontWeight + ], + fontSize: + font.fontSize[ + value["fontSize"] + .replace("}", "") + .split(".") + .slice(-1)[0] as keyof FontSize + ], + fontFamily: + font.fontFamily[ + value["fontFamily"] + .replace("{", "") + .replace("}", "") as keyof FontFamily + ], + }; + }; const parseString = (value: string) => value; const getValueToken = ( - tokenValue: any, - parseMethod: (value: any) => R + tokenValue: any, + parseMethod: (value: any) => R ): T => { - let values = {}; - const value = tokenValue; - Object.keys(value).forEach((key) => { - const parsedValue = parseMethod(value[key].value); - if (parsedValue) { - (values as Record)[key] = parsedValue; - } - }); - return values as T; + let values = {}; + const value = tokenValue; + Object.keys(value).forEach((key) => { + const parsedValue = parseMethod(value[key].value); + if (parsedValue) { + (values as Record)[key] = parsedValue; + } + }); + return values as T; }; const getTokens = () => { - const shadows = getValueToken( - tokensJson.global.shadow, - parseShadow - ); - const fontSize = getValueToken( - tokensJson.global["font-size"], - parseInt - ); - const fontWeight = getValueToken( - tokensJson.global["font-weight"], - parseInt - ); - const fontFamily: FontFamily = { - "public-sans": "Public Sans", - "noto-sans": "Noto Sans", - }; - const font: Fonts = { fontWeight, fontSize, fontFamily }; - - return { - spacing: getValueToken( - tokensJson.global.spacing, - parseInt - ), - boxShadow: { - ...shadows, - ...getValueToken( + const shadows = getValueToken( tokensJson.global.shadow, - parseAliasShadow(shadows) - ), - }, - borderRadius: getValueToken( - tokensJson.global["border-radius"], - parseInt - ), - fontWeight: fontWeight, - lineHeight: getValueToken( - tokensJson.global["line-height"], - parseString - ), - color: { - primary: getValueToken( - tokensJson.global.primary, - parseString - ), - secondary: getValueToken( - tokensJson.global.secondary, - parseString - ), - info: getValueToken(tokensJson.global.info, parseString), - success: getValueToken( - tokensJson.global.success, - parseString - ), - warning: getValueToken( - tokensJson.global.warning, - parseString - ), - error: getValueToken(tokensJson.global.error, parseString), - neutral: getValueToken( - tokensJson.global.neutral, - parseString - ), - }, - fontSize: fontSize, - fontFamily: fontFamily, - typography: { - headline: getValueToken( - tokensJson.global.headline, - parseTypography(font) - ), - body: getValueToken( - tokensJson.global.body, - parseTypography(font) - ), - label: getValueToken( - tokensJson.global.label, - parseTypography(font) - ), - button: getValueToken( - tokensJson.global.button, - parseTypography(font) - ), - }, - }; + parseShadow + ); + const fontSize = getValueToken( + tokensJson.global["font-size"], + parseInt + ); + const fontWeight = getValueToken( + tokensJson.global["font-weight"], + parseInt + ); + const fontFamily: FontFamily = { + "public-sans": "Public Sans", + "noto-sans": "Noto Sans", + }; + const font: Fonts = {fontWeight, fontSize, fontFamily}; + + return { + spacing: getValueToken( + tokensJson.global.spacing, + parseInt + ), + boxShadow: { + ...shadows, + ...getValueToken( + tokensJson.global.shadow, + parseAliasShadow(shadows) + ), + }, + borderRadius: getValueToken( + tokensJson.global["border-radius"], + parseInt + ), + fontWeight: fontWeight, + lineHeight: getValueToken( + tokensJson.global["line-height"], + parseString + ), + color: { + primary: getValueToken( + tokensJson.global.primary, + parseString + ), + secondary: getValueToken( + tokensJson.global.secondary, + parseString + ), + info: getValueToken(tokensJson.global.info, parseString), + success: getValueToken( + tokensJson.global.success, + parseString + ), + warning: getValueToken( + tokensJson.global.warning, + parseString + ), + error: getValueToken(tokensJson.global.error, parseString), + neutral: getValueToken( + tokensJson.global.neutral, + parseString + ), + }, + fontSize: fontSize, + fontFamily: fontFamily, + typography: { + headline: getValueToken( + tokensJson.global.headline, + parseTypography(font) + ), + body: getValueToken( + tokensJson.global.body, + parseTypography(font) + ), + label: getValueToken( + tokensJson.global.label, + parseTypography(font) + ), + button: getValueToken( + tokensJson.global.button, + parseTypography(font) + ), + }, + }; }; const tokens = getTokens();