0.1.3 • Published 5 years ago

explicit v0.1.3

Weekly downloads
894
License
ISC
Repository
github
Last release
5 years ago

build status Code Climate js-standard-style

Explicit.js

Explicit.js allows explicitl annotation, documentation and augmentation of JavaScript methods.

npm i explicit joi -S

Usage

var explicit = require("explicit"),
    joi = require("joi");

var object = explicit({
    foo: {
        $args: [
            joi.string().meta("bar")
        ],
        $: function (bar) {
            console.info(bar);
        }
    }
});

object.foo(1); // 1
object.foo.valid(1); // will fail because the first argument is not allowed to be a string
object.foo.validObject({
    bar: "Hello World"
}); // "Hello World"

For single method definition add the $one parameter.

var foo = explicit({
    $one: true,   
    $args: [
        joi.string().meta("bar")
    ],
    $: function (bar) {
        console.info(bar);
    }
});

foo(1); // 1
foo.valid(1); // will fail because the first argument has to be a string
foo.validObject({
    bar: "Hello World"
}); // "Hello World"

And in case you want to make the assertion required you add the $assert parameter.

var foo = explicit({
    $one: true,
    $assert: true, 
    $args: [
        joi.string().meta("bar")
    ],
    $: function (bar) {
        console.info(bar);
    }
});
foo(1); // will fail because the first argument has to be a string
0.1.3

5 years ago

0.1.2

6 years ago

0.1.1

8 years ago

0.1.0

9 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago