kriszyp / commonjs-utils Goto Github PK
View Code? Open in Web Editor NEWUtility modules for CommonJS
Utility modules for CommonJS
Hi, do you/will you have support for the required properties?
For example to pass this
var event = {"controller":"dash","type":"launch","data":{},"method":null};
var schema = {
properties : {
controller : { type: 'string' },
data : { type: 'object' },
method : { type: 'any' }
},
required: ['controller', 'data', 'method', 'bacon']
}
var valid = Schema.validate(event, schema);
@returns {"valid":true,"errors":[]}
at the moment this returns valid.valid = true, even though bacon doesnt exist
thanks
How do I install it on node.js?
/Johnny
Hi,
if you allow multiple types for a property like
properties: {
myProp: { type: [ "string", "integer", "object" ] }
}
this works fine, but as soon as you add myProp.properties = {...} or myProp.schema.additionalProperties = false only "objects" are permitted for myProp and not any "string" or "integer".
This should fix this issue:
diff --git a/lib/json-schema.js b/lib/json-schema.js
index f4fc07d..f13acc3 100644
--- a/lib/json-schema.js
+++ b/lib/json-schema.js
@@ -134,7 +134,7 @@ var validate = exports._validate = function(/Any/instance,/Object/schema,/*B
if(schema.maxItems && value.length > schema.maxItems){
addError("There must be a maximum of " + schema.maxItems + " in the array");
}
}else if(schema.properties || schema.additionalProperties){
}else if(typeof value == 'object' && (schema.properties || schema.additionalProperties) ){
errors.concat(checkObj(value, schema.properties, path, schema.additionalProperties));
}
if(schema.pattern && typeof value == 'string' && !value.match(schema.pattern)){
Hi! L35 of json-ext.js -- we aggressively convert any string which looks lile a valid ISO date to JS Date object, thus preventing from satisfying the recommended date format in json-schema: {type: 'string', format: 'date-time'} -- the latter simply has no chances to receive a valid ISO string
--dvv
Any plan to publish this to NPM?
add a description to package.json for visibility in package managers
For example, take the following schema definition:
{
"type": "object",
"properties": {
"quizname": {
"type": "string",
"required" : true
},
"scores": {
"type": "object",
"required" : true,
"items": {
"type": "integer",
"required" : true,
"minimum" : 0,
"maximum" : 1
}
}
},
"additionalProperties" : false
}
Then try to this with it, which should be invalid:
{
"quizname": "quiz1",
"scores": {"foobar":[0,1,1,1]}
}
This is invalid for a number of reasons, including: the instance value of scores is not a array, and the contents of the instance value of scores are not integers, they're objects (arrays).
I have noticed multiple other schemas containing "items" in which validation does not go as expected. I'm looking into the code to try to fix it, but in the meantime does anyone see anything wrong with my schema that would allow that bad json to get marked as valid?
The base64 module in commonjs-utils is not functioning correctly.
As an example, decode(encode("username:password")) does not return the correct result. The other examples I tested didn't return the correct result either.
Common-js' base64 overrides Narwhal's base64 module (which works correctly) when installed as a Narwhal package and this can silently break a lot of applications.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.