Skip to content

Not one of

notOneOf validates that a string is not included in a provided list of disallowed values.

It enforces strict structural string validation and rejects any non-string value or string present in the disallowed list. If the value is not a string or is in the disallowed values, the rule emits a single validation event. Otherwise, it produces no validation output.

Signature

Through the API:

.notOneOf(disallowed: readonly string[])

And internally:

export const notOneOf = (disallowed: readonly string[]): ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>

Events

Event code Description
type.not.valid Value is not structurally a string
string.is.disallowed String is in the disallowed values list

Design rationale

  • Provides a strict, predictable exclusion-based string validation.
  • Rejects non-string values with a clear structural-type diagnostic.
  • Never coerces or normalizes — validation is explicit and opt-in.
  • Emits exactly one event per failure for clarity and composability.
  • Async-compatible and returns a readonly array of JaneEvent objects.

Invoke

notOneOf runs only when explicitly included in a boundary or pipeline. It does not run automatically.

The rule activates when:

  • The value is any JavaScript value.
  • If the value is not a string, emits type.not.valid.
  • If the value is a string present in the disallowed list, emits string.is.disallowed.
  • If the value is a string not in the disallowed values → returns an empty result set.

Examples

Valid string not in disallowed list

await notOneOf(["admin", "root"])("user", "$");
// → []

String in disallowed list

await notOneOf(["admin", "root"])("admin", "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "string.is.disallowed",
//       path: "$",
//       ...
//     }
//   ]

Non-string value

await notOneOf(["admin"])(42, "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "type.not.valid",
//       path: "$",
//       ...
//     }
//   ]