UNPKG

fashion-model

Version:

JavaScript library for defining types and their properties with support for wrapping/unwrapping and serialization/deserialization.

30 lines (24 loc) 562 B
module.exports = require('./Model').extend({ typeName: 'number', wrap: false, coerce: function (value, options) { if (options.strict) { // strict mode if (value != null && (value.constructor !== Number)) { this.coercionError(value, options); } return value; } if (value == null) { return value; } if (value.constructor === Number) { return value; } const number = Number(value); if (isNaN(number)) { this.coercionError(value, options); } return number; } });