Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@helpdotcom/build-ast
Advanced tools
Make build AST nodes easy
$ npm install [--save] @helpdotcom/build-ast
$ npm test
'use strict'
const B = require('@helpdotcom/build-ast')
const toCode = require('escodegen').generate
// 'use strict'
const b = B().use('strict')
// `typeof opts.name`
const left = B.typeof('opts.name')
// `'string'`
const right = B.string('string')
// `typeof opts.name !== 'string'`
const check = B.notEquals(left, right)
// new TypeError('name must be a string')
const error = B.TypeError('name must be a string')
// const er = new TypeError('name must be a string')
// return setImmediate(cb, er)
const errorBlock = B()
.declare('const', 'er', error)
.returns(
B.callFunction('setImmediate', [
B.id('cb')
, B.id('er')
])
).build()
// if (typeof opts.name !== 'string') {
// const er = new TypeError('name must be a string')
// return setImmediate(cb, er)
// }
const block = B()
block.if(check, B.block(errorBlock))
block.returns(
B.callFunction('setImmediate', [
B.id('cb')
, B.ast.literal(null)
, B.id('opts')
])
)
// module.exports = function validate(opts, cb) {}
b.module(B.function('validate', ['opts', 'cb'], block.build()))
console.log(toCode(b.program()))
which will print out:
'use strict';
module.exports = function validate(opts, cb) {
if (typeof opts.name !== 'string') {
const er = new TypeError('name must be a string')
return setImmediate(cb, er)
}
return setImmediate(cb, null, opts)
}
See DOCS.md
Evan Lucas
MIT (See LICENSE
for more info)
FAQs
Make building AST nodes easy
The npm package @helpdotcom/build-ast receives a total of 1 weekly downloads. As such, @helpdotcom/build-ast popularity was classified as not popular.
We found that @helpdotcom/build-ast demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 19 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.