Code Monkey home page Code Monkey logo

commonjs-utils's People

Contributors

deanlandolt avatar kriszyp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

commonjs-utils's Issues

json schema validator - required?

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

Only "object" type valid if multiple types permitted

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)){
    

json-ext: greedy dates

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

NPM?

Any plan to publish this to NPM?

Item attribute doesn't validate properly

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?

base64 is not working correctly

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.