Installation & Quick Start
Requirements
Section titled “Requirements”- Node.js 22 or higher (or any runtime with ES modules and modern
Datesupport) - TypeScript 5.0+ (optional — the library ships bundled types and works in plain JavaScript)
Installation
Section titled “Installation”-
Install the package
Terminal window npm install @slashlab/numerik-jsTerminal window pnpm add @slashlab/numerik-jsTerminal window yarn add @slashlab/numerik-jsTerminal window bun add @slashlab/numerik-js -
No configuration needed
The package ships ESM and CJS builds. There is no setup step, no config file, and no tree-shaking required.
-
Use it
import { Numerik } from '@slashlab/numerik-js'Numerik.pesel().isValid('92060512186') // true
Quick start
Section titled “Quick start”Boolean validation
Section titled “Boolean validation”import { Numerik } from '@slashlab/numerik-js'
Numerik.pesel().isValid('92060512186') // trueNumerik.idCard().isValid('ABC123454') // trueNumerik.passport().isValid('AB1234564') // trueNumerik.nip().isValid('5260250274') // trueNumerik.vatEu().isValid('PL5260250274') // trueNumerik.regon().isValid('850518457') // trueNumerik.krs().isValid('0000127206') // trueNumerik.nrb().isValid('61102010260000000000000000') // trueNumerik.iban().isValid('PL61102010260000000000000000') // trueRich validation result
Section titled “Rich validation result”validate() never throws. It returns a ValidationResult carrying the list of failures when validation does not pass.
import { Numerik } from '@slashlab/numerik-js'
const result = Numerik.pesel().validate('92060512186')result.isValid // trueresult.failures // []
const failed = Numerik.pesel().validate('00000000000')failed.isFailed() // truefailed.getFirstFailure()?.reason // ValidationFailureReason.AllZerosfailed.getFirstFailure()?.message // human-readable messageParsing to a value object
Section titled “Parsing to a value object”On success, parse() returns a value object. On failure, it throws a ValidationException.
import { Numerik } from '@slashlab/numerik-js'
const pesel = Numerik.pesel().parse('92060512186')pesel.getBirthDate() // Date — 1992-06-05pesel.getGender() // Gender.Femalepesel.getAge() // number — calculated from todaypesel.isAdult() // trueUse tryParse() when you prefer null on failure instead of an exception:
const pesel = Numerik.pesel().tryParse('bad-input') // nullChoosing the right method
Section titled “Choosing the right method”| Method | Returns | Throws | Use when |
|---|---|---|---|
isValid() | boolean | never | Simple existence check |
validate() | ValidationResult | never | You need the failure reason |
parse() | value object | ValidationException | You need extracted data and want exceptions |
tryParse() | value object or null | never | You need extracted data but prefer null over exceptions |
Strict mode
Section titled “Strict mode”All identifiers support a strict flag (default true). In strict mode, additional semantic checks are applied — for example, PESEL rejects future birth dates and all-same-digit patterns.
// Strict mode on (default)Numerik.pesel().isValid('11111111111') // false — all same digit
// Strict mode offNumerik.pesel(false).isValid('11111111111') // true if checksum passes
// Check whether strict mode is activeNumerik.pesel().isStrict() // trueNumerik.pesel(false).isStrict() // falseZod integration
Section titled “Zod integration”The optional /zod sub-path provides Zod schemas for all identifiers. Requires zod as a peer dependency.
import { peselSchema, peselParseSchema } from '@slashlab/numerik-js/zod'
// Validates the string — errors surface as Zod issuesconst schema = peselSchema()schema.parse('92060512186') // '92060512186'
// Validates and transforms to a Pesel value objectconst parseSchema = peselParseSchema()const pesel = parseSchema.parse('92060512186') // Pesel instancepesel.getBirthDate() // DateNext steps
Section titled “Next steps”- Browse the PESEL, ID Card, Passport, NIP, VAT-EU, REGON, KRS, NRB, or IBAN reference for full method listings.
- See Validation Results, Error Handling, Algorithms, and Zod in the Guide for everything beyond the basics.