js-data / js-data-schema

Define and validate rules, datatypes and schemata in Node and in the browser.
http://www.js-data.io/docs/js-data-schema
MIT License
18 stars 10 forks source link

Custom dataType Not Working #12

Closed willrstern closed 9 years ago

willrstern commented 9 years ago

Always possible that I'm missing something... But I can't get custom data types working: http://codepen.io/anon/pen/VYNNQE?editors=001

var schemator = new Schemator();

schemator.defineDataType('NaN', function (x) {
  if (isNaN(x)) {
    return null;
  } else {
    return {
      rule: 'type',
      actual: typeof x,
      expected: 'NaN'
    };
  }
});

var schema = schemator.defineSchema('mySchema', {
  notNumber: {
    type: 'NaN'
  }
});

var errors = schema.validateSync({
  notNumber: 123
});

console.log('never errors for any value?', errors);
jmdobry commented 9 years ago

Fixed in 1.2.1

willrstern commented 9 years ago

Thanks!