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

modelok

v0.1.31

Published

A simple JavaScript object validation library.

Downloads

4

Readme

modelok

Pronounced 'model okay' is a simple JavaScript object validation library.

The primary goal is to be lightweight and super easy to use in JavaScript environments regardless of your framework of choice (React, Vue, Angular etc).

Let's say Jon Doe is filling out some info on your app but has omitted his country which is required. Thankfully you use modelok to ensure the data entered is valid before posting it to your backend.

how to use

  1. First install using npm i modelok and import into your project.

    import validate from 'modelok'
  2. Instantiate with your data model and chain your desired validation rules.

    const model = { 
        firstName: 'Jon', 
        surname: 'Doe', 
        country: '',
        email: 'jon.doe@' 
    }
    const results = validate(model).
            required('firstName').
            length('firstName', { minLength: 4 }).
            required('country').
            email('email', 'Please enter a valid email').
            done()

IMPORTANT NOTE to ensure you call .done() at the end to get results.

  1. Receive your model back with any validation errors.

    const model = { 
        firstName: 'Jon', 
        surname: 'Doe', 
        country: '',
        email: 'jon.doe@', 
        errors: {
            'firstName': ['Invalid length for firstName'],
            'country: ['The country field is required'],
            'email': ['Please enter a valid email']
        } 
    }

parameters

| Validator | Parameter | Description | Example | --- | --- | --- | --- | .required() | field | The first parameter is required to be the property string on your model holding the value to be validated. | 'country' | | message | The second parameter is an optional message string. | 'Please enter your country.' | .length() | field | The first parameter is required to be the property string on your model holding the value to be validated. | 'firstName' | | rules | The second parameter is an optional object containing message, minLength and maxLength, all of which are also optional. | { message: 'Your first name must be between 4 and 100 characters long.', minLength: 4, maxLength: 100 }

. . .

frequent questions

- Why are the errors placed in an array?

A single field may fail multiple validation rules therefore 
an array is used to collate error messages for each field.

- Can I validate an array field?

This feature is currently under development and will be available soon.

- Where can I place a feature request?

If you need a feature that is not yet available. Feel free to 
create an issue on the github repo, github.com/jomeno/modelok.