Socket
Socket
Sign inDemoInstall

gulp-edit-xml

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-edit-xml - npm Package Compare versions

Comparing version 3.1.1 to 3.2.0

index.d.ts

33

package.json
{
"name": "gulp-edit-xml",
"version": "3.1.1",
"version": "3.2.0",
"description": "Gulp plugin for editing xml files",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "jest src",
"lint": "eslint src && prettier --check src/*.js"
},
"repository": {

@@ -17,3 +13,4 @@ "type": "git",

"src",
"index.js"
"index.js",
"index.d.ts"
],

@@ -34,17 +31,21 @@ "keywords": [

"dependencies": {
"@types/xml2js": "^0.4.5",
"@types/xml2js": "^0.4.11",
"lodash.defaultsdeep": "^4.6.1",
"lodash.isfunction": "^3.0.6",
"lodash.isfunction": "^3.0.9",
"lodash.isobject": "^3.0.2",
"plugin-error": "^1.0.1",
"xml2js": "^0.4.8"
"plugin-error": "^2.0.1",
"xml2js": "^0.5.0"
},
"devDependencies": {
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.7.0",
"eslint": "^8.38.0",
"eslint-config-prettier": "^8.8.0",
"event-stream": "^4.0.1",
"jest": "^24.9.0",
"prettier": "^1.19.1",
"vinyl": "^2.1.0"
"jest": "^29.5.0",
"prettier": "^2.8.7",
"vinyl": "^3.0.0"
},
"scripts": {
"test": "jest src",
"lint": "eslint src && prettier --check src/*.js"
}
}
}

@@ -8,54 +8,59 @@ const Stream = require('stream');

