Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

arg-check

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arg-check

A lightweight library to help developers catch bugs before they skitter in by making sure the right types of arguments are being passed into functions and methods.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

arg-check

arg-check is a lightweight library to help developers catch bugs before they skitter in by making sure the right types of arguments are being passed into functions and methods.

It takes two arguments: (1) an argument you've passed into a function declaration, and (2) the type you expect that argument to be. It couldn't be easier:

let argCheck = require('arg-check');

let add = (a, b) => {
  argCheck(a, 'number');
  argCheck(b, 'number');

  return a + b;
};

add(3, 4); // 7

add(3, 'four'); // TypeError: Expected argument to be of type "number" but instead received type "string"

Getting Started

Step 1

In the terminal:

$ npm install arg-check
Step 2

In path/to/my/rad/app/or/whatever/app.js:

let argCheck = require('arg-check');
Step 3

Really, that's it. Start arg-checking!

Supported Argument Types

Note all argument types are lowercase strings.

  • 'null'
  • 'undefined'
  • 'string'
  • 'number'
  • 'boolean'
  • 'array'
  • 'object'

argCheck also supports custom class types:

class Person {
  constructor(attributes) {
    this.name = attributes.name;
  }
}

let rachael = new Person({ name: 'Rachael' });

let personName = (person) => {
  argCheck(person, 'person');

  return person.name;
};

personName(rachael); // 'Rachael'
personName({ name: 'Rachael' }) // TypeError: Expected argument to be of type "person" but instead received type "object"

Note again that the expected class name will be a lowercase string.

Contributing

We'd love contributors and feedback! We are currently at 100% test coverage and that's the way we like it. Hit us up and let's make this thing even better.

License

arg-check is released under the MIT License

FAQs

Package last updated on 20 Jan 2017

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