Not Pictured: Mangoes

    paramatas

    0.1.1 • Public • Published

    Paramatas

    A tiny utility library for validating function parameters.

    Installation

    • via npm: npm install paramatas --save

    • via bower: bower install paramatas --save

    Usage

    required(name, param, [type])

    Throws an error if the supplied parameter isn't defined or (optionally) doesn't match the supplied type.

    • name - The parameter name
    • param - The parameter value
    • type (optional) - The data type to check in addition to the required check- see typedAs for a list of valid values
    Node.js example
    var Params = require('paramatas');
    ...
    function(value, callback) {
      // Throws an error if the "value" param isn't defined
      Params.required('value', value);
      // Throws an error if the "callback" param isn't defined or is not a Function
      Params.required('callback', callback, Function);
     
      // The above two calls could be chained together as
      Params.required('value', value).required('callback', callback, Function);
      ...
    }
    ...
    Vanilla JS example
    function(value, callback) {
      // Throws an error if the "value" param isn't defined
      paramatas.required('value', value);
      // Throws an error if the "callback" param isn't defined or is not a Function
      paramatas.required('callback', callback, Function);
     
      // The above two calls could be chained together as
      paramatas.required('value', value).required('callback', callback, Function);
      ...
    }

    typedAs(name, param, type)

    Throws an error if the supplied parameter is defined and does not match the supplied type.

    • name - The parameter name
    • param - The parameter value
    • type - The expected data type, valid types include: Boolean, Number, String, Object, Function
    Node.js example
    var Params = require('paramatas');
    ...
    function(value, callback) {
      // Throws an error if the "callback" param is defined but not a Function
      Params.typedAs('callback', callback, Function);
      // Calls are chainable, too!
      Params.required('value', value).typedAs('callback', callback, Function);
      ...
    }
    ...
    Vanilla JS example
    function(value, callback) {
      // Throws an error if the "callback" param is defined but not a Function
      paramatas.typedAs('callback', callback, Function);
      // Calls are chainable, too!
      paramatas.required('value', value).typedAs('callback', callback, Function);
      ...
    }

    Tests

    npm test

    Release History

    • 0.1.0 Initial release

    Install

    npm i paramatas

    DownloadsWeekly Downloads

    2

    Version

    0.1.1

    License

    ISC

    Last publish

    Collaborators

    • patrickvalle