Skip to content

KeyPathPattern

KeyPathPattern = string | KeyPath

Defined in: keyPath.ts:136

A pattern that matches key paths

Keys are separated by dots, as in a key path, and three spellings have a meaning of their own:

  • . matches the self path, as KeyPath.Self and an empty string do
  • * matches exactly one key
  • ** matches any number of keys, including none, so items.** matches items itself as well

Any other key matches only a key spelled the same way, so a pattern without wildcards matches just the key path it spells. There is no escaping: a key spelled * or ** is always a wildcard.

validator.getErrorMessages("email"); // email
validator.getErrorMessages("items.*"); // items.0 and items.1, but neither items nor items.0.name
validator.getErrorMessages("items.*.name"); // items.0.name and items.1.name
validator.getErrorMessages("items.**"); // items, items.0, items.0.name, ...
validator.getErrorMessages("."); // the errors of the object itself
validator.getErrorMessages("**"); // every error