Negative¶
negative validates that a number is strictly less than zero.
It enforces strict numeric validation and rejects any non-number value, NaN, or non-negative numbers. If the value is not a number or is not negative, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.negative()
And internally:
export const negative: ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
type.not.valid |
Value is not structurally a number or is NaN |
number.not.negative |
Number is not strictly less than zero |
Design rationale¶
- Provides a strict, predictable negative number validation.
- Rejects zero and positive values explicitly.
- Rejects non-number 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
JaneEventobjects.
Invoke¶
negative 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 number or is NaN, emits
type.not.valid. - If the value is a number but not less than zero, emits
number.not.negative. - If the value is a negative number → returns an empty result set.
Examples¶
Valid negative number¶
await negative(-5, "$");
// → []
Zero¶
await negative(0, "$");
// → [
// JaneEvent{
// kind: "error",
// code: "number.not.negative",
// path: "$",
// ...
// }
// ]
Non-number value¶
await negative("-5", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "type.not.valid",
// path: "$",
// ...
// }
// ]