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

rewrite-imports

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rewrite-imports - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

31

dist/rewrite-imports.es5.js

@@ -6,29 +6,28 @@ 'use strict';

function alias(key) {
key = key.trim();
var name = key.split(' as ');
(name.length > 1) && (key=name.shift());
return { key: key, name: name[0] };
function destruct(keys, target) {
var tmp, out=[];
while (keys.length) {
tmp = keys.shift().trim().split(' as ');
out.push(tmp.join(':'));
}
return ("const { " + (out.join(', ')) + " } = " + target + ";");
}
function generate(keys, dep, base, fn) {
var tmp = base || (dep.split('/').pop().replace(/\W/g, '_') + '$' + num++); // uniqueness
var name = base || alias(tmp).name;
dep = fn + "('" + dep + "')";
var obj;
var out = "const " + name + " = " + dep + ";";
if (keys.length && !base) {
return destruct(keys, dep);
}
keys.forEach(function (key) {
obj = alias(key);
out += "\nconst " + (obj.name) + " = " + tmp + "." + (obj.key) + ";";
});
var out = "const " + base + " = " + dep + ";";
if (keys.length) {
out += '\n' + destruct(keys, base);
}
return out;
}
var num;
module.exports = function (str, fn) {
num = 0;
fn = fn || 'require';

@@ -35,0 +34,0 @@ return str

@@ -6,29 +6,28 @@ 'use strict';

function alias(key) {
key = key.trim();
let name = key.split(' as ');
(name.length > 1) && (key=name.shift());
return { key, name: name[0] };
function destruct(keys, target) {
let tmp, out=[];
while (keys.length) {
tmp = keys.shift().trim().split(' as ');
out.push(tmp.join(':'));
}
return `const { ${ out.join(', ')} } = ${target};`;
}
function generate(keys, dep, base, fn) {
const tmp = base || (dep.split('/').pop().replace(/\W/g, '_') + '$' + num++); // uniqueness
const name = base || alias(tmp).name;
dep = `${fn}('${dep}')`;
let obj;
let out = `const ${name} = ${dep};`;
if (keys.length && !base) {
return destruct(keys, dep);
}
keys.forEach(key => {
obj = alias(key);
out += `\nconst ${obj.name} = ${tmp}.${obj.key};`;
});
let out = `const ${base} = ${dep};`;
if (keys.length) {
out += '\n' + destruct(keys, base);
}
return out;
}
let num;
module.exports = function (str, fn) {
num = 0;
fn = fn || 'require';

@@ -35,0 +34,0 @@ return str

{
"name": "rewrite-imports",
"version": "2.0.0",
"version": "2.0.1",
"repository": "lukeed/rewrite-imports",

@@ -5,0 +5,0 @@ "description": "Rewrite `import` statements as `require()`s; via RegExp",

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