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
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`.
npm i js-function-parts --save
Arguments
- func {Function}
Returns {Object}
var obj = deconstruct(function() {});
console.log(obj);
/*
{
isAsync: false,
isGenerator: false,
isArrowFunc: false,
name: null,
params: null,
body: null,
}
*/
Arguments
- obj {Object} a parts object
Returns {Function}
var func = reconstruct({
isAsync: false,
isGenerator: false,
name: 'name',
params: 'a, b',
body: 'return 1;',
});
MIT