simpl-schema
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -6,2 +6,4 @@ <!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
- [simpl-schema CHANGELOG](#simpl-schema-changelog) | ||
- [1.1.0](#110) | ||
- [1.0.0](#100) | ||
- [0.5.0](#050) | ||
@@ -26,2 +28,7 @@ - [0.4.2](#042) | ||
## 1.1.0 | ||
- The `autoConvert` cleaning now converts strings that are "true" or "false" to Boolean if the schema expects a Boolean. | ||
- The `autoConvert` cleaning now converts numbers to Boolean if the schema expects a Boolean, with 0 being `false` and all other numbers being `true`. | ||
## 1.0.0 | ||
@@ -28,0 +35,0 @@ |
@@ -51,2 +51,13 @@ 'use strict'; | ||
// Convert to Boolean type | ||
if (type === Boolean) { | ||
if (typeof value === 'string') { | ||
// Convert exact string 'true' and 'false' to true and false respectively | ||
if (value.toLowerCase() === 'true') return true;else if (value.toLowerCase() === 'false') return false; | ||
} else if (typeof value === 'number' && !isNaN(value)) { | ||
// NaN can be error, so skipping it | ||
return Boolean(value); | ||
} | ||
} | ||
// If an array is what you want, I'll give you an array | ||
@@ -53,0 +64,0 @@ if (type === Array) return [value]; |
{ | ||
"name": "simpl-schema", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A schema validation package that supports direct validation of MongoDB update modifier objects.", | ||
@@ -5,0 +5,0 @@ "author": "Eric Dobbertin <aldeed@gmail.com>", |
@@ -1,3 +0,5 @@ | ||
# simple-schema | ||
[![CircleCI](https://circleci.com/gh/aldeed/simple-schema-js/tree/master.svg?style=svg)](https://circleci.com/gh/aldeed/simple-schema-js/tree/master) | ||
# SimpleSchema (simpl-schema NPM package) | ||
SimpleSchema validates JavaScript objects to ensure they match a schema. It can also clean the objects to automatically convert types, remove unsupported properties, and add automatic values such that the object is then more likely to pass validation. | ||
@@ -26,2 +28,3 @@ | ||
- [Validate an Array of Objects and Throw an Error](#validate-an-array-of-objects-and-throw-an-error) | ||
- [Validate a Meteor Method Argument and Satisfy `audit-argument-checks`](#validate-a-meteor-method-argument-and-satisfy-audit-argument-checks) | ||
- [Validate an Object and Get the Errors](#validate-an-object-and-get-the-errors) | ||
@@ -1081,2 +1084,4 @@ - [Validate a MongoDB Modifier](#validate-a-mongodb-modifier) | ||
* Strings that are numbers are converted to Numbers if the schema expects a Number | ||
* Strings that are "true" or "false" are converted to Boolean if the schema expects a Boolean | ||
* Numbers are converted to Boolean if the schema expects a Boolean, with 0 being `false` and all other numbers being `true` | ||
* Non-array values are converted to a one-item array if the schema expects an Array | ||
@@ -1083,0 +1088,0 @@ * `removeEmptyStrings`: Remove keys in normal object or $set where the value is an empty string? True by default. |
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
171602
2568
1217