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

jebena

v2.0.2

Published

Lightweight JSON validation library

Readme

alt text CI License: ISC npm version

Lightweight ES6 promise based JSON validation library with 0 dependencies

Heavily inspired by https://github.com/lperrin/paperwork

Installation

npm i jebena

Usage

import jebena from 'jebena'


const spec = {
    name: String,
    age: Number,
    "phone?": Number // ? = optional prop
}

const data = {
    name: "Foo Bar",
    age: 34
}

jebena(spec, data)
.then( res => {
    // cleaned and validated data
})
.catch(err => {
    // array of errors
})

Express

import {jx, email, runEach} from 'jebena'

const app = express()
app.use(express.json())

const spec = {
    email: email(),
    password: runEach(String, minLen(8)),
}

app.post("/users", jx(spec), () => {
    //req.body is validated and cleaned
})

That's it. jebena returns a 400 response silently if there are any errors. Sample 400 response:

{
  "errors": [
    "password: must be at least 8 characters long"
  ]
}

Options

jebena accepts a third optional argument where you can define your preferences. Below are the defaults

const defaultOps = {
    allowEmpty: false,
    ignoreUnknown: true,
    showOnlyFirstErrorForSameKey: false,
    dataSource: "body" //for express only. either 'body' or 'query'

}

Custom Types

runEach(type1, type2...) validates each type against key value

email() checks if value is email

len(n) checks if value is exactly n characters long

minLen(n) checks if value is at least n characters long

maxLen(n) checks if value is at most n characters long

match(reg) checks if value matches regex

equals(val) checks if value equals given value

oneOf([el, el2, el3...]) checks if value is equal to one of the array elements

ifKey(key, predicate = v => true) runs validation on current key only if the key argument is present in the spec and the predicate returns true

ifKey(key, predicate = v => true).runEach(type1, type2...) validates each type if predicate is true

any() accepts any value but undefined

int() checks if value is integer

pInt() checks if value is positive integer

date(format = "mm/dd/yy") checks if value matches date format. Supports - or / separators and dd/mm/yyyy or mm/dd/yyyy formats

Advanced Usage

Custom Validation

For custom validations simply provide a predicate. If you want to return a custom error message, return [false, <your error message>]

const spec = {
    fullName: (val) => val.split(" ").length == 2 ? true : [false, "invalid name"] 
}

Arrays and nested objects

const spec = {
    links: [], //array of any
    address: {
        street: String,
        city: String,
        state: oneOf(statesList),
        zipCode: runEach(int(),len(5))
    }
    books: [{
        title: String,
        author: String,
        yearPublished: int(),
        someProp: {
            otherProp: Number
        }
    }]
}

Param dependent on other param

There might situations where you want to run a validation on a param only if another param meets certain conditions and for that you can use ifKey()

const spec  = {
    shippingPreference: oneOf(['pickup', 'delivery']),
    deliveryAddress: ifKey('shippingPreference', v => v == 'delivery').runEach({
        street: String,
        city: String,
        state: oneOf(['az','co']),
        zipCode: runEach(int(),len(5))

    })
}

Test

clone repo to your machine and run:

npm run jebena-test