Socket
Socket
Sign inDemoInstall

gulp-dom

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-dom - npm Package Compare versions

Comparing version 0.9.17 to 1.0.0

47

lib/dom.js

@@ -5,42 +5,27 @@ /* jshint node: true, strict: true */

var jsdom = require("jsdom");
var PluginError = require('plugin-error');
var through2 = require("through2");
var pluginName = "gulp-dom";
var jsdom = require("jsdom"),
utils = require("gulp-util"),
PluginError = utils.PluginError,
through2 = require("through2"),
pluginName = "gulp-dom";
module.exports = function (mutator) {
var stream = through2.obj(function(file, enc, callback) {
if (file.isNull()) {
return callback(null, file);
}
if (file.isNull()) {
return callback(null, file);
}
if (file.isStream()) {
return stream.emit("error", new PluginError(pluginName, "Streaming not supported"));
}
if (file.isStream()) {
return stream.emit("error", new PluginError(pluginName, "Streaming not supported"));
}
if (file.isBuffer()) {
if (file.isBuffer()) {
var dom = new jsdom.JSDOM(file.contents.toString("utf8"));
var mutated = mutator.call(dom.window.document);
jsdom.env({
html: file.contents.toString("utf8"),
done: function (errors, window) {
if (errors) {
return stream.emit("error", new PluginError(pluginName, "Error parsing document: " + file.path));
}
file.contents = Buffer.from(typeof mutated === 'string' ? mutated : dom.serialize());
callback(null, file);
var mutated = mutator.call(window.document);
file.contents = new Buffer(typeof mutated === 'string' ? mutated : jsdom.serializeDocument(mutated));
callback(null, file);
window.close();
}
});
dom.window.close();
}
});

@@ -47,0 +32,0 @@

{
"name": "gulp-dom",
"version": "0.9.17",
"version": "1.0.0",
"description": "Gulp plugin for generic DOM manipulation",

@@ -27,16 +27,16 @@ "main": "lib/dom.js",

"devDependencies": {
"jshint": "2.9.4",
"mocha": "3.1.2",
"request": "2.79.0",
"jshint": "2.9.6",
"mocha": "5.2.0",
"request": "2.88.0",
"dom-whitespace": "0.1.2",
"vinyl-source-stream": "1.1.0",
"vinyl-buffer": "1.0.0",
"chai": "3.5.0",
"gulp": "3.9.1"
"vinyl-source-stream": "2.0.0",
"vinyl-buffer": "1.0.1",
"chai": "4.2.0",
"gulp": "4.0.0"
},
"dependencies": {
"jsdom": "9.8.3",
"gulp-util": "3.0.7",
"through2": "2.0.1"
"jsdom": "12.2.0",
"plugin-error": "1.0.1",
"through2": "2.0.3"
}
}

@@ -7,4 +7,4 @@ # gulp-dom

This [Gulp](http://gulpjs.com/) plugin is a simple wrapper around
[jsdom](https://github.com/tmpvar/jsdom) making it possible to run DOM
This [Gulp](http://gulpjs.com/) plugin is a simple wrapper around
[jsdom](https://github.com/tmpvar/jsdom) making it possible to run DOM
operations on any inbound HTML.

@@ -22,3 +22,2 @@

## Installation

@@ -31,22 +30,5 @@

### Note
[Jsdom version 6.0.0](https://github.com/tmpvar/jsdom/blob/master/Changelog.md#600)
require io.js version 2.0.0 or newer. Version 0.6.0 of this
plugin depend on [jsdom version 6.0.0](https://github.com/tmpvar/jsdom/blob/master/Changelog.md#600)
and therefor require io.js version 2.0.0 or newer.
[Jsdom version 4.0.0](https://github.com/tmpvar/jsdom/blob/master/Changelog.md#400)
does not support Node.js™ and requires io.js. Version 0.4.0 of this
plugin depend on [jsdom version 4.0.0](https://github.com/tmpvar/jsdom/blob/master/Changelog.md#400)
and therefor require io.js.
For a working version of this plugin which works with Node.js™, please use
version 0.3.x or older.
## Basic example
Example on adding a `data` attribute with a version number on the `body` tag of
Example on adding a `data` attribute with a version number on the `body` tag of
a HTML document:

@@ -68,3 +50,2 @@

## Usage

@@ -82,6 +63,6 @@

The plugin will take the provided HTML and parse it into a DOM document. The DOM
The plugin will take the provided HTML and parse it into a DOM document. The DOM
document is then set as `this` on the mutator function.
A value must be returned by the mutator function and it is this returned value
A value must be returned by the mutator function and it is this returned value
which will be passed on to the next step in the gulp chain.

@@ -101,3 +82,3 @@

By default it is expected that the mutator function returns a DOM document, but
By default it is expected that the mutator function returns a DOM document, but
any `String` value can be returned. If the default is being used, the returned

@@ -107,7 +88,6 @@ DOM document will be serialized into a HTML document.

If the mutator function shall return something else than a DOM document its
important that serialization is turned off. Please see the
important that serialization is turned off. Please see the
[serialize attribute](#serialize) for further information.
### serialize

@@ -138,15 +118,13 @@

## A note on jsdom
This plugin wraps [jsdom](https://github.com/tmpvar/jsdom). Though, this plugin
does not enable all features provided by jsdom. The sole purpose for jsdom in
does not enable all features provided by jsdom. The sole purpose for jsdom in
this plugin is to parse a HTML document into a DOM so we can run operations on
it.
Features such as injecting scripts into the DOM which jsdom can do is not
Features such as injecting scripts into the DOM which jsdom can do is not
enabled in this plugin.
## Tests

@@ -158,8 +136,7 @@

Tests are written in [mocha](http://visionmedia.github.io/mocha/).
Tests are written in [mocha](http://mochajs.org/).
## License
## License
The MIT License (MIT)

@@ -166,0 +143,0 @@

@@ -6,6 +6,4 @@ /* jshint node: true, strict: true */

var mocha = require('mocha'),
assert = require('chai').assert,
utils = require('gulp-util'),
jsdom = require('jsdom'),
var assert = require('chai').assert,
Vinyl = require('vinyl'),
dom = require('../');

@@ -16,7 +14,7 @@

function createFixture(markup) {
return new utils.File({
return new Vinyl({
cwd: './',
base: './',
path: './',
contents: new Buffer(markup)
contents: Buffer.from(markup)
});

@@ -34,4 +32,4 @@ }

var mockFile = {
isNull: function() {
return true;
isNull: function() {
return true;
}

@@ -51,10 +49,10 @@ };

var mockFile = {
isNull: function () {
return false;
isNull: function () {
return false;
},
isStream: function () {
return true;
isStream: function () {
return true;
}
};
stream.on('error', function (err) {

@@ -64,3 +62,3 @@ assert.equal(err.message, 'Streaming not supported');

});
stream.write(mockFile);

@@ -67,0 +65,0 @@ });

Sorry, the diff of this file is not supported yet

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