https://github.com/keyz/babel-plugin-transform-optimize-object-literal
Rewrites object and array literals with JSON.parse calls.
https://github.com/keyz/babel-plugin-transform-optimize-object-literal
Last synced: over 1 year ago
JSON representation
Rewrites object and array literals with JSON.parse calls.
- Host: GitHub
- URL: https://github.com/keyz/babel-plugin-transform-optimize-object-literal
- Owner: keyz
- License: mit
- Created: 2019-11-10T07:28:58.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T06:16:17.000Z (over 3 years ago)
- Last Synced: 2025-03-14T22:56:01.378Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://npmjs.org/package/babel-plugin-transform-optimize-object-literal
- Size: 7.29 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# babel-plugin-transform-optimize-object-literal
[](https://github.com/keyz/babel-plugin-transform-optimize-object-literal/actions "CI Status") [](https://npmjs.org/package/babel-plugin-transform-optimize-object-literal "View on npm")
Because I heard `JSON.parse` is blazing fast https://v8.dev/blog/cost-of-javascript-2019#json
Input:
```javascript
const foo = { a: "3", d: "f" };
const bar = [1, 4, -2, true, false, {}, "ok"];
```
Output:
```javascript
const foo = JSON.parse('{"a":"3","d":"f"}');
const bar = JSON.parse('[1,4,-2,true,false,{},"ok"]');
```
## Usage
```
yarn add -D babel-plugin-transform-optimize-object-literal
```
`.babelrc`:
```json
{
"plugins": [
[
"babel-plugin-transform-optimize-object-literal",
{
"skipArrayOptimizationIfLengthIsBelow": 0,
"skipObjectOptimizationIfLengthIsBelow": 0
}
]
]
}
```