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.6.0 to 0.6.1

6

index.js

@@ -5,2 +5,4 @@ 'use strict';

var esrefactor = require('esrefactor');
var requireRegexp = /require.*\(.*['"]/m;
function testParse (code) {

@@ -12,2 +14,4 @@ try{

function rename(code, tokenTo, tokenFrom) {
if (!requireRegexp.test(code)) return code;
tokenTo = tokenTo || '_dereq_';

@@ -23,3 +27,3 @@ tokenFrom = tokenFrom || 'require';

}
var ctx = new esrefactor.Context(inCode);;
var ctx = new esrefactor.Context(inCode);

@@ -26,0 +30,0 @@ estraverse.traverse(ast,{

2

package.json
{
"name": "derequire",
"version": "0.6.0",
"version": "0.6.1",
"description": "remove requires",

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

@@ -10,3 +10,3 @@ derequire

var derequire = require('derequire');
var transformedCode = derequire(code [,tokenTo='_dereq_', tokenFrom='require');
var transformedCode = derequire(code, /*tokenTo=*/'_dereq_', /*tokenFrom=*/'require');
```

@@ -13,0 +13,0 @@

@@ -26,14 +26,25 @@ var should = require('chai').should();

});
it('should work with whitespace inside require statement', function(){
var exampleText = 'var x=function(require,module,exports){var process=require( "__browserify_process" )}';
derequire(exampleText).should.equal('var x=function(_dereq_,module,exports){var process=_dereq_( "__browserify_process" )}');
});
it('should work with single quoted requires', function(){
var exampleText = 'var x=function(require,module,exports){var process=require(\'__browserify_process\')}';
derequire(exampleText).should.equal('var x=function(_dereq_,module,exports){var process=_dereq_(\'__browserify_process\')}');
});
it('should throw an error if you try to change things of different sizes', function(){
should.throw(function(){
derequire('lalalalla', 'la');
derequire('require("x")', 'lalalalla', 'la');
});
});
it("should return the code back if it can't parse it", function(){
it("should return notthe code back if it can't parse it", function(){
derequire("/*").should.equal("/*");
});
it("should return the code back if it can't parse it and it has a require", function(){
derequire("/*require('").should.equal("/*require('");
});
it('should work on something big', function(done){
fs.readFile('./test/pouchdb.js', {encoding:'utf8'}, function(err, data){
if(err){
done(err);
return done(err);
}

@@ -40,0 +51,0 @@ var transformed = derequire(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