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

paramnames

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

paramnames

Returns function parameter names.

latest
Source
npmnpm
Version
1.1.2
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

paramnames

Returns function parameter names using the acorn parser, thus slower than regex implementations. Works with all kinds of functions and parameters. Also works with classes returning the constructor parameter names. Deconstructed parameter names are undefined.

npm version

API

getParameterNames(fn: Function): Array<string | undefined>

Useful information

Returns undefined if the argument is not a function.

Deconstructed parameter names are undefined.

Native function's parameter names are [].

If a class does not have a constructor the function will try to look it up in the prototype. It will go up the inheritance hierarchy until it finds the constructor or hits a native function. If the constructor is still not found, it will return the default constructor's parameter names [].

Examples

const getParameterNames = require("paramnames");

function add(a, b) {
  return a + b;
}

console.log(getParameterNames(add)); // ["a", "b"]
const getParameterNames = require("paramnames");

const fn = (a, [b, c], ...d) => {};

console.log(getParameterNames(fn)); // ["a", undefined, "d"]
const getParameterNames = require("paramnames");

const obj = {
  async *["f" + "n"](a = (1, 2, 3), b = [{}, x => {}], { x, y: { z } }, ...rest) {}
};

console.log(getParameterNames(obj.fn)); // ["a", "b", undefined, "rest"]
const getParameterNames = require("paramnames");

class Sample {
  constructor(a, b) {}
}

console.log(getParameterNames(Sample)); // ["a", "b"]
const getParameterNames = require("paramnames");

class Sample {}

console.log(getParameterNames(Sample)); // []
const getParameterNames = require("paramnames");

class Base {
  constructor(a, b) {}
}

class Child extends Base {}

console.log(getParameterNames(Child)); // ["a", "b"]
const getParameterNames = require("paramnames");

class Base {
  constructor(a, b) {}
}

class Child1 extends Base {}

class Child2 extends Child1 {
  constructor(c, d) {
    super(a, b);
  }
}

class Child3 extends Child2 {}

console.log(getParameterNames(Child3)); // ["c", "d"]
const getParameterNames = require("paramnames");

console.log(getParameterNames(console.log)); // []

console.log(getParameterNames(isNaN)); // []

console.log(getParameterNames(Object)); // []

console.log(getParameterNames(Number)); // []

FAQs

Package last updated on 30 Mar 2020

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