Socket
Socket
Sign inDemoInstall

mschema

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.5.0 to 0.5.1

test/non-strict-type-conversion-test.js

24

build/build.js

@@ -220,7 +220,12 @@

var validate = mschema.validate = function (data, _schema) {
var validate = mschema.validate = function (data, _schema, options) {
var result = { valid: true, instance: {} },
errors = [];
errors = [],
options = options || {};
if (typeof options.strict === "undefined") {
options.strict = true;
}
if (typeof _schema !== 'object') {

@@ -257,4 +262,17 @@ return 'schema contains no properties, cannot validate';

if (options.strict === false) {
var _value;
// determine if any incoming data might need to be changed from a string number into a Number type
if (typeof value === "string" && (property === "number" || property.type === "number")) {
_value = parseInt(data[propertyName], 10);
if (_value.toString() !== "NaN") {
// a non NaN number was parsed, assign it as validation value and to instance value
value = _value;
data[propertyName] = value;
}
}
}
// check if it's value is required but undefined in value
if (property.required && (value === undefined || value.length === 0)) {
if (property.required && (value === null || value === undefined || value.length === 0)) {
errors.push({

@@ -261,0 +279,0 @@ property: propertyName,

@@ -18,7 +18,12 @@ var mschema = {};

var validate = mschema.validate = function (data, _schema) {
var validate = mschema.validate = function (data, _schema, options) {
var result = { valid: true, instance: {} },
errors = [];
errors = [],
options = options || {};
if (typeof options.strict === "undefined") {
options.strict = true;
}
if (typeof _schema !== 'object') {

@@ -55,4 +60,17 @@ return 'schema contains no properties, cannot validate';

if (options.strict === false) {
var _value;
// determine if any incoming data might need to be changed from a string number into a Number type
if (typeof value === "string" && (property === "number" || property.type === "number")) {
_value = parseInt(data[propertyName], 10);
if (_value.toString() !== "NaN") {
// a non NaN number was parsed, assign it as validation value and to instance value
value = _value;
data[propertyName] = value;
}
}
}
// check if it's value is required but undefined in value
if (property.required && (value === undefined || value.length === 0)) {
if (property.required && (value === null || value === undefined || value.length === 0)) {
errors.push({

@@ -59,0 +77,0 @@ property: propertyName,

2

package.json
{
"name": "mschema",
"version": "0.5.0",
"version": "0.5.1",
"keywords": ["schema", "mschema", "validator", "json", "json-schema"],

@@ -5,0 +5,0 @@ "description": "A schema language for defining the structure of JSON data",

@@ -203,3 +203,3 @@ # mschema

Simply put: JSON-Schema has a lot of functionality that most developers don't need or want. The complexity of JSON-Schema makes it hard to use.
Simply put: JSON-Schema has a lot of functionality that most developers don't need or want. The complexity of JSON-Schema makes it difficult to use and hard to build tools for.

@@ -206,0 +206,0 @@ ### Key differences between mschema and JSON-Schema

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc