npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

yss-validator-js

v1.0.1

Published

YAML Schema Syntax - a human-friendly YAML-based payload validator

Downloads

13

Readme

Introduction

A YSS validator for JavaScript.

See YAML Schema Syntax for the full specification.

Performance

Benchmarked against AJV.

Inputs: schema.yaml and schema.json

| | yss | ajv | difference | |---|---|---|---| | valid payload | 2,478,605 ops/sec | 1,271,329 ops/sec | +95% | | invalid payload | 1,938,438 ops/sec | 1,441,741 ops/sec | +34% |

*Measured on GitHub Actions (ubuntu-latest, Node.js 24, 10M iterations).

Examples

# order.yaml

id: integer
customer:
  name:  string
  email: string, ~ email
items:
  $type: array
  $size: [1, ~]
  $item:
    id: integer
    qty: integer, >= 1
    price: number
import { schema } from 'yss-validator-js'

const validate = schema.fromFile('./order.yaml')
const errors   = validate(payload)
// [] -> valid
// [{ path: 'customer.email', code: 'format_invalid', message: 'Value does not match required format', data: { format: 'email' } }]

Install

npm install yss-validator-js

Requires Node.js >= 22. Supports ESM only.

API

schema.fromFile(path, options?)

Loads and compiles a schema from a .yaml file on disk. The schema is compiled once and reused - call this at application startup, not on every request.

const validate = schema.fromFile('./schemas/order.yaml')

schema.fromObject(raw, options?)

Same as fromFile, but receives a plain JavaScript object. Useful when the schema is already parsed or comes from another source.

const validate = schema.fromObject({
  name:  'string, size [2, 80]',
  email: 'string, ~ email',
})

schema.fromString(yaml, options?)

Same as fromFile, but receives the YAML directly as a string. Useful for tests or when the schema comes from a database or environment variable.

const validate = schema.fromString(`
  name:  string, size [2, 80]
  email: string, ~ email
`)

validate(payload)

Validates a payload against the compiled schema. Returns an array of error objects. An empty array means the payload is valid.

const errors = validate({ name: 'Ana', email: '[email protected]' })
// -> []

const errors = validate({ name: 'A', email: 'not-an-email' })
// -> [
//     { path: 'name',  code: 'size_min_invalid', message: 'Minimum size is `2`',                  data: { min: 2 } },
//     { path: 'email', code: 'format_invalid',   message: 'Value does not match required format', data: { format: 'email' } }
//   ]

validate.assert(payload)

Same validation, but throws a ValidationError if the payload is invalid. Useful for frameworks that handle exceptions globally.

try {
  validate.assert(payload)
} catch (e) {
  console.log(e.errors) // [{ path, code, message, data }]
}

validate.valid(payload)

Returns true if valid, false otherwise.

if (!validate.valid(payload)) {
  return res.status(400).json({ error: 'Invalid payload' })
}

Tip: if you only use .valid(), compile with { bail: true } to avoid collecting errors that are never used.

const validate = schema.fromFile('./order.yaml', { bail: true })

if (!validate.valid(payload)) { ... }

Options

All three schema.from* methods accept an optional options object as the last argument.

| Option | Type | Default | Description | |--------|------|---------|-------------| | bail | boolean | false | Stop at the first error instead of collecting all errors |

bail

By default, validation collects all errors. With bail: true, it stops at the first error and returns a single-element array. Useful when you only need to know whether the payload is valid, or when you want to fail fast on large payloads.

const validate = schema.fromObject({
  name:  'string',
  age:   'integer',
  email: 'string',
}, { bail: true })

validate({ name: 42, age: 'old', email: 123 })
// -> [{ path: 'name', code: 'type', message: 'Unexpected type', ... }]
//    stops after the first error — age and email are not checked

License

MIT

Copyright (c) 2026-present, Alexandre Magro