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 🙏

© 2024 – Pkg Stats / Ryan Hefner

juzz

v0.2.0

Published

Fuzzer for Joi schema

Downloads

6

Readme

Juzz

npm version Build Status codecov Known Vulnerabilities License Greenkeeper badge

Fuzzer for Joi

Warning this is a proof of concept and is currently a work in progress. It is mostly used by me to automatically add fuzzing to my hapi test suites so stability and accuracy though important is not a major factor.

Usage

const Joi  = require('joi');
const Juzz = require('juzz');

const schema = Joi.object({
        id: Joi.number().integer().min(1).max(1000).required(),
        name: Joi.string().alphanum().min(1).max(32).required(),
        blob: Joi.any()
    });

const example = Juzz(schema);
const {errors} = schema.validate(example);
console.log(errors) // errors should not exist
console.log(example) // example will be some object that contains a valid

API

Juzz(schema, [options])

Generates a random example according to schema

schema - a valid joi schema

options - object with optional options

  • replace: (res, desc, rules) => new res - method that allows to override generated values default((res) => res)

    • res - the result that Juzz created
    • desc - the description for that item

    for example to replace all strings with 'aaaaa' use the following replace function -

    relace (res, desc, rules) {
    
        if (desc.type === 'string') {
            return 'aaaaa';
        }
        return res;
    }

    replace can also be useful when using custom version of joi without a standard types -

    relace (res, desc, rules) {
    
        if (desc.type === 'myCustomType') {
            return 'aaaaa';
        }
        return res;
    }
  • contextObject - should be identical to the context object passed to joi.validate when schema references a context default({})

  • strictBoolean - if set to true will bail with an error when schema description is not known (can be useful for debugging) default(false)

  • extendedTypesarray - custom types that will pass strict mode default([])

  • extendedTypesDictObject - Dictionary object to allow replacing custom type with built-in type for example: {customType: 'string'} default({})

  • stringMininteger: used if string min is not forced in schema default(0)

  • stringMaxinteger: used if string max is not forced in schema default(100)

  • numberMininteger: used if number min is not forced in schema default(-10e6)

  • numberMaxinteger: used if number max is not forced in schema default(10e6)

  • numberPrecisioninteger: used if number precision is not forced in schema default(4)

  • arrayMininteger: used if array min is not forced in schema default(0)

  • arrayMaxinteger: used if array max is not forced in schema default(10)

  • objectMininteger: used if object min is not forced in schema default(0)

  • objectMaxinteger: used if object max is not forced in schema _default(10)

Known issues

It is possible to have very limited schemas or even schemas which has no valid values. In cases where Juzz can not create a valid schema it might throw a value but can also return an undefined value or invalid value instead. If always getting a correct schema is essential, you should always check the returned value using joi validate method.

Schemas containing lazy values (Joi.lazy()) are currently not supported due to their description returned from joi is not useful. this will hopefully change in future versions.