Socket
Socket
Sign inDemoInstall

ast-to-literal

Package Overview
Dependencies
487
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ast-to-literal

Transform a Babel Expression into a JS value


Version published
Weekly downloads
1.8K
increased by6.57%
Maintainers
1
Install size
42.7 MB
Created
Weekly downloads
 

Readme

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

Last updated on 16 Jun 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc