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

@hqjs/babel-plugin-transform-json-imports

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hqjs/babel-plugin-transform-json-imports - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

18

index.js

@@ -24,3 +24,4 @@ const path = require('path');

if (notRequire(t, nodePath)) return;
const [requireArg] = nodePath.node.arguments;
const { node, parent } = nodePath;
const [requireArg] = node.arguments;
const { value: modName } = requireArg;

@@ -32,3 +33,3 @@ if (notJsonImport(modName)) return;

nodePath.replaceWith(t.valueToNode(json));
nodePath.replaceWith(t.valueToNode(cleanRequiredJSON(t, parent, json)));
},

@@ -92,1 +93,14 @@ ImportDeclaration(nodePath, stats) {

}
function cleanRequiredJSON(t, node, json) {
if (t.isObjectPattern(node.id)) {
const res = {};
for (const property of node.id.properties) {
const { name } = property.key;
if (name in json) res[name] = json[name];
}
return res;
}
return json;
}

2

package.json
{
"name": "@hqjs/babel-plugin-transform-json-imports",
"version": "0.0.3",
"version": "0.0.4",
"description": "Transform json imports",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -34,2 +34,8 @@ # https://hqjs.org

```
or similar expressions with require
```js
const values = require('./values.json');
// Or with destructure
const {a, b} = require('./values.json');
```
we will obtain

@@ -36,0 +42,0 @@ ```js

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