Socket
Socket
Sign inDemoInstall

gulp-edit-xml

Package Overview
Dependencies
18
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 3.1.0

src/gulp-edit-xml.js

63

index.js

@@ -1,62 +0,1 @@

const Stream = require('stream');
const xml2js = require('xml2js');
const isFunction = require('lodash.isfunction');
const isObject = require('lodash.isobject');
const assign = require('object-assign');
const PluginError = require('plugin-error');
const xmlEdit = function(transform, options) {
if (!isFunction(transform)) {
transform = function(data) {
return data;
};
}
const defaults = {
parserOptions: {},
builderOptions: {
headless: true,
renderOpts: {
pretty: false
}
}
};
const settings = assign(defaults, options);
const stream = new Stream.Transform({ objectMode: true });
stream._transform = function(file, unused, done) {
const that = this;
if (file.isNull()) {
return done(null, file);
}
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);
parser.parseString(content, function(err, data) {
let content = transform.call(null, data);
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);
return done(null, file);
});
};
return stream;
};
module.exports = xmlEdit;
module.exports = require("./src/gulp-edit-xml");
{
"name": "gulp-edit-xml",
"version": "3.0.0",
"description": "Gulp plugin for editing xml files",
"main": "index.js",
"scripts": {
"test": "jasmine-node test/edit-xml-spec.js"
},
"repository": {
"type": "git",
"url": "https://github.com/vkbansal/gulp-edit-xml.git"
},
"keywords": [
"gulp",
"plugin",
"gulpplugin",
"xml",
"svg"
],
"author": "Vivek Kumar Bansal <contact@vkbansal.me>",
"license": "MIT",
"bugs": {
"url": "https://github.com/vkbansal/gulp-edit-xml/issues"
},
"homepage": "https://github.com/vkbansal/gulp-edit-xml",
"dependencies": {
"lodash.isfunction": "^3.0.6",
"lodash.isobject": "^3.0.2",
"object-assign": "^4.0.1",
"plugin-error": "^0.1.2",
"xml2js": "^0.4.8"
},
"devDependencies": {
"event-stream": "^3.3.1",
"jasmine-node": "^1.14.5",
"vinyl": "^2.1.0"
}
"name": "gulp-edit-xml",
"version": "3.1.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": {
"type": "git",
"url": "https://github.com/vkbansal/gulp-edit-xml.git"
},
"files": [
"src",
"index.js"
],
"keywords": [
"gulp",
"plugin",
"gulpplugin",
"xml",
"svg"
],
"author": "Vivek Kumar Bansal <contact@vkbansal.me>",
"license": "MIT",
"bugs": {
"url": "https://github.com/vkbansal/gulp-edit-xml/issues"
},
"homepage": "https://github.com/vkbansal/gulp-edit-xml",
"dependencies": {
"@types/xml2js": "^0.4.5",
"lodash.isfunction": "^3.0.6",
"lodash.isobject": "^3.0.2",
"plugin-error": "^1.0.1",
"xml2js": "^0.4.8"
},
"devDependencies": {
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.7.0",
"event-stream": "^4.0.1",
"jest": "^24.9.0",
"lodash.defaultsdeep": "^4.6.1",
"prettier": "^1.19.1",
"vinyl": "^2.1.0"
}
}

@@ -1,2 +0,5 @@

[![NPM version](https://badge.fury.io/js/gulp-edit-xml.svg)](http://badge.fury.io/js/gulp-edit-xml) [![Build Status](https://travis-ci.org/vkbansal/gulp-edit-xml.svg?branch=master)](https://travis-ci.org/vkbansal/gulp-edit-xml) [![Dependencies](https://david-dm.org/vkbansal/gulp-edit-xml.png)](https://david-dm.org/vkbansal/gulp-edit-xml) [![devDependency Status](https://david-dm.org/vkbansal/gulp-edit-xml/dev-status.svg)](https://david-dm.org/vkbansal/gulp-edit-xml#info=devDependencies)
[![NPM version](https://badge.fury.io/js/gulp-edit-xml.svg)](http://badge.fury.io/js/gulp-edit-xml)
[![Build Status](https://github.com/vkbansal/gulp-edit-xml/workflows/master/badge.svg)](https://travis-ci.org/vkbansal/gulp-edit-xml)
[![Dependencies](https://david-dm.org/vkbansal/gulp-edit-xml.png)](https://david-dm.org/vkbansal/gulp-edit-xml)
[![devDependency Status](https://david-dm.org/vkbansal/gulp-edit-xml/dev-status.svg)](https://david-dm.org/vkbansal/gulp-edit-xml#info=devDependencies)

@@ -29,33 +32,33 @@ # gulp-edit-xml

var gulp = require('gulp'),
svgo = require('gulp-svgo'),
xmlEdit = require('gulp-edit-xml');
svgo = require('gulp-svgo'),
xmlEdit = require('gulp-edit-xml');
gulp.task('svg', function() {
gulp
.src('src/img/main.svg')
.pipe(svgo())
.pipe(
xmlEdit(function(xml) {
var nodes = xml.svg.g[0].circle;
for (var i = 0, l = nodes.length; i < l; i++) {
var cn = nodes[i].$;
if (cn.hasOwnProperty('transform')) {
var transforms = cn.transform.match(/translate\(([\d\s\-\.]+)\)/)[1];
transforms = transforms.split(' ');
cn.cx = parseInt(cn.cx) + parseInt(transforms[0]);
cn.cx = Math.round(cn.cx * 10) / 10;
if (transforms.length == 2) {
cn.cy = parseInt(cn.cy) + parseInt(transforms[1]);
cn.cy = Math.round(cn.cy * 10) / 10;
}
delete cn.transform;
delete cn.fill;
}
nodes[i].$ = cn;
}
xml.svg.g[0].circle = nodes;
return xml;
})
)
.pipe(gulp.dest('dist/img/'));
gulp
.src('src/img/main.svg')
.pipe(svgo())
.pipe(
xmlEdit(function(xml) {
var nodes = xml.svg.g[0].circle;
for (var i = 0, l = nodes.length; i < l; i++) {
var cn = nodes[i].$;
if (cn.hasOwnProperty('transform')) {
var transforms = cn.transform.match(/translate\(([\d\s\-\.]+)\)/)[1];
transforms = transforms.split(' ');
cn.cx = parseInt(cn.cx) + parseInt(transforms[0]);
cn.cx = Math.round(cn.cx * 10) / 10;
if (transforms.length == 2) {
cn.cy = parseInt(cn.cy) + parseInt(transforms[1]);
cn.cy = Math.round(cn.cy * 10) / 10;
}
delete cn.transform;
delete cn.fill;
}
nodes[i].$ = cn;
}
xml.svg.g[0].circle = nodes;
return xml;
})
)
.pipe(gulp.dest('dist/img/'));
});

@@ -68,12 +71,17 @@ ```

```js
xmlEdit(transform, options, file);
```
xmlEdit(transform,options)
```
**transform:** A function that can be used to do manual operations. It takes one argument: The `xml` as an object. _Remember to return the object at end_.
**transform:** A function that can be used to do manual operations. It takes two arguments:
- The `xml` as an object.
- The original raw file
_Remember to return the object at end_.
default:
```js
function(data){
function(data, file){
return data;

@@ -80,0 +88,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc