Giter Site home page Giter Site logo

ensurethat's People

Contributors

bhasis avatar goloroden avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bhasis the-cc-dev

ensurethat's Issues

Provide predicates to check for different data types

At the moment, a check can only be done for the actual type, such as number, string, …

It would be great to also have checks for custom data types such as uuid, positiveNumber, and so on. These checks should be pluggable.

Improve object validator to support object schemas

At the moment, the object validator only checks whether a given argument is of type object or not. It would be awesome if there was a way to validate an object for a specific schema. The syntax might be:

var args = ensure.that(arguments).are({
  options: { foo: 'string', bar: [ 'number' ] }
});

This could also be combined with making the entire object optional:

var args = ensure.that(arguments).are({
  options: [ { foo: 'string', bar: [ 'number' ] } ]
});

Or, with making it optional and providing a default value:

var args = ensure.that(arguments).are({
  options: [ { foo: 'string', bar: [ 'number' ] }, { foo: 'Hello world!', bar: 42 } ]
});

Provide more lightweight syntax

Provide a more lightweight syntax for just validating arguments, without actually modifying them. An idea might be:

ensure.that(arguments).are({
  options: {
    id: 'uuid',
    version: [ 'positiveNumber' ]
  },
  callback: 'function'
});

Allow configurable validators

You could think of a range validator which has a min and a max value.

Basically the syntax should be something such as:

var args = ensure.that(arguments).are({
  first: 'number',
  second: [ 'range', 1, 10 ]
});

Unfortunately this interferes with optional arguments. Another idea may be to use object syntax:

var args = ensure.that(arguments).are({
  first: 'number',
  second: { validator: 'range', min: 1, max: 10 }
});

But somehow this looks … well, strange ;-).

Other ideas?

successively optional parameter of the Same Type are set wrong

Look at the code, comments will show the bug:

'use strict';
var ensure = require('node-ensurethat');

var doSomethingVeryComplex = function () {
var args = ensure.that(arguments).are({
first: 'number',
second: [ 'boolean', false ],
callback: [ 'function', function () {console.log('cb default'); } ],
callback2: [ 'function', function () {console.log('cb default2'); } ]
});
console.log(args);
if (args.second === true) {
console.log("second is true?:" + args.second);
args.callback();
} else {
console.log("second is false?:" + args.second);
console.log(args.second);
args.callback2();
}

};

var cb = function () {
console.log('cb real');
};

var cb2 = function () {
console.log('cb real2');
};
doSomethingVeryComplex(23); //all fine
console.log('--------');
doSomethingVeryComplex(23,true); //all fine
console.log('--------');
doSomethingVeryComplex(23,cb); //aspect's "cb2 default" but out will be "cb real" ?
console.log('--------');
doSomethingVeryComplex(23,cb,cb2); //aspect's "cb real2" but out will be "cb real" ?
console.log('--------');
doSomethingVeryComplex(23,true,cb,cb2); //aspect's "cb real" but out will be "cb default" ?
console.log('--------');

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.