New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

connect-inject

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-inject - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

15

index.js

@@ -30,4 +30,4 @@ module.exports = function inject(opt) {

var runAll = opt.runAll || false;
// helper functions

@@ -68,7 +68,11 @@ var regex = (function() {

rules.some(function(rule) {
if (rule.match.test(body)) {
_body = body.replace(rule.match, function(w) {
return rule.fn(w, snippet);
if (rule.match.test(_body)) {
_body = _body.replace(rule.match, function(w) {
return rule.fn(w, rule.snippet|| snippet);
});
return true;
if (runAll === false) {
return true;
} else {
return false;
}
}

@@ -101,3 +105,2 @@ return false;

if (res.inject) return next();
res.inject = true;

@@ -104,0 +107,0 @@ var writeHead = res.writeHead;

2

package.json
{
"name": "connect-inject",
"description": "connect middleware for adding any script to the response",
"version": "0.3.2",
"version": "0.4.0",
"author": "Daniel Duches <iridiumweb@gmail.com>",

@@ -6,0 +6,0 @@ "email":"iridiumweb@gmail.com",

@@ -24,4 +24,3 @@ connect-inject

```
snippet now accepts either string or an array which will be inserted at the bottom of the page by default.
snippet now accepts either string or an array.
## connect/express example

@@ -113,2 +112,31 @@ ```javascript

#### multiple injections
You can also do multiple injections by defining a snippet inside of a rule and setting the `runAll` option to true
```javascript
{
runAll: true,
rules: [
{
match: /<head>/ig,
snippet: '<script src="/top_file.js"></script>',
fn: function(w, s) {
return w + s;
}
},
{
match: /<script .* src=".*\.test\.js"><\/script>/ig,
snippet: [
'<script src="/bottomFile1.js"></script>',
'<script src="/bottomFile2.js"></script>',
'<script src="/src-test/testUtils.js"></script>'
]
fn: function(w, s) {
return s + w;
}
}
]
}
```
credits

@@ -122,1 +150,5 @@ =======

[MIT License](https://github.com/intesso/connect-livereload/blob/master/LICENSE)
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/danielhq/connect-inject/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
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