Socket
Socket
Sign inDemoInstall

tv4-formats

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tv4-formats

Common JSON Schema string format constraints in the form of tv4 validator callbacks


Version published
Weekly downloads
2.8K
decreased by-7.32%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

About

Provides an 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

  • credit-card-number
  • date (YYYY-MM-DD)
  • date-time (for example, 2014-05-02T12:59:29+00:00)
  • duration (for example, P1DT12H for 1.5 days)
  • time-offset (same format as duration, but can also be negative: -P7D)
  • email
  • guid
  • uri
  • url

Keywords

FAQs

Package last updated on 25 Apr 2017

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