0.1.5 • Published 7 years ago

normalize-json v0.1.5

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

Try normalize-json on RunKit

normalize-json

Terse syntax for validating and normalizing JavaScript objects in Node.

const nJ = require('normalize-json');

// a schema looks like this!
let validator = nJ({
    name: [String, 30], // a string with <= 30 characters
    age: [Number, 0, 100], // a number between 0 and 100, inclusive
    color: ['red', 'yellow', 'blue'] // must be one of these three values
});

// here's how we might validate/normalize an object
let obj = {
    name: ' Nigel   ', // this string will be trimmed!
    age: 23,
    color: 'blue',
    someUndefinedField: undefined // undefined fields will be stripped out
};

let result = validator(obj); // 'result' is a new object; 'obj' has not been changed
console.log(result); // { name: 'Nigel', age: 23, color: 'blue' }

Try it out!

You can try out normalize-json in your browser at npm.runkit.com/normalize-json.

API

TODO

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago