Jetons.Ref (jetons v0.2.2)

Copy Markdown View Source

Token reference expansion for DTCG brace references and JSON pointers.

Handles {ref.path} brace references, #/json/pointer references, and embedded references within string values. Provides error suggestions for mistyped reference paths.

Summary

Functions

Finds the closest match to target among candidates using Jaro distance.

Expands all {ref.path} references in a token list.

Extracts the dot-path from a brace reference like {color.brand.primary}.

Returns true if the value is a single full brace reference like {color.brand.primary}.

Functions

closest(target, candidates)

Finds the closest match to target among candidates using Jaro distance.

Returns the best match if its score exceeds 0.8, otherwise nil.

Examples

iex> Jetons.Ref.closest("colors.rd", ["colors.red", "colors.blue", "spacing.sm"])
"colors.red"

iex> Jetons.Ref.closest("xyz", ["colors.red", "colors.blue"])
nil

expand(tokens)

Expands all {ref.path} references in a token list.

Takes a list of {path, value} tuples and returns a new list where all reference values have been replaced with their resolved values. Raises ArgumentError on circular or missing references.

Examples

iex> Jetons.Ref.expand([{"colors.primary", "#f00"}, {"colors.alias", "{colors.primary}"}])
[{"colors.primary", "#f00"}, {"colors.alias", "#f00"}]

path(value)

Extracts the dot-path from a brace reference like {color.brand.primary}.

Examples

iex> Jetons.Ref.path("{colors.primary}")
"colors.primary"

ref?(value)

Returns true if the value is a single full brace reference like {color.brand.primary}.

Examples

iex> Jetons.Ref.ref?("{colors.primary}")
true

iex> Jetons.Ref.ref?("not a ref")
false

iex> Jetons.Ref.ref?("{a} and {b}")
false