0.4.0 • Published 6 years ago

fparts v0.4.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

fparts 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, fparts should parse the input properly.

engines: node >= 8.x

Example

const {deconstruct, reconstruct} = require('fparts');

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 fparts --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