Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hypervillain/ast-to-literal

Transform a Babel ObjectExpression into a JS object
https://github.com/hypervillain/ast-to-literal

Last synced: about 2 months ago
JSON representation

Transform a Babel ObjectExpression into a JS object

Awesome Lists containing this project

README

        

# ast-to-literal

Transform a Babel Expression into a JS object.

----

code example:

```javascript
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 ✌️