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

veracityjs

v1.1.0

Published

A object data validator for javascript

Downloads

4

Readme

Veracity JS - Synopsis

Veracity JS is a plugin for validating your javascript object and ensuring you that the object you have received is consistent with what you want.

Installation

Veracity JS doesn't require anything. Just add the script into your app like this :

Basic usage

    var Veracity = require('veracityjs')

ES6

    import Veracity from "veracityjs"

How to use it

To use it, you must follow this pattern :

    Veracity.validate(<your data>, <your validation pattern>);

Example

Basic example

    var data = {
        test: 1
    };
    
    Veracity.validate(data, [
      {name: 'test', type: Veracity.Type.Integer, required: true}
    ];      // It will return true
    

You don't have to pass an object, you can just pass a variable and test its type

    var test = "string test";
    
    Veracity.validate(test, Veracity.Type.String);  // It will return true
    Veracity.validate(test, Veracity.Type.Integer); // It will return false

Here is a complete example for testing all types and all parameters

    Veracity.validate({
        integer: 1,
        float: 1.5,
        string: 'test',
        array: [1, 5],
        object: { data: 1 },
        objectWaterfall: { float: 1, integer: 1.5 },
        amongValues: 3,
        amongTypes: '3',
        regex: 'price'

    }, [
        {name: 'integer', type: Veracity.Type.Integer, required: true},
        {name: 'float', type: Veracity.Type.Float, required: true},
        {name: 'string', type: Veracity.Type.String, required: true},
        {name: 'array', type: Veracity.Type.Array, required: true},
        {name: 'object', type: Veracity.Type.Object, required: true},
        {name: 'objectWaterfall', type: Veracity.Type.Object([
            {name: 'float', type: Veracity.Type.Integer, required: true},
            {name: 'integer', type: Veracity.Type.Float, required: true}
        ]), required: true},
        {name: 'amongValues', type: Veracity.Type.AmongValues([1, 2, 3]), required: true},
        {name: 'amongTypes', type: Veracity.Type.AmongTypes([Veracity.Type.Integer, Veracity.Type.Float, Veracity.Type.String]), required: true},
        {name: 'regex', type: Veracity.Type.Regex(/price/gi), required: true}

    ]); // It will return true

Validation Pattern parameters

| Parameters | State | Explication | |------------|-------|-------------| | name | required | The name of property of the data to test | | type | required | A type | | required | optional | if this is required, the validation won't pass if the property doesn't exist |

List of types

| Type | Parameters | Explication| |------|------------|------------| | Veracity.Type.Integer | / | Test if the property is an integer (it won't pass if it is a float) | | Veracity.Type.Float | / | Test if the property is a float (it won't pass if it is an integer) | | Veracity.Type.Boolean | / | Test if the property is a boolean (even if a boolean is 'false') | | Veracity.Type.String | / | Test if the property is a string | | Veracity.Type.Array | / | Test if the property is an array (it will pass if it is an empty array) | | Veracity.Type.Object | Array of types (optional) | Test if the property is an object (you can validate all object properties with the optional parameters) | | Veracity.Type.Regex | Regular Expression (REQUIRED) | Test if the property match with the regular expression passed by paramaters) | | Veracity.Type.AmongValues | Array of values (REQUIRED) | Test if the property match with one of values contained in array passed by parameters) | | Veracity.Type.AmongTypes | Array of types (REQUIRED) | Test if the property type match with one of types contained in array passed by parameters) |

Example

To run test, juste use :

npm test

License

This plugin is licensed under Creative Commons Attribution 4.0 International License.