const xmlEdit = function(transform, options) {
if (!isFunction(transform)) {
transform = function(data) {
return data;
};
}
const xmlEdit = function (transform, options) {
if (!isFunction(transform)) {
transform = function (data) {
return data;
};
}
const defaults = {
parserOptions: {},
builderOptions: {
headless: true,
renderOpts: {
pretty: false
}
}
};
const defaults = {
parserOptions: {},
builderOptions: {
headless: true,
renderOpts: {
pretty: false
}
}
};
const settings = assign(options, defaults);
const settings = assign(options, defaults);
const stream = new Stream.Transform({ objectMode: true });
const stream = new Stream.Transform({ objectMode: true });
stream._transform = function(file, unused, done) {
if (file.isNull()) {
return done(null, file);
}
stream._transform = function (file, unused, done) {
if (file.isNull()) {
return done(null, file);
}
if (file.isStream()) {
return done(new PluginError('gulp-xml-edit', 'Streaming not supported'));
}
if (file.isStream()) {
return done(new PluginError('gulp-xml-edit', 'Streaming not supported'));
}
const content = file.contents.toString('utf-8');
const parser = new xml2js.Parser(settings.parserOptions);
const builder = new xml2js.Builder(settings.builderOptions);
const content = file.contents.toString('utf-8');
const parser = new xml2js.Parser(settings.parserOptions);
const builder = new xml2js.Builder(settings.builderOptions);
parser.parseString(content, function(err, data) {
let content = transform.call(null, data, file);
parser.parseString(content, function (err, data) {
let content = transform.call(null, data, file);
if (!isObject(content)) {
done(new PluginError('gulp-xml-edit', 'transformation does not returns an object'));
return;
}
if (!isObject(content)) {
done(
new PluginError(
'gulp-xml-edit',
'transformation does not returns an object'
)
);
return;
}
content = builder.buildObject(content);
file.contents = new Buffer(content);
content = builder.buildObject(content);
file.contents = new Buffer(content);
return done(null, file);
});
};
return done(null, file);
});
};
return stream;
return stream;
};
module.exports = xmlEdit;

@@ -6,103 +6,105 @@ const xmlEdit = require('./gulp-edit-xml');

describe('gulp-xml-edit', () => {
it('should work in buffer mode', (done) => {
const stream = xmlEdit();
const fakeBuffer = new Buffer('<svg/>');
const fakeFile = new Vinyl({ contents: fakeBuffer });
it('should work in buffer mode', (done) => {
const stream = xmlEdit();
const fakeBuffer = new Buffer('<svg/>');
const fakeFile = new Vinyl({ contents: fakeBuffer });
stream.on('data', (file) => expect(file.contents.toString()).toEqual(fakeBuffer.toString()));
stream.on('end', () => done());
stream.write(fakeFile);
stream.end();
});
stream.on('data', (file) =>
expect(file.contents.toString()).toEqual(fakeBuffer.toString())
);
stream.on('end', () => done());
stream.write(fakeFile);
stream.end();
});
it('should let null files pass through', (done) => {
const stream = xmlEdit();
const fakeFile = new Vinyl({ path: 'null.md', contents: null });
let n = 0;
it('should let null files pass through', (done) => {
const stream = xmlEdit();
const fakeFile = new Vinyl({ path: 'null.md', contents: null });
let n = 0;
stream.pipe(
es.through(
(file) => {
expect(file.path).toBe('null.md');
expect(file.contents).toBe(null);
n++;
},
() => {
expect(n).toBe(1);
done();
}
)
);
stream.pipe(
es.through(
(file) => {
expect(file.path).toBe('null.md');
expect(file.contents).toBe(null);
n++;
},
() => {
expect(n).toBe(1);
done();
}
)
);
stream.write(fakeFile);
stream.end();
});
stream.write(fakeFile);
stream.end();
});
it('should transform as expected', (done) => {
const stream = xmlEdit((data) => {
delete data.svg.g[0].circle[0].$.transform;
return data;
});
const fakeBuffer = new Buffer(
"<svg><g><circle cx='20' cy='20' cr='20' transform='translate(20 20)'/></g></svg>"
);
const fakeFile = new Vinyl({
contents: fakeBuffer
});
let n = 0;
it('should transform as expected', (done) => {
const stream = xmlEdit((data) => {
delete data.svg.g[0].circle[0].$.transform;
return data;
});
const fakeBuffer = new Buffer(
"<svg><g><circle cx='20' cy='20' cr='20' transform='translate(20 20)'/></g></svg>"
);
const fakeFile = new Vinyl({
contents: fakeBuffer
});
let n = 0;
stream.pipe(
es.through(
(file) => {
expect(file.contents.toString()).toBe(
'<svg><g><circle cx="20" cy="20" cr="20"/></g></svg>'
);
n++;
},
() => {
expect(n).toBe(1);
done();
}
)
);
stream.pipe(
es.through(
(file) => {
expect(file.contents.toString()).toBe(
'<svg><g><circle cx="20" cy="20" cr="20"/></g></svg>'
);
n++;
},
() => {
expect(n).toBe(1);
done();
}
)
);
stream.write(fakeFile);
stream.end();
});
stream.write(fakeFile);
stream.end();
});
it('should pass the raw file to the transform', (done) => {
let captured = null;
const stream = xmlEdit((data, file) => {
delete data.svg.g[0].circle[0].$.transform;
captured = file.name;
return data;
});
const fakeBuffer = new Buffer(
"<svg><g><circle cx='20' cy='20' cr='20' transform='translate(20 20)'/></g></svg>"
);
const fakeFile = new Vinyl({
contents: fakeBuffer,
name: 'expected.xml'
});
let n = 0; // eslint-disable-line no-unused-vars
it('should pass the raw file to the transform', (done) => {
let captured = null;
const stream = xmlEdit((data, file) => {
delete data.svg.g[0].circle[0].$.transform;
captured = file.name;
return data;
});
const fakeBuffer = new Buffer(
"<svg><g><circle cx='20' cy='20' cr='20' transform='translate(20 20)'/></g></svg>"
);
const fakeFile = new Vinyl({
contents: fakeBuffer,
name: 'expected.xml'
});
let n = 0; // eslint-disable-line no-unused-vars
stream.pipe(
es.through(
(file) => {
expect(file.contents.toString()).toBe(
'<svg><g><circle cx="20" cy="20" cr="20"/></g></svg>'
);
n++;
},
() => {
expect(captured).not.toBe(null);
expect(captured).toBe('expected.xml');
done();
}
)
);
stream.pipe(
es.through(
(file) => {
expect(file.contents.toString()).toBe(
'<svg><g><circle cx="20" cy="20" cr="20"/></g></svg>'
);
n++;
},
() => {
expect(captured).not.toBe(null);
expect(captured).toBe('expected.xml');
done();
}
)
);
stream.write(fakeFile);
stream.end();
});
stream.write(fakeFile);
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