v8n (validation) is a JavaScript validation library offering a dead-simple, fluent API for creating complex validation rules. It supports chaining multiple rules and modifiers, allowing for highly intuitive and readable validation logic for various data types including primitives, arrays, and objects. The library provides flexible validation strategies, including boolean-based `test()`, exception-based `check()` for detailed error feedback, and `testAll()` to gather all failures, as well as asynchronous validation. Currently at version 1.5.1, v8n maintains an active development pace with incremental feature additions and bug fixes, often addressing issues related to its schema, optional, and async validation capabilities. It differentiates itself through its highly customizable nature, enabling users to extend it with custom rules, and its reusability, allowing validation chains to be exported as modules.
npm install v8nVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic string, array, object schema validation, custom rule extension, and exception-based error handling using the fluent API.
Update `catch (ex: ValidationException)` to `catch (ex: ValidationError)` and import `ValidationError`.
Ensure `check()` is used for its side effect (throwing an error) and not for a boolean return value. The type definition has been corrected in v1.5.0.
Upgrade to v1.5.0 or later to ensure correct behavior of the `optional` rule, especially concerning empty strings and async validation within it.
Update to v1.5.0 or newer. The bug with `Proxy` check returning `true` has been fixed.
Upgrade to v1.5.1 or later to benefit from the fixed and more efficient regular expressions for these rules.
Change all references from `ValidationException` to `ValidationError` and ensure `ValidationError` is imported.
Ensure `check()` is always within a `try...catch` block and that you are checking for `instanceof ValidationError`. Remember `check()` throws on failure and returns `void` on success.
Update `v8n` to version 1.5.0 or later. Also, consider the `considerTrimmedEmptyString` flag on the `optional` rule for specific empty string handling needs.
Ensure `v8n.extend({ myCustomRule })` is called before using the rule. For TypeScript, you might need declaration merging (see v8n documentation on custom types).No dependency data recorded yet.