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

js-function-parts

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-function-parts

Deconstruct JS functions into individual components and reconstruct from data.

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

js-function-parts Build Status

low-level function parser optimized for performance.

.deconstruct() JS functions into objects containing:

.reconstruct() objects into functions.

Params

  • isAsync
  • isGenerator
  • isArrowFunc
  • name
  • params
  • body

Syntax is generous - if it's valid JS, js-function-parts should parse the input properly.

engines: node >= 8.x

Example

const {deconstruct, reconstruct} = require('js-function-parts');

var obj = deconstruct(function() {return null;});

console.log(obj);
// obj.isAsync = false
// obj.isGenerator = false
// obj.isArrowFunc = true
// obj.name = null
// obj.params = null
// obj.body = 'return null;'

var func = reconstruct(obj);
func(); // returns `null`.

Installation

npm i js-function-parts --save

API

.deconstruct()

Arguments

  • func {Function}

Returns {Object}

var obj = deconstruct(function() {});
console.log(obj);
/*
{
  isAsync: false,
  isGenerator: false,
  isArrowFunc: false,
  name: null,
  params: null,
  body: null,
}
*/

.reconstruct()

Arguments

  • obj {Object} a parts object

Returns {Function}

var func = reconstruct({
  isAsync: false,
  isGenerator: false,
  name: 'name',
  params: 'a, b',
  body: 'return 1;',
});

License

MIT

FAQs

Package last updated on 26 Feb 2018

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