Validator API
Exports of open-design-tokens/validator.
The complete, generated reference with every signature is at /api/. This page groups the exports by purpose.
Entry point
validateDtcg(input, options?)validates a JSON string, an object, or a prepared document. ReturnsValidationResult. Never throws on a document; throws only for an unknownspec.
Document preparation
prepareDocument(input, options?)parses and indexes once; pass the result tovalidateDtcgorlintDtcgto share the work.walkDocument(doc, visitor),getNodeAtPointer(doc, pointer),isPreparedDocument(value).
Composable validators
Each returns ValidationIssue[] and can be used on its own, for example in an editor that validates a single value as the user types.
- Values:
validateColorValue,validateDimensionValue,validateFontFamilyValue,validateFontWeightValue,validateDurationValue,validateCubicBezierValue,validateNumberValue. - Composites:
validateStrokeStyleValue,validateBorderValue,validateTransitionValue,validateShadowValue,validateGradientValue,validateTypographyValue;validateSubValuefor a sub-value that may be an alias;validateValueOfTypeand theVALUE_VALIDATORStable to dispatch by type. - Tokens and groups:
validateDesignToken,validateGroup,validateExtends,validateName,validateNameCollisions,validateDescription,validateType,validateDeprecated,validateExtensions. - Aliases:
validateAliasToken(doc, pointer, expectedType?),parseAlias,parseRef. - Whole document:
validateDocument.
Resolver
createResolver(preparedDocument) returns a memoised resolver with resolveAlias, resolveRef, lookupPath, mergedGroup, effectiveType, owningToken, and dereference for property-level references.
Spec tables and messages
TOKEN_TYPES, PRIMITIVE_TOKEN_TYPES, COMPOSITE_TOKEN_TYPES, COLOR_SPACES, COLOR_COMPONENT_RANGES, DIMENSION_UNITS, DURATION_UNITS, FONT_WEIGHT_ALIASES, FONT_WEIGHT_RANGE, ALPHA_RANGE, CUBIC_BEZIER_X_RANGE, STROKE_STYLES, LINE_CAPS, SUB_FIELD_TYPES, TOKEN_PROPS, GROUP_PROPS, RESERVED_PROPS, ROOT_TOKEN_NAME, MAX_DEPTH, SPEC_IDS, LATEST_SPEC; MESSAGES, DEFAULT_SEVERITY, ISSUE_CODES.
Helpers
Predicates isToken, isGroup, isAlias, isReference, isAliasOrReference, isTokenOfType; pointer helpers parseJsonPointer, toJsonPointer, toDotPath, escapePointerSegment, unescapePointerSegment; formatValue for safe message interpolation; createIssue and createRootContext for validator authors.