Socket
Socket
Sign inDemoInstall

@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.1 to 0.0.2

11

index.js

@@ -12,3 +12,3 @@ const fs = require('fs');

const notRequire = (t, nodePath) => {
const [ requireArg, ...rest ] = nodePath.node.arguments;
const [requireArg, ...rest] = nodePath.node.arguments;
return nodePath.node.callee.name !== 'require' ||

@@ -20,3 +20,3 @@ rest.length !== 0 ||

module.exports = function({ types: t }) {
module.exports = function ({ types: t }) {
return {

@@ -27,3 +27,3 @@ visitor: {

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

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

const [ specifier ] = node.specifiers;
const [specifier] = node.specifiers;

@@ -71,4 +71,3 @@ return t.identifier(specifier.local.name);

function isDestructuredImportExpression(t, node) {
const [ specifier, ...rest ] = node.specifiers;
return rest.length !== 0 || t.isImportDefaultSpecifier(specifier);
return node.specifiers.length !== 0 && node.specifiers.some(specifier => !t.isImportDefaultSpecifier(specifier));
}

@@ -75,0 +74,0 @@

{
"name": "@hqjs/babel-plugin-transform-json-imports",
"version": "0.0.1",
"version": "0.0.2",
"description": "Transform json imports",

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

@@ -8,1 +8,23 @@ # https://hqjs.org

```
# Transformation
Transforms `.json` imports into inplace definition e.g. having file values.json
```json
{
"a": 1,
"b": 2
}
```
and importing it
```js
import values from './values.json';
// Or with destructure
import {a, b} from './values.json';
```
we will obtain
```js
const values = {a: 1, b: 2};
const {a, b} = {a: 1, b: 2};
```
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