schema-casting
JSON Schema type casting and normalization
Last updated a year ago by runk .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install schema-casting 
SYNC missed versions from official npm registry.

schema-casting Build Status

Tiny tool aimed to type cast raw data based on provided json schema.

Installation

npm i schema-casting

Usage

const sc = require('schema-casting');

const schema = {
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "a": { "required": true, "type": "integer" },
    "b": { "required": true, "type": "boolean" },
    "c": { "required": true, "type": "number" },
    "d": {
      "required": true,
      "type": "object",
      "properties": {
        "e": {
          "required": true,
          "type": "number",
        }
      }
    }
  },
  "required": true,
  "additionalProperties": false
};

const input = {
  a: '1',
  b: 'true',
  c: '2.3',
  d: { e: '4.56' },
};

const output = sc(schema, input);
console.log(output);
// { a: 1, b: true, c: 2.3, d: { e: 4.56 } }

License

MIT

Current Tags

  • 1.4.0                                ...           latest (a year ago)

5 Versions

  • 1.4.0                                ...           a year ago
  • 1.3.1                                ...           3 years ago
  • 1.3.0                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 2
This Month 3
Last Day 1
Last Week 1
Last Month 7
Dependencies (2)
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |