Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/hypervillain/ast-to-literal
- Owner: hypervillain
- Created: 2020-04-25T21:25:22.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T04:25:02.000Z (almost 2 years ago)
- Last Synced: 2024-11-01T19:35:59.760Z (2 months ago)
- Language: JavaScript
- Size: 851 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
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 ✌️