Registry / testing / n4s
library6.2.1jsnpmunverified

n4s is a typed schema validation library (v6.2.1) built as a typed version of 'enforce' for the Vest testing framework ecosystem. It provides compile-time type inference and runtime validation using a chained API. Unlike alternatives like Zod or Yup, n4s is tightly integrated with Vest and follows a similar syntax. Released sporadically, it focuses on small bundle size and TypeScript-first design. Key differentiator: seamless validation integration within Vest test suites.

npm install n4s
INSTALL
IMPORT
SIG · N4S
N
n4s
testingjavascriptv6.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

n4s
import n4s from 'n4s';
import { n4s } from 'n4s';
Default export, not named.
enforce
import { enforce } from 'n4s';
import enforce from 'n4s';
Named export for legacy compatibility.
N4sTypes
import type { N4sTypes } from 'n4s';
import { N4sTypes } from 'n4s';
Type-only import for TypeScript.

Shows basic validation using n4s chained schema and test method.

import n4s from 'n4s'; const schema = n4s.number().gte(0).lte(100); const value = 50; const result = schema.test(value); console.log(result); // { valid: true, message: '', value: 50 } const invalid = -1; console.log(schema.test(invalid)); // { valid: false, message: 'value must be greater than or equal to 0', value: -1 }
Debug
Known issues
breakingv6 changed default export from enforce to n4s; enforce is now a named export.
fix
Use import n4s from 'n4s' instead of import enforce from 'n4s'.
affects: >=6.0.0
deprecated.isRequired() is deprecated in v6; use .required() instead.
fix
Replace .isRequired() with .required().
affects: >=6.0.0
gotchaValidation returns an object with { valid, message, value }, not a boolean.
fix
Check result.valid rather than passing result directly as a boolean.
affects: >=6.0.0
gotchaString schema .equals() compares case-sensitively by default; use .equalsIgnoreCase() for case-insensitive.
fix
Use .equalsIgnoreCase() for case-insensitive comparison.
affects: >=6.0.0
deprecated.notEmpty() is deprecated in v6; use .required() for strings.
fix
Replace .notEmpty() with .required().
affects: >=6.0.0
Errors
Common errors & fixes
TypeError: n4s is not a function
Incorrect import: using named import instead of default.
fix
Use import n4s from 'n4s' instead of import { n4s } from 'n4s'.
Property 'test' does not exist on type 'typeof import...'
Using enforce default import (old version) which returns a function, not a schema object.
fix
Upgrade to v6 and use import n4s from 'n4s'.
Module '"n4s"' has no exported member 'enforce'.
Using named import for enforce in version <6 where enforce was the default export.
fix
Use import enforce from 'n4s' for v5 or use import n4s from 'n4s' for v6.
Upgrade
Version history
6.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
packagen4s
n4s — npm install n4s · libregistry