Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
babel-plugin-reshow-object-to-json-parse
Advanced tools
[![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
Readme
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.
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}');
$ npm install babel-plugin-object-to-json-parse -D
or
$ yarn add babel-plugin-object-to-json-parse -D
.babelrc
{
"plugins": ["object-to-json-parse"]
}
minJSONStringSize
(number
, defaults 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
}]
]
}
I just made this plugin for my understanding about AST and babel plugin.
I decided not to support partially JSON expression like below.
Partially JSON expressions such as [notValid, {isValid:true}] ensuring {isValid:true} is transformed.
const data = { bar: invalid_object, foo: 'foo' }
↓
const data = { bar: invalid_object, JSON.parse('{"foo": "foo"}')}
This is because I think most large objects are not partially JSON expressions. JSON.parse() is much faster in the case that object is 10 kB or larger. Converting small object to JSON.parse expression is not meaningful.
I don't care about some backwards compatibilities like this issue.
$ git clone git@github.com:nd-02110114/babel-plugin-object-to-json-parse.git
$ cd babel-plugin-object-to-json-parse
$ yarn install
// example
$ yarn build && yarn example
// test
$ yarn test
FAQs
[![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
The npm package babel-plugin-reshow-object-to-json-parse receives a total of 288 weekly downloads. As such, babel-plugin-reshow-object-to-json-parse popularity was classified as not popular.
We found that babel-plugin-reshow-object-to-json-parse demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.