@lucania/schema 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/build/index.js +9 -1
  2. package/package.json +1 -1
package/build/index.js CHANGED
@@ -126,6 +126,9 @@
126
126
  if (isSchemaPrimitive(schema)) {
127
127
  const sourceType = getType(source);
128
128
  if (sourceType === schema || schema === "any") {
129
+ if (schema === "number" && isNaN(source)) {
130
+ throw new ValidationError("incorrectType", schema, source, path, originalSchema, originalSource, `Missing required number.`);
131
+ }
129
132
  return source;
130
133
  }
131
134
  else if (sourceType === "object" && source !== null && source.constructor.name === schema) {
@@ -321,7 +324,10 @@
321
324
  return "unfamiliar object";
322
325
  }
323
326
  static getMessage(type, source, schema, path) {
324
- const sourceRepresentation = JSON.stringify(source);
327
+ let sourceRepresentation = JSON.stringify(source);
328
+ if (isNaN(source)) {
329
+ sourceRepresentation = "NaN";
330
+ }
325
331
  switch (type) {
326
332
  case "missing":
327
333
  return path.length === 0 ?
@@ -342,5 +348,7 @@
342
348
  }
343
349
  Schema.ValidationError = ValidationError;
344
350
  })(Schema || (exports.Schema = Schema = {}));
351
+ const cow = Schema.validate({ cow: { type: "number", required: true } }, { cow: NaN });
352
+ console.log(cow);
345
353
 
346
354
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucania/schema",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "A schema module for compile-time and runtime type checking.",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",