Skip to content

formatPath ​

Turns a path into a definition into text: ['fields', 1, 'rules', 0] into fields[1].rules[0].

ts
const text = formatPath(path)

Parameters ​

Returns ​

  • text string

Example ​

ts
const json: unknown = {
  version: '1',
  fields: [
    { name: 'email', type: 'emial' },
    {
      name: 'age',
      type: 'number',
      rules: [{ rule: 'minLength', value: 3 }],
    },
  ],
}

const result = builder.validate(json)
if (!result.success) {
  for (const issue of result.issues) {
    console.log(formatPath(issue.path), issue.code, issue.message)
    // fields[0].type unknown_type Unknown field type "emial"
    // fields[1].rules[0].rule kind_mismatch Rule "minLength" can't be used on number fields
  }
}

Types ​