TokenState
The TokenState class API reference
The TokenState is accessible via the SDTFEngine API over methods like: getTokenState
, getAllTokenStates…
The TokenState host all the methods to work with the token value, read, update, resolve aliases…
Properties
aliases
This getter returns the stateful alias references of the token.
get aliases: Array<StatefulAliasReference>;
type
This getter returns the type of the token.
get type: SpecifyDesignTokenTypeName;
value
This getter returns the SDTF JSON representation of the token value.
get value: SpecifyDesignToken['$value'];
modes
This getter returns the resolved modes of the token.
get modes: Array<string>;
isTopLevelAlias
This getter indicates whether the token is a top level alias.
get isTopLevelAlias: boolean;
isFullyResolvable
This getter indicates whether the token holds unresolvable aliases.
get isFullyResolvable: boolean;
modesResolvability
This getter returns a map representation of whether the token holds unresolvable aliases per mode.
get modesResolvability: Record<string, boolean>;
definition
This getter returns the design token definition - containing validation schemas of the token.
get definition: DesignTokenDefinition<Type>;
Methods
getCollection
This method returns the parent collection of the token if any.
getCollection(): import("./CollectionState.js").CollectionState | undefined;
getStatefulValueResult
This method returns a StatefulValueResult instance allowing to map over the token possible values for modes and aliases.
getStatefulValueResult(): StatefulValueResult<Type>;
resolveDeepStatefulValueForMode
This method resolves the stateful value for a given mode.
resolveDeepStatefulValueForMode<T extends SpecifyDesignTokenTypeName = Type>(mode: string): ResolvedDeepStatefulValueForMode<T>;
getUIValueResultOnMode
This method returns the Stateful Value representation for frontend usage.
getUIValueResultOnMode(targetMode: string): UIValueResultSignature<Type>;
rename
This method renames the token.
rename(newName: string): boolean;
renameMode
This method renames a mode of the token.
renameMode(fromMode: string, toMode: string): void;
updateValue
This method updates the whole value of the token (including modes).
updateValue(nextValue: Partial<PickSpecifyDesignToken<Type, string, false, true>['$value']>, { allowModeCreation, overrideAliases }?: UpdateOptions): void;
updateModeValue
This method updates the value of a specific mode of the token.
updateModeValue(mode: string, nextValue: Partial<PickSpecifyDesignToken<Type, string, true, false>['$value']>, { overrideAliases, allowModeCreation }?: UpdateOptions): void;
resolveValueAliases
This method resolves the aliases from the token.
resolveValueAliases(): void;
createModeValue
This method creates a new mode for the token.
createModeValue(mode: string, nextValue: PickSpecifyDesignToken<Type, string, true, false>['$value']): void;
deleteModeValue
This method deletes a mode of the token.
deleteModeValue(mode: string): void;
getJSONValue
This method returns the JSON representation of the Token value.
getJSONValue<ResolveAliases extends boolean, AllowUnresolvable extends boolean = true, TargetMode extends Mode | null = null>(options?: GetJSONTokenValueOptions<ResolveAliases, AllowUnresolvable, TargetMode>): PickSpecifyDesignToken<Type, Mode, AllowUnresolvable extends true ? true : false, TargetMode extends string ? false : true>['$value'];
getJSONToken
This method returns the JSON representation of the Token.
getJSONToken<ResolveAliases extends boolean, AllowUnresolvable extends boolean = true, TargetMode extends Mode | null = null>(options?: GetJSONTokenValueOptions<ResolveAliases, AllowUnresolvable, TargetMode>): PickSpecifyDesignToken<Type, Mode, AllowUnresolvable extends true ? true : false, TargetMode extends string ? false : true>;
move
This method moves the item to the specified path.
move(toPath: Array<string>): void;
matchByType
This method matches the token by type.
matchByType<Return>(matcher: {
[K in SpecifyDesignTokenTypeName]?: (token: TokenState<K, Value, Mode>) => Return;
}, missingFn: (token: TokenState) => Return): Return;
matchJSONValueByType
This method matches the JSON value of the token by type.
matchJSONValueByType<MatchReturn, MissingReturn = undefined>(matcher: {
[K in Type]?: (token: PickSpecifyDesignToken<K, string, false, false>['$value'], mode: string) => MatchReturn;
}, missingFn: (token: TokenState) => MissingReturn): {
[mode: string]: MatchReturn;
} | MissingReturn | undefined;
toTokenStateParams
This method returns the token state parameters.
toTokenStateParams(): TokenStateParams;
toAnalyzedToken
This method returns the analyzed token.
toAnalyzedToken(): AnalyzedToken;
Matchers
isString
This method checks if the token state is of type 'string'.
isString(): this is TokenState<'string'>;
isNumber
This method checks if the token state is of type 'number'.
isNumber(): this is TokenState<'number'>;
isBoolean
This method checks if the token state is of type 'boolean'.
isBoolean(): this is TokenState<'boolean'>;
isNull
This method checks if the token state is of type 'null'.
isNull(): this is TokenState<'null'>;
isArray
This method checks if the token state is of type 'array'.
isArray(): this is TokenState<'array'>;
isObject
This method checks if the token state is of type 'object'.
isObject(): this is TokenState<'object'>;
isIntegerNumber
This method checks if the token state is of type 'integerNumber'.
isIntegerNumber(): this is TokenState<'integerNumber'>;
isZeroToOneNumber
This method checks if the token state is of type 'zeroToOneNumber'.
isZeroToOneNumber(): this is TokenState<'zeroToOneNumber'>;
isArcDegreeNumber
This method checks if the token state is of type 'arcDegreeNumber'.
isArcDegreeNumber(): this is TokenState<'arcDegreeNumber'>;
isRgbColorNumber
This method checks if the token state is of type 'rgbColorNumber'.
isRgbColorNumber(): this is TokenState<'rgbColorNumber'>;
isPositiveNumber
This method checks if the token state is of type 'positiveNumber'.
isPositiveNumber(): this is TokenState<'positiveNumber'>;
isPositiveIntegerNumber
This method checks if the token state is of type 'positiveIntegerNumber'.
isPositiveIntegerNumber(): this is TokenState<'positiveIntegerNumber'>;
isPercentageNumber
This method checks if the token state is of type 'percentageNumber'.
isPercentageNumber(): this is TokenState<'percentageNumber'>;
isHexadecimalColorString
This method checks if the token state is of type 'hexadecimalColorString'.
isHexadecimalColorString(): this is TokenState<'hexadecimalColorString'>;
isBitmap
This method checks if the token state is of type 'bitmap'.
isBitmap(): this is TokenState<'bitmap'>;
isBitmapFormat
This method checks if the token state is of type 'bitmapFormat'.
isBitmapFormat(): this is TokenState<'bitmapFormat'>;
isBlur
This method checks if the token state is of type 'blur'.
isBlur(): this is TokenState<'blur'>;
isBorder
This method checks if the token state is of type 'border'.
isBorder(): this is TokenState<'border'>;
isBorderStyle
This method checks if the token state is of type 'borderStyle'.
isBorderStyle(): this is TokenState<'borderStyle'>;
isBorderStyleLineCap
This method checks if the token state is of type 'borderStyleLineCap'.
isBorderStyleLineCap(): this is TokenState<'borderStyleLineCap'>;
isBreakpoint
This method checks if the token state is of type 'breakpoint'.
isBreakpoint(): this is TokenState<'breakpoint'>;
isColor
This method checks if the token state is of type 'color'.
isColor(): this is TokenState<'color'>;
isCubicBezier
This method checks if the token state is of type 'cubicBezier'.
isCubicBezier(): this is TokenState<'cubicBezier'>;
isDimension
This method checks if the token state is of type 'dimension'.
isDimension(): this is TokenState<'dimension'>;
isDimensionUnit
This method checks if the token state is of type 'dimensionUnit'.
isDimensionUnit(): this is TokenState<'dimensionUnit'>;
isDuration
This method checks if the token state is of type 'duration'.
isDuration(): this is TokenState<'duration'>;
isDurationUnit
This method checks if the token state is of type 'durationUnit'.
isDurationUnit(): this is TokenState<'durationUnit'>;
isFont
This method checks if the token state is of type 'font'.
isFont(): this is TokenState<'font'>;
isFontFamily
This method checks if the token state is of type 'fontFamily'.
isFontFamily(): this is TokenState<'fontFamily'>;
isFontFeature
This method checks if the token state is of type 'fontFeature'.
isFontFeature(): this is TokenState<'fontFeature'>;
isFontFeatures
This method checks if the token state is of type 'fontFeatures'.
isFontFeatures(): this is TokenState<'fontFeatures'>;
isFontFormat
This method checks if the token state is of type 'fontFormat'.
isFontFormat(): this is TokenState<'fontFormat'>;
isFontStyle
This method checks if the token state is of type 'fontStyle'.
isFontStyle(): this is TokenState<'fontStyle'>;
isFontWeight
This method checks if the token state is of type 'fontWeight'.
isFontWeight(): this is TokenState<'fontWeight'>;
isGradient
This method checks if the token state is of type 'gradient'.
isGradient(): this is TokenState<'gradient'>;
isGradients
This method checks if the token state is of type 'gradients'.
isGradients(): this is TokenState<'gradients'>;
isOpacity
This method checks if the token state is of type 'opacity'.
isOpacity(): this is TokenState<'opacity'>;
isRadius
This method checks if the token state is of type 'radius'.
isRadius(): this is TokenState<'radius'>;
isRadii
This method checks if the token state is of type 'radii'.
isRadii(): this is TokenState<'radii'>;
isShadow
This method checks if the token state is of type 'shadow'.
isShadow(): this is TokenState<'shadow'>;
isShadows
This method checks if the token state is of type 'shadows'.
isShadows(): this is TokenState<'shadows'>;
isShadowType
This method checks if the token state is of type 'shadowType'.
isShadowType(): this is TokenState<'shadowType'>;
isSpacing
This method checks if the token state is of type 'spacing'.
isSpacing(): this is TokenState<'spacing'>;
isSpacings
This method checks if the token state is of type 'spacings'.
isSpacings(): this is TokenState<'spacings'>;
isStepsTimingFunction
This method checks if the token state is of type 'stepsTimingFunction'.
isStepsTimingFunction(): this is TokenState<'stepsTimingFunction'>;
isTextAlignHorizontal
This method checks if the token state is of type 'textAlignHorizontal'.
isTextAlignHorizontal(): this is TokenState<'textAlignHorizontal'>;
isTextAlignVertical
This method checks if the token state is of type 'textAlignVertical'.
isTextAlignVertical(): this is TokenState<'textAlignVertical'>;
isTextDecoration
This method checks if the token state is of type 'textDecoration'.
isTextDecoration(): this is TokenState<'textDecoration'>;
isTextStyle
This method checks if the token state is of type 'textStyle'.
isTextStyle(): this is TokenState<'textStyle'>;
isTextTransform
This method checks if the token state is of type 'textTransform'.
isTextTransform(): this is TokenState<'textTransform'>;
isTransition
This method checks if the token state is of type 'transition'.
isTransition(): this is TokenState<'transition'>;
isVector
This method checks if the token state is of type 'vector'.
isVector(): this is TokenState<'vector'>;
isVectorFormat
This method checks if the token state is of type 'vectorFormat'.
isVectorFormat(): this is TokenState<'vectorFormat'>;
isZIndex
This method checks if the token state is of type 'zIndex'.
isZIndex(): this is TokenState<'zIndex'>;
Last updated
Was this helpful?