Install
Add Typezy to your project with your preferred package manager.
npm install --save typezy
# or
pnpm add typezy
# or
yarn add typezy
Small & focused
Minimal helpers that do one job well.
Tree-shakeable
Import single functions to keep bundles tiny.
Well-tested
Comprehensive unit tests show example usage.
Examples
Practical snippets
1) Form validation (client-side)
import { isEmail, assertNonEmptyString } from 'typezy'
function validateRegistration(data) {
if (!isEmail(data.email)) return { ok:false, error:'Invalid email' }
assertNonEmptyString(data.name, 'Name is required')
return { ok:true }
}
2) API input guards (server-side)
import { isObject, assertInRange, isInteger } from 'typezy'
function handleListRequest(qs) {
const limit = isInteger(qs.limit) ? Number(qs.limit) : 20
assertInRange(limit, 1, 100)
// proceed using safe `limit`
}
3) Safe parsing & validation
import { isJSON, isObject } from 'typezy'
function parsePayload(raw) {
if (!isJSON(raw)) throw new Error('Bad payload')
const parsed = JSON.parse(raw)
if (!isObject(parsed)) throw new Error('Expected object')
return parsed
}
4) Tests: assert helpers
import { assertUUID, assertEmail } from 'typezy'
test('user payload', ()=>{
assertUUID(user.id)
assertEmail(user.email)
})
API Highlights
Common helpers — see code for the full list and exact semantics.
| Function | Type | Notes |
|---|---|---|
| isString(v) | Guard | True for string primitives |
| isNumber(v) | Guard | True for finite numbers |
| isEmail(v) | Validator | Lightweight RFC-like check |
| isUUID(v) | Validator | v4 UUID format |
| assertString(v,msg?) | Assertion | Throws TypeError on failure |
| assertInRange(n,min,max) | Assertion | Throws RangeError when out of bounds |