> For the complete documentation index, see [llms.txt](https://docs.specifyapp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.specifyapp.com/reference/sdtf-engine/tokenstate.md).

# TokenState

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.

```typescript
get aliases: Array<StatefulAliasReference>;
```

### type

This getter returns the type of the token.

```typescript
get type: SpecifyDesignTokenTypeName;
```

### value

This getter returns the SDTF JSON representation of the token value.

```typescript
get value: SpecifyDesignToken['$value'];
```

### modes

This getter returns the resolved modes of the token.

```typescript
get modes: Array<string>;
```

### isTopLevelAlias

This getter indicates whether the token is a top level alias.

```typescript
get isTopLevelAlias: boolean;
```

### isFullyResolvable

This getter indicates whether the token holds unresolvable aliases.

```typescript
get isFullyResolvable: boolean;
```

### modesResolvability

This getter returns a map representation of whether the token holds unresolvable aliases per mode.

```typescript
get modesResolvability: Record<string, boolean>;
```

### definition

This getter returns the design token definition - containing validation schemas of the token.

```typescript
get definition: DesignTokenDefinition<Type>;
```

## Methods

### getCollection

This method returns the parent collection of the token if any.

```typescript
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.

```typescript
getStatefulValueResult(): StatefulValueResult<Type>;
```

### resolveDeepStatefulValueForMode

This method resolves the stateful value for a given mode.

```typescript
resolveDeepStatefulValueForMode<T extends SpecifyDesignTokenTypeName = Type>(mode: string): ResolvedDeepStatefulValueForMode<T>;
```

### getUIValueResultOnMode

This method returns the Stateful Value representation for frontend usage.

```typescript
getUIValueResultOnMode(targetMode: string): UIValueResultSignature<Type>;
```

### rename

This method renames the token.

```typescript
rename(newName: string): boolean;
```

### renameMode

This method renames a mode of the token.

```typescript
renameMode(fromMode: string, toMode: string): void;
```

### updateValue

This method updates the whole value of the token (including modes).

```typescript
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.

```typescript
updateModeValue(mode: string, nextValue: Partial<PickSpecifyDesignToken<Type, string, true, false>['$value']>, { overrideAliases, allowModeCreation }?: UpdateOptions): void;
```

### resolveValueAliases

This method resolves the aliases from the token.

```typescript
resolveValueAliases(): void;
```

### createModeValue

This method creates a new mode for the token.

```typescript
createModeValue(mode: string, nextValue: PickSpecifyDesignToken<Type, string, true, false>['$value']): void;
```

### deleteModeValue

This method deletes a mode of the token.

```typescript
deleteModeValue(mode: string): void;
```

### getJSONValue

This method returns the JSON representation of the Token value.

```typescript
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.

```typescript
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.

```typescript
move(toPath: Array<string>): void;
```

### matchByType

This method matches the token by type.

```typescript
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.

```typescript
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.

```typescript
toTokenStateParams(): TokenStateParams;
```

### toAnalyzedToken

This method returns the analyzed token.

```typescript
toAnalyzedToken(): AnalyzedToken;
```

## Matchers

### isString

This method checks if the token state is of type 'string'.

```typescript
isString(): this is TokenState<'string'>;
```

### isNumber

This method checks if the token state is of type 'number'.

```typescript
isNumber(): this is TokenState<'number'>;
```

### isBoolean

This method checks if the token state is of type 'boolean'.

```typescript
isBoolean(): this is TokenState<'boolean'>;
```

### isNull

This method checks if the token state is of type 'null'.

```typescript
isNull(): this is TokenState<'null'>;
```

### isArray

This method checks if the token state is of type 'array'.

```typescript
isArray(): this is TokenState<'array'>;
```

### isObject

This method checks if the token state is of type 'object'.

```typescript
isObject(): this is TokenState<'object'>;
```

### isIntegerNumber

This method checks if the token state is of type 'integerNumber'.

```typescript
isIntegerNumber(): this is TokenState<'integerNumber'>;
```

### isZeroToOneNumber

This method checks if the token state is of type 'zeroToOneNumber'.

```typescript
isZeroToOneNumber(): this is TokenState<'zeroToOneNumber'>;
```

### isArcDegreeNumber

This method checks if the token state is of type 'arcDegreeNumber'.

```typescript
isArcDegreeNumber(): this is TokenState<'arcDegreeNumber'>;
```

### isRgbColorNumber

This method checks if the token state is of type 'rgbColorNumber'.

```typescript
isRgbColorNumber(): this is TokenState<'rgbColorNumber'>;
```

### isPositiveNumber

This method checks if the token state is of type 'positiveNumber'.

```typescript
isPositiveNumber(): this is TokenState<'positiveNumber'>;
```

### isPositiveIntegerNumber

This method checks if the token state is of type 'positiveIntegerNumber'.

```typescript
isPositiveIntegerNumber(): this is TokenState<'positiveIntegerNumber'>;
```

### isPercentageNumber

This method checks if the token state is of type 'percentageNumber'.

```typescript
isPercentageNumber(): this is TokenState<'percentageNumber'>;
```

### isHexadecimalColorString

This method checks if the token state is of type 'hexadecimalColorString'.

```typescript
isHexadecimalColorString(): this is TokenState<'hexadecimalColorString'>;
```

### isBitmap

This method checks if the token state is of type 'bitmap'.

```typescript
isBitmap(): this is TokenState<'bitmap'>;
```

### isBitmapFormat

This method checks if the token state is of type 'bitmapFormat'.

```typescript
isBitmapFormat(): this is TokenState<'bitmapFormat'>;
```

### isBlur

This method checks if the token state is of type 'blur'.

```typescript
isBlur(): this is TokenState<'blur'>;
```

### isBorder

This method checks if the token state is of type 'border'.

```typescript
isBorder(): this is TokenState<'border'>;
```

### isBorderStyle

This method checks if the token state is of type 'borderStyle'.

```typescript
isBorderStyle(): this is TokenState<'borderStyle'>;
```

### isBorderStyleLineCap

This method checks if the token state is of type 'borderStyleLineCap'.

```typescript
isBorderStyleLineCap(): this is TokenState<'borderStyleLineCap'>;
```

### isBreakpoint

This method checks if the token state is of type 'breakpoint'.

```typescript
isBreakpoint(): this is TokenState<'breakpoint'>;
```

### isColor

This method checks if the token state is of type 'color'.

```typescript
isColor(): this is TokenState<'color'>;
```

### isCubicBezier

This method checks if the token state is of type 'cubicBezier'.

```typescript
isCubicBezier(): this is TokenState<'cubicBezier'>;
```

### isDimension

This method checks if the token state is of type 'dimension'.

```typescript
isDimension(): this is TokenState<'dimension'>;
```

### isDimensionUnit

This method checks if the token state is of type 'dimensionUnit'.

```typescript
isDimensionUnit(): this is TokenState<'dimensionUnit'>;
```

### isDuration

This method checks if the token state is of type 'duration'.

```typescript
isDuration(): this is TokenState<'duration'>;
```

### isDurationUnit

This method checks if the token state is of type 'durationUnit'.

```typescript
isDurationUnit(): this is TokenState<'durationUnit'>;
```

### isFont

This method checks if the token state is of type 'font'.

```typescript
isFont(): this is TokenState<'font'>;
```

### isFontFamily

This method checks if the token state is of type 'fontFamily'.

```typescript
isFontFamily(): this is TokenState<'fontFamily'>;
```

### isFontFeature

This method checks if the token state is of type 'fontFeature'.

```typescript
isFontFeature(): this is TokenState<'fontFeature'>;
```

### isFontFeatures

This method checks if the token state is of type 'fontFeatures'.

```typescript
isFontFeatures(): this is TokenState<'fontFeatures'>;
```

### isFontFormat

This method checks if the token state is of type 'fontFormat'.

```typescript
isFontFormat(): this is TokenState<'fontFormat'>;
```

### isFontStyle

This method checks if the token state is of type 'fontStyle'.

```typescript
isFontStyle(): this is TokenState<'fontStyle'>;
```

### isFontWeight

This method checks if the token state is of type 'fontWeight'.

```typescript
isFontWeight(): this is TokenState<'fontWeight'>;
```

### isGradient

This method checks if the token state is of type 'gradient'.

```typescript
isGradient(): this is TokenState<'gradient'>;
```

### isGradients

This method checks if the token state is of type 'gradients'.

```typescript
isGradients(): this is TokenState<'gradients'>;
```

### isOpacity

This method checks if the token state is of type 'opacity'.

```typescript
isOpacity(): this is TokenState<'opacity'>;
```

### isRadius

This method checks if the token state is of type 'radius'.

```typescript
isRadius(): this is TokenState<'radius'>;
```

### isRadii

This method checks if the token state is of type 'radii'.

```typescript
isRadii(): this is TokenState<'radii'>;
```

### isShadow

This method checks if the token state is of type 'shadow'.

```typescript
isShadow(): this is TokenState<'shadow'>;
```

### isShadows

This method checks if the token state is of type 'shadows'.

```typescript
isShadows(): this is TokenState<'shadows'>;
```

### isShadowType

This method checks if the token state is of type 'shadowType'.

```typescript
isShadowType(): this is TokenState<'shadowType'>;
```

### isSpacing

This method checks if the token state is of type 'spacing'.

```typescript
isSpacing(): this is TokenState<'spacing'>;
```

### isSpacings

This method checks if the token state is of type 'spacings'.

```typescript
isSpacings(): this is TokenState<'spacings'>;
```

### isStepsTimingFunction

This method checks if the token state is of type 'stepsTimingFunction'.

```typescript
isStepsTimingFunction(): this is TokenState<'stepsTimingFunction'>;
```

### isTextAlignHorizontal

This method checks if the token state is of type 'textAlignHorizontal'.

```typescript
isTextAlignHorizontal(): this is TokenState<'textAlignHorizontal'>;
```

### isTextAlignVertical

This method checks if the token state is of type 'textAlignVertical'.

```typescript
isTextAlignVertical(): this is TokenState<'textAlignVertical'>;
```

### isTextDecoration

This method checks if the token state is of type 'textDecoration'.

```typescript
isTextDecoration(): this is TokenState<'textDecoration'>;
```

### isTextStyle

This method checks if the token state is of type 'textStyle'.

```typescript
isTextStyle(): this is TokenState<'textStyle'>;
```

### isTextTransform

This method checks if the token state is of type 'textTransform'.

```typescript
isTextTransform(): this is TokenState<'textTransform'>;
```

### isTransition

This method checks if the token state is of type 'transition'.

```typescript
isTransition(): this is TokenState<'transition'>;
```

### isVector

This method checks if the token state is of type 'vector'.

```typescript
isVector(): this is TokenState<'vector'>;
```

### isVectorFormat

This method checks if the token state is of type 'vectorFormat'.

```typescript
isVectorFormat(): this is TokenState<'vectorFormat'>;
```

### isZIndex

This method checks if the token state is of type 'zIndex'.

```typescript
isZIndex(): this is TokenState<'zIndex'>;
```
