Function resolveRefs

Resolve $ references within an object or array using a provided schema.

References are resolved recursively allowing simple string lookups and advanced operations defined by rules.

const data = { values: { a: 1 } };
const obj = { num: "$values/a" };
const result = resolveRefs(obj, data);
console.log(result.num); // 1
  • Parameters

    • object: any

      Object or array containing $path/to/value references.

    • schema: any = ...

      Optional schema object used as the base for lookups. Defaults to a deep clone of object.

    • rules: Record<string, [string, ...any[]]> = {}

      Custom rule definitions used when a reference matches a rule key. Each rule maps to a tuple where the first element is the task name and the rest are arguments passed to that task.

    • extraTasks: Record<string, Function> = {}

      Additional task implementations that can be referenced in rules.

    Returns any

    The object with all references resolved.