0.0.5 • Published 3 years ago

ast-to-literal v0.0.5

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

ast-to-literal

Transform a Babel Expression into a JS object.


code example:

const t = require('@babel/types')
const equal = require('deep-equal')

const toJs = require('ast-to-literal')

const obj = { key: 'value' }
const astObject = t.objectExpression([
  t.objectProperty(t.identifier('key'), t.stringLiteral('value'))
])

console.log(equal(obj, toJs(astObject))) // true

Supported value types:

  • BooleanLiteral
  • StringLiteral
  • NumericLiteral
  • ObjectExpression
  • ArrayExpression
  • null (stripped from object)
  • undefined (stripped from object too)

It could support other value types as long as they don't need any sort of computation.

Feel free to file an issue if you use this package and need more ou of it ✌️