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

derequire

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

derequire - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

5

index.js

@@ -11,3 +11,6 @@ 'use strict';

leave:function(node, parent) {
if (node.type == 'Identifier'&&node.name===tokenFrom){
var isVariableName = node.type === 'Identifier'&&node.name===tokenFrom;
var isArugment = parent && (parent.type === 'FunctionDeclaration' || parent.type === 'FunctionExpression');
var isCall = parent && (parent.type === 'CallExpression' && parent.callee.type === 'Identifier' && parent.callee.name === tokenFrom);
if (isVariableName && (isArugment||isCall)){
node.name = tokenTo;

@@ -14,0 +17,0 @@ }

2

package.json
{
"name": "derequire",
"version": "0.1.0",
"version": "0.2.0",
"description": "remove requires",

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

@@ -13,2 +13,2 @@ derequire

takes a string of code and replaces all instances of the identifier `tokenFrom` (default 'require') and replaces them with tokenTo (default '\_\_derequire\_\_'), returnes the code.
takes a string of code and replaces all instances of the identifier `tokenFrom` (default 'require') and replaces them with tokenTo (default '\_\_derequire\_\_'), returnes the code, but only if they are used as function arguments or if they are called as function.
var should = require('chai').should();
var derequire = require('../');
var exampleText = "var x=function(require,module,exports){var process=require(\"__browserify_process\");var requireText = \"require\";}";
describe('derequire', function(){
it('should work', function(){
var exampleText = "var x=function(require,module,exports){var process=require(\"__browserify_process\");var requireText = \"require\";}";
derequire(exampleText).should.equal("var x=function(__derequire__,module,exports){var process=__derequire__('__browserify_process');var requireText='require'}");
});
it('should only replace arguments and calls',function(){
var exampleText = "function x(require,module,exports){var process=require(\"__browserify_process\");var requireText = {}; requireText.require = \"require\";(function(){var require = 'blah';}())}";
derequire(exampleText).should.equal("function x(__derequire__,module,exports){var process=__derequire__('__browserify_process');var requireText={};requireText.require='require';(function(){var require='blah'}())}");
});
});
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