New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

paramatas

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

paramatas

Utility library for validating function parameters

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 21 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc