@tfk-samf/figma-to-dtcg
Advanced tools
Comparing version 0.3.8 to 0.4.0
@@ -32,4 +32,5 @@ import { RGB, LocalVariable, GetLocalVariablesResponse } from '@figma/rest-api-spec'; | ||
}; | ||
export type Options = { | ||
export type Options<Collection> = { | ||
verbosity?: 'silent' | 'verbose'; | ||
typeMap?: Record<FigmaTokenType, (category: Collection) => string>; | ||
}; | ||
@@ -92,5 +93,5 @@ export type DesignTokenType = 'color' | 'number' | 'fontFamily' | 'boolean'; | ||
*/ | ||
declare function useFigmaToDTCG<Themes extends string = any, Variants extends string = any, SharedCollections extends string = any, InvariantCollections extends string = any, VariantCollections extends string = any>(props: RestAPIProps | PluginAPIProps, options?: Options): Promise<{ | ||
declare function useFigmaToDTCG<Themes extends string = any, Variants extends string = any, SharedCollections extends string = any, InvariantCollections extends string = any, VariantCollections extends string = any>(props: RestAPIProps | PluginAPIProps, options?: Options<SharedCollections | InvariantCollections | VariantCollections>): Promise<{ | ||
tokens: Tokens<Themes, Variants, SharedCollections, InvariantCollections, VariantCollections>; | ||
}>; | ||
export { useFigmaToDTCG }; |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const figmaDesignTokenTypeMap = { | ||
COLOR: 'color', | ||
FLOAT: 'number', | ||
STRING: 'fontFamily', | ||
BOOLEAN: 'boolean', | ||
let globalOptions; | ||
const defaultOptions = { | ||
verbosity: 'silent', | ||
typeMap: { | ||
COLOR: () => 'color', | ||
FLOAT: () => 'number', | ||
STRING: () => 'fontFamily', | ||
BOOLEAN: () => 'boolean', | ||
}, | ||
}; | ||
let globalOptions = {}; | ||
const isVerbose = () => globalOptions.verbosity === 'verbose'; | ||
@@ -175,3 +178,3 @@ let getVariableById; | ||
obj.value = objValue; | ||
obj.type = figmaDesignTokenTypeMap[resolvedType]; | ||
obj.type = globalOptions.typeMap[resolvedType](sanitizeName(collectionName)); | ||
obj.prefix = collectionPrefix; | ||
@@ -213,4 +216,7 @@ } | ||
*/ | ||
async function useFigmaToDTCG(props, options = { verbosity: 'silent' }) { | ||
globalOptions = options; | ||
async function useFigmaToDTCG(props, options) { | ||
globalOptions = { | ||
...defaultOptions, | ||
...options, | ||
}; | ||
const isRestApiEnv = (p) => p.api === 'rest'; | ||
@@ -217,0 +223,0 @@ getVariableById = isRestApiEnv(props) |
{ | ||
"name": "@tfk-samf/figma-to-dtcg", | ||
"version": "0.3.8", | ||
"version": "0.4.0", | ||
"description": "Parse Figma Variables Plugin API and REST API into design tokens.", | ||
@@ -35,3 +35,3 @@ "files": [ | ||
}, | ||
"gitHead": "b50bedaad4e5b8e6c10c2a3550ed8491f832ed06" | ||
"gitHead": "1742bde862d47482df3a0ce8c7a826c5d8ea6f28" | ||
} |
16908
340