Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-object-to-json-parse

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-object-to-json-parse

[![CircleCI](https://circleci.com/gh/nd-02110114/babel-plugin-object-to-json-parse/tree/master.svg?style=svg)](https://circleci.com/gh/nd-02110114/3dmol-sandbox/tree/master) [![License: MIT](https://img.shields.io/github/license/nd-02110114/babel-plugin-o

  • 0.0.8
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
decreased by-4.09%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-object-to-json-parse 🚀

CircleCI License: MIT npm version

This repository is inspired by this article

As long as the JSON string is only evaluated once, the JSON.parse approach is much faster compared to the JavaScript object literal, especially for cold loads.

Caution!! : I made this plugin for my understanding about AST and babel plugin, so this plugin is not production ready.

Object to JSON.parse

This plugin converts from object literal to JSON.parse (example)

// before
const data = { foo: 42, bar: 1337 };

// after
const data = JSON.parse('{"foo":42,"bar":1337}');

How to use

Install

$ npm install babel-plugin-object-to-json-parse -D
or
$ yarn babel-plugin-object-to-json-parse -D

setup .babelrc

{
  "plugins": ["object-to-json-parse"]
}

Options

minJSONStringSize (number, dafaults to 1024)

The minJSONStringSize option will prevent the plugin from replacing an expression if the length of the JSON string given to JSON.parse is smaller than minJSONStringSize. For example, the following ensures all replacements have a string size of at least 1kb.

{
  "plugins": [
    ["object-to-json-parse", {
      "minJSONStringSize": 1024
    }]
  ]
}

Development

Setup

$ git clone git@github.com:nd-02110114/babel-plugin-object-to-json-parse.git
$ cd babel-plugin-object-to-json-parse
$ yarn install

Tips

// example
$ yarn build && yarn example

// test
$ yarn test

FAQs

Package last updated on 24 Nov 2019

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc