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.5.0 to 0.5.1

17

index.js

@@ -5,3 +5,8 @@ 'use strict';

var esrefactor = require('esrefactor');
function rename(code, tokenTo, tokenFrom){
function testParse (code) {
try{
return esprima.parse(code,{range:true});
}catch(e){}
}
function rename(code, tokenTo, tokenFrom) {
tokenTo = tokenTo || '_dereq_';

@@ -12,5 +17,9 @@ tokenFrom = tokenFrom || 'require';

}
var inCode = '!function(){'+code+'}';
var inCode = '!function(){'+code+'\n;}';
var ast = testParse(inCode);
if(!ast){
return code;
}
var ctx = new esrefactor.Context(inCode);;
var ast = esprima.parse(inCode,{range:true});
estraverse.traverse(ast,{

@@ -28,3 +37,3 @@ enter:function(node, parent) {

});
return ctx._code.slice(12, -1);
return ctx._code.slice(12, -3);
}

@@ -31,0 +40,0 @@

{
"name": "derequire",
"version": "0.5.0",
"version": "0.5.1",
"description": "remove requires",

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

@@ -22,2 +22,6 @@ var should = require('chai').should();

});
it('should work with a comment on the end', function(){
var exampleText = 'var x=function(require,module,exports){var process=require("__browserify_process");var requireText = "require";}//lala';
derequire(exampleText).should.equal('var x=function(_dereq_,module,exports){var process=_dereq_("__browserify_process");var requireText = "require";}//lala');
});
it('should throw an error if you try to change things of different sizes', function(){

@@ -28,2 +32,5 @@ should.throw(function(){

});
it("should return the code back if it can't parse it", function(){
derequire("/*").should.equal("/*");
});
it('should work on something big', function(done){

@@ -30,0 +37,0 @@ fs.readFile('./test/pouchdb.js', {encoding:'utf8'}, function(err, data){

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