JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 266686
  • Score
    100M100P100Q186456F
  • License MIT

Inspects function's parameters declaration and returns information about it (e.g. names, default values, if needs destructuring, destructured parameters names and default values)

Package Exports

  • inspect-parameters-declaration

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (inspect-parameters-declaration) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

inspect-parameters-declaration

Build Status npm npm

Inspects function's parameters declaration and returns information about it (e.g. names, default values, if needs destructuring, destructured parameters names and default values).

Installation

npm install inspect-parameters-declaration

CLI

npm install inspect-parameters-declaration -g
npx inspect-parameters-declaration --help

Usage

inspectParameters(source);

getParametersNames(source);

  • source is a function reference or a string containing the parameters declaration (e.g. 'a = "z, b = [1,2,3], c, {d,e: {f}, g} = {}')

getParametersNamesFromInspection(inspectedParameters);

  • inspectedParameters expects the result from inspectParameters(source);
const { getParametersNames, inspectParameters } = require('inspect-parameters-declaration');

const testFunction = (a = "z", b = [1,2,3], c, {d,e: {f}, g} = {}, ...theArgs) => console.log("noop");

const parametersNames = getParametersNames(testFunction);
const inspectedParameters = inspectParameters(testFunction);

///////////////////////////////
// parametersNames :: RESULT //
///////////////////////////////
// [ "a", "b", "c", "d", "f", "g", "theArgs" ]


///////////////////////////////////
// inspectedParameters :: RESULT //
///////////////////////////////////
// [
//     {
//         "parameter": "a",
//         "defaultValue": "z",
//         "declaration": "a = \"z\""
//     },
//     {
//         "parameter": "b",
//         "defaultValue": "[1,2,3]",
//         "declaration": "b = [1,2,3]"
//     },
//     {
//         "parameter": "c",
//         "declaration": "c"
//     },
//     {
//         "parameter": "{d,e: {f}, g}",
//         "defaultValue": "{}",
//         "expectsDestructuring": true,
//         "declaration": "{d,e: {f}, g} = {}",
//         "destructuredParameters": [
//             {
//                 "parameter": "d",
//                 "declaration": "d"
//             },
//             {
//                 "parameter": "f",
//                 "declaration": "f"
//             },
//             {
//                 "parameter": "g",
//                 "declaration": "g"
//             }
//         ]
//     },
//     {
//         "parameter": "theArgs",
//         "isRestParameter": true,
//         "declaration": "...theArgs"
//     }
// ]