New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

anyargs

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anyargs

A small utility module that converts function arguments to an object for use within the function based on a supplied metadata object. This allows parameters to be passed in any order, making the resultant function very flexible.

latest
Source
npmnpm
Version
1.0.5
Version published
Weekly downloads
4.2K
5.45%
Maintainers
1
Weekly downloads
 
Created
Source

AnyArgs

A small utility module that converts function arguments to an object for use within the function based on a supplied metadata object. This allows parameters to be passed in any order, making the resultant function very flexible.

Features

  • Adds type safety to function parameters
  • Adds ability to specify default parameters in any order
  • Adds ability to pass parameters in any order
  • Adds ability to skip parameters at any position in the function signature

NPM

Official home on NPM: https://www.npmjs.com/package/anyargs

Github

Official home on Github: https://github.com/eenewbsauce/anyargs

Setup

  • Install the module

    npm i anyargs

Usage

Add anyargs to your function

  • anyargs does not support multiple keys having the same type in the metadata object.
let anyArgs = require('anyargs');

function add(one, two, cb) {
  let metadata = {
    one: {
      type: 'number',
      required: true
    },
    two: {
      type: 'string',
      required: true
    },
    cb: {
      type: 'function',
      required: false,
      defaultValue: function() {}
    }
  };

  let args = anyArgs(arguments, metadata);

  return new Promise((resolve, reject) => {
    let sum = args.one + parseInt(args.two);
    resolve(sum);
    args.cb(sum);
  });
}

Use function how ever you'd like

let sum = add(1,'2', function(sum) {
  console.log(sum) //3   
});

let sumV2 = add(function(sum) {
  console.log(sum) // 7
}, '3', 4);

Tests

Run test suite

npm test

Keywords

default

FAQs

Package last updated on 10 Apr 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