schema-llama
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -35,2 +35,5 @@ 'use strict'; | ||
} | ||
//TODO: implement check for required fields. | ||
const toJSON = function () { | ||
@@ -77,2 +80,9 @@ const object = {}; | ||
switch (key) { | ||
case 'required': | ||
{ | ||
if (options[key].constructor !== Array) { | ||
throw new _errors.TypeError(`Required field list must be an array of strings or numbers.`); | ||
} | ||
break; | ||
} | ||
case 'attemptCast': | ||
@@ -118,2 +128,11 @@ { | ||
function primitiveHelper(value, schemaItem, options, key, schema) { | ||
if (value == null || value == undefined) { | ||
if (options.required) { | ||
if (options.required.find(requiredKey => requiredKey == key)) { | ||
throw new _errors.TypeError(`If you set ${key}, it cannot be null or undefined. value = ${value}`); | ||
} | ||
} | ||
return value; | ||
} | ||
const primitives = [Boolean, String, Date, Number, Symbol]; | ||
@@ -120,0 +139,0 @@ const Primitive = primitives.find(primitive => schemaItem === primitive); |
{ | ||
"name": "schema-llama", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A more purely javascript es6 class generator. Takes the work out of validation, type checking, and more.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -27,2 +27,5 @@ import { TypeError, ValidationError, Error } from './errors'; | ||
} | ||
//TODO: implement check for required fields. | ||
const toJSON = (function () { | ||
@@ -70,2 +73,8 @@ const object = {}; | ||
switch(key) { | ||
case 'required': { | ||
if(options[key].constructor !== Array) { | ||
throw new TypeError(`Required field list must be an array of strings or numbers.`); | ||
} | ||
break; | ||
} | ||
case 'attemptCast': { | ||
@@ -106,2 +115,11 @@ if(options[key].constructor !== Boolean) { | ||
function primitiveHelper(value, schemaItem, options, key, schema) { | ||
if(value == null || value == undefined) { | ||
if(options.required) { | ||
if(options.required.find(requiredKey => requiredKey == key)) { | ||
throw new TypeError(`If you set ${key}, it cannot be null or undefined. value = ${value}`); | ||
} | ||
} | ||
return value; | ||
} | ||
const primitives = [ Boolean, String, Date, Number, Symbol ]; | ||
@@ -108,0 +126,0 @@ const Primitive = primitives.find(primitive => schemaItem === primitive); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25673
488