Skip to content

@dtcg-formulas/registry

Function declaration registry with built-in function support.

createRegistry(): Registry

Create a new registry, pre-loaded with built-in functions (round, clamp, min, max).

Returns

ts
interface Registry {
  register(modulePath: string, functionName: string, declaration: FunctionDeclaration): void;
  resolve(definitionRef: string): FunctionDeclaration | null;
  list(): string[];
}

Registry.register(modulePath, functionName, declaration)

Register a parsed function declaration under a path#name key.

ParamTypeDescription
modulePathstringFile path of the .module.scssdef source
functionNamestringFunction name
declarationFunctionDeclarationParsed declaration from the parser

Throws if the path#name combination is already registered (collision detection).

Registry.resolve(definitionRef)

Look up a function by its definition reference string.

ParamTypeDescription
definitionRefstringKey in "path#name" format

Returns null if not found.

Registry.list()

Returns all registered definition reference keys, sorted alphabetically.

Built-in Functions

Pre-registered at the builtins# namespace:

KeyFunctionDescription
builtins#roundround($value, $step, $mode)Round to nearest step
builtins#clampclamp($min, $preferred, $max)Constrain to bounds
builtins#minmin(...$values)Minimum value
builtins#maxmax(...$values)Maximum value

Released under the MIT License.