Git Product home page Git Product logo

tv4-formats's Introduction

Build Status

About

Provides the implementation of common JSON Schema string format constraints in the form of tv4 validator callbacks. Thus, it's a plug-in for tv4.

Usage

First, install it, together with tv4 itself, via Node.js'es npm into your project

$ npm install --save tv4 tv4-formats

Then, in the code

var tv4 = require('tv4'),
    formats = require('tv4-formats'),
    assert = require('assert'),
    validator = tv4.freshApi(),
    schema = {type: 'string', format: 'date'};

validator.addFormat(formats);
assert(validator.validate('2014-02-11', schema));  // Valid ISO 8601 date
assert(!validator.validate('2014-02-29', schema)); // Invalid. Only 28 days in this February
assert(!validator.validate('11.02.2014', schema)); // Invalid. Wrong date format

Here, the format: 'date' part of the schema validation is provided by tv4-formats package.

Supported formats

  • date (YYYY-MM-DD)
  • date-time (for example, 2014-05-02T12:59:29+00:00)
  • email
  • uri
  • url
  • credit-card-number
  • duration (for example, P1DT12H for 1.5 days)

tv4-formats's People

Contributors

deyhle avatar ikr avatar magomogo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.