Socket
Book a DemoInstallSign in
Socket

ast-to-literal

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ast-to-literal

Transform a Babel Expression into a JS value

latest
Source
npmnpm
Version
0.0.5
Version published
Weekly downloads
1.2K
-37.27%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 16 Jun 2021

Did you know?

Socket

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.

Install

Related posts