Socket
Socket
Sign inDemoInstall

gulp-css-background-remove

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-css-background-remove - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

43

index.js

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

var fs = require('fs');
var extend = require('util')._extend;
var File = require('vinyl');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
module.exports = function (opts) {
return through.obj(function (file, enc, cb) {
opts = extend({
filename: 'image.css',
dest: '',
writeImagesFile: true,
regex: /.*(url\((["|']?.+["|']?)?\))+.*/g
}, opts);
var imagesContent;
var throughObj = through.obj(function (file, enc, cb) {
if (file.isNull()) {

@@ -51,3 +63,3 @@ cb(null, file);

// Search regex to separate out elements
var regex = opts.regex || /.*(url\((["|']?.+["|']?)?\))+.*/g;
var regex = opts.regex;

@@ -92,6 +104,9 @@ // Empty stylesheet or broken

// Write images file
fs.writeFileSync(
path.join((opts.dest || ''), (opts.filename || 'image.css')),
stylesheets.images
);
if (opts.writeImagesFile) {
fs.writeFileSync(
path.join(opts.dest, opts.filename),
stylesheets.images
);
}
imagesContent = stylesheets.images;

@@ -103,2 +118,18 @@ // Return rules file

});
return extend(throughObj, {
images: function (callback) {
throughObj.on('finish', function () {
var imagesFile = new File({
contents: new Buffer(imagesContent)
});
callback(
imagesFile
.pipe(source(opts.filename))
.pipe(buffer())
);
});
return throughObj;
}
});
};

6

package.json
{
"name": "gulp-css-background-remove",
"version": "1.1.0",
"version": "1.2.0",
"description": "Remove `background-image` from CSS file to load asynchron",

@@ -29,5 +29,7 @@ "main": "index.js",

"devDependencies": {
"mocha": "*"
"mocha": "*",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
},
"license": "MIT"
}

@@ -49,1 +49,21 @@ /* eslint-env mocha */

});
it('should be possible to get a stream from the image properties', function (cb) {
var stream = cssBackgroundRemove({
writeImagesFile: false
});
stream.images(function (imagesStream) {
imagesStream.on('data', function (file) {
assert(file.contents.toString(), 'div {\n\tbackground-image: url(image.png);\n}');
})
});
stream.on('data', function (file) {
assert(file.contents.toString(), 'a {\n\tbackground: #ddd; color: #ddd;\n}\na {\n\tcolor: #fff;\n}');
});
stream.on('end', cb);
stream.write(generateFile('a {\n\tbackground: #ddd; color: #ddd;\n}\na {\n\tcolor: #fff;\n}\ndiv {\n\tbackground-image: url(image.jpg);\n}'));
stream.end();
});
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