Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace tv4 with is-my-json-valid #40

Open
adrai opened this issue Mar 23, 2015 · 2 comments
Open

replace tv4 with is-my-json-valid #40

adrai opened this issue Mar 23, 2015 · 2 comments

Comments

@adrai
Copy link
Contributor

adrai commented Mar 23, 2015

wait for: mafintosh/is-my-json-valid#38 (comment) and mafintosh/is-my-json-valid#43 and mafintosh/is-my-json-valid#46

@adrai
Copy link
Contributor Author

adrai commented Mar 23, 2015

@adrai
Copy link
Contributor Author

adrai commented Mar 25, 2015

my tmp clipboard:

var validator = require('is-my-json-valid');

var ext = {
  type: 'number'
};

var validate = validator({
  type: 'object',
  properties: {
    hello: {
      type: 'string',
      format: 'only-a'
    },
    hello2: {
      '$ref': '/other'
    }
  },
  required: ['hello', 'hello2']
}, {
  schemas: {
    '/other2': ext
  },
  formats: {
    // 'only-a': /^a+$/
    'only-a': function (data) {
      if (data.indexOf('b') >= 0) {
        return false;
      }
      return true;
    }
  },
  verbose: true,
  greedy: true
});

console.log(validate({ hello: 'aa', hello2: 3 })); // true
console.log(validate.errors);
console.log(validate.missing);
console.log(validate({ hello: 'ab' })); // false
console.log(validate.errors);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant