Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nagoya

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nagoya

Opinionated? validation library

  • 1.2.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

nagoya Build Status NPM Version License

Nagoya is a validation library for writing cool and arbitrary validation schemas and producing user-friendly validation error messages.

Usage

import * as nagoya from 'nagoya';

const schema = {
    username(username) {
        nagoya.isString(username, 'not a string', TypeError);
        nagoya.isAlphanumeric(username, 'must contain only letters and numbers');
        // alternatively nagoya.matches(username, /^\w*$/)
        nagoya.isMinLength(username, 3, 'must be at least 3 characters long');
        nagoya.isMaxLength(username, 30, 'cannot be more than 30 characters long');
    },

    password(password) {
        nagoya.isString(username, 'not a string', TypeError);
        nagoya.isMinLength(username, 8, 'must be at least 8 characters long');
        nagoya.isMaxLength(username, 30, 'cannot be more than 30 characters long');
    },

    email(emailAddress) {
        nagoya.isEmail(emailAddress, 'must be a valid email address');
    }
};

const validate = nagoya.schema(schema);

try {
    validate({
        username: '*asdf^',
        password: 'foo321',
        email: 'bob@@foo.com'
    });
} catch (err) {
    console.log(err.message);
    console.log(err.columns);
}

// ValidationError: username must contain only letters and numbers,
//                  password must be at least 8 characters long,
//                  email must be a valid email address

// {
//     username: [ValidationError: must contain only letters and numbers],
//     password: [ValidationError: must be at least 8 characters long],
//     email: [ValidationError: must be a valid email address]
// }

Documentation

TODO

Keywords

FAQs

Package last updated on 25 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc