Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svg-pathdata

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-pathdata - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

53

package.json
{
"name": "svg-pathdata",
"version": "1.0.0",
"description": "SVG Path Datas parsing",
"version": "1.0.1",
"description": "Parse, transform and encode SVG Path Data.",
"main": "src/SVGPathData.js",

@@ -24,4 +24,3 @@ "scripts": {

"writer",
"stream",
"browserify"
"stream"
],

@@ -34,30 +33,30 @@ "author": "Nicolas Froidure",

"engines": {
"node": "0.10.*"
"node": ">= 0.10.0"
},
"dependencies": {
"readable-stream": "~1.0.26-3"
"readable-stream": "~2.0.1"
},
"devDependencies": {
"mocha": "~1.18.2",
"mocha-lcov-reporter": "0.0.1",
"coveralls": "~2.10.0",
"istanbul": "~0.2.6",
"karma": "~0.12.1",
"karma-chrome-launcher": "~0.1.2",
"karma-firefox-launcher": "~0.1.3",
"karma-opera-launcher": "~0.1.0",
"grunt": "~0.4.4",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-jshint": "~0.9.2",
"grunt-browserify": "~2.0.1",
"grunt-parallel": "~0.3.1",
"grunt-karma": "~0.8.2",
"karma-mocha": "~0.1.3",
"karma-chai": "0.1.0",
"karma-sinon": "1.0.3",
"matchdep": "~0.3.0",
"chai": "~1.9.1",
"rimraf": "~2.2.6"
"mocha": "^2.2.5",
"mocha-lcov-reporter": "^0.0.2",
"coveralls": "^2.11.2",
"istanbul": "^0.3.16",
"karma": "^0.12.37",
"karma-chrome-launcher": "^0.2.0",
"karma-firefox-launcher": "^0.1.6",
"karma-opera-launcher": "^0.1.0",
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-contrib-jshint": "^0.11.2",
"grunt-browserify": "^3.8.0",
"grunt-parallel": "^0.4.1",
"grunt-karma": "^0.11.1",
"karma-mocha": "^0.2.0",
"karma-chai": "^0.1.0",
"karma-sinon": "^1.0.4",
"matchdep": "^0.3.0",
"chai": "^3.0.0",
"rimraf": "^2.4.0"
}
}
# SVGPathData
> Manipulating SVG path datas (path[d] attribute content) simply and efficiently.
> Manipulating SVG path data (path[d] attribute content) simply and efficiently.
[![NPM version](https://badge.fury.io/js/svg-pathdata.png)](https://npmjs.org/package/svg-pathdata) [![Build status](https://secure.travis-ci.org/nfroidure/SVGPathData.png)](https://travis-ci.org/nfroidure/SVGPathData) [![Dependency Status](https://david-dm.org/nfroidure/SVGPathData.png)](https://david-dm.org/nfroidure/SVGPathData) [![devDependency Status](https://david-dm.org/nfroidure/SVGPathData/dev-status.png)](https://david-dm.org/nfroidure/SVGPathData#info=devDependencies) [![Coverage Status](https://coveralls.io/repos/nfroidure/SVGPathData/badge.png?branch=master)](https://coveralls.io/r/nfroidure/SVGPathData?branch=master)
[![NPM version](https://badge.fury.io/js/svg-pathdata.svg)](https://npmjs.org/package/svg-pathdata) [![Build status](https://secure.travis-ci.org/nfroidure/SVGPathData.svg)](https://travis-ci.org/nfroidure/SVGPathData) [![Dependency Status](https://david-dm.org/nfroidure/SVGPathData.svg)](https://david-dm.org/nfroidure/SVGPathData) [![devDependency Status](https://david-dm.org/nfroidure/SVGPathData/dev-status.svg)](https://david-dm.org/nfroidure/SVGPathData#info=devDependencies) [![Coverage Status](https://coveralls.io/repos/nfroidure/SVGPathData/badge.svg?branch=master)](https://coveralls.io/r/nfroidure/SVGPathData?branch=master)

@@ -93,3 +93,3 @@ ## Including the library

// }
// {

@@ -153,3 +153,3 @@ // "type": SVGPathData.CLOSE_PATH

// "L10 60"
encoder.write({"type": SVGPathData.CLOSE_PATH});

@@ -156,0 +156,0 @@ // "Z"

@@ -5,10 +5,10 @@ // Encode SVG PathData

// Access to SVGPathData constructor
var SVGPathData = require('./SVGPathData.js')
var SVGPathData = require('./SVGPathData.js');
// TransformStream inherance required modules
, TransformStream = require('readable-stream').Transform
, util = require('util')
var TransformStream = require('readable-stream').Transform;
var util = require('util');
// Private consts : Char groups
, WSP = ' ';
var WSP = ' ';

@@ -51,47 +51,47 @@ // Inherit of writeable stream

} else if(commands[i].type === SVGPathData.HORIZ_LINE_TO) {
str += (commands[i].relative?'h':'H')
+ commands[i].x;
str += (commands[i].relative?'h':'H') +
commands[i].x;
// Vertical move to command
} else if(commands[i].type === SVGPathData.VERT_LINE_TO) {
str += (commands[i].relative?'v':'V')
+ commands[i].y;
str += (commands[i].relative?'v':'V') +
commands[i].y;
// Move to command
} else if(commands[i].type === SVGPathData.MOVE_TO) {
str += (commands[i].relative?'m':'M')
+ commands[i].x + WSP + commands[i].y;
str += (commands[i].relative?'m':'M') +
commands[i].x + WSP + commands[i].y;
// Line to command
} else if(commands[i].type === SVGPathData.LINE_TO) {
str += (commands[i].relative?'l':'L')
+ commands[i].x + WSP + commands[i].y;
str += (commands[i].relative?'l':'L') +
commands[i].x + WSP + commands[i].y;
// Curve to command
} else if(commands[i].type === SVGPathData.CURVE_TO) {
str += (commands[i].relative?'c':'C')
+ commands[i].x2 + WSP + commands[i].y2
+ WSP + commands[i].x1 + WSP + commands[i].y1
+ WSP + commands[i].x + WSP + commands[i].y;
str += (commands[i].relative?'c':'C') +
commands[i].x2 + WSP + commands[i].y2 +
WSP + commands[i].x1 + WSP + commands[i].y1 +
WSP + commands[i].x + WSP + commands[i].y;
// Smooth curve to command
} else if(commands[i].type === SVGPathData.SMOOTH_CURVE_TO) {
str += (commands[i].relative?'s':'S')
+ commands[i].x2 + WSP + commands[i].y2
+ WSP + commands[i].x + WSP + commands[i].y;
str += (commands[i].relative?'s':'S') +
commands[i].x2 + WSP + commands[i].y2 +
WSP + commands[i].x + WSP + commands[i].y;
// Quadratic bezier curve to command
} else if(commands[i].type === SVGPathData.QUAD_TO) {
str += (commands[i].relative?'q':'Q')
+ commands[i].x1 + WSP + commands[i].y1
+ WSP + commands[i].x + WSP + commands[i].y;
str += (commands[i].relative?'q':'Q') +
commands[i].x1 + WSP + commands[i].y1 +
WSP + commands[i].x + WSP + commands[i].y;
// Smooth quadratic bezier curve to command
} else if(commands[i].type === SVGPathData.SMOOTH_QUAD_TO) {
str += (commands[i].relative?'t':'T')
+ commands[i].x + WSP + commands[i].y;
str += (commands[i].relative?'t':'T') +
commands[i].x + WSP + commands[i].y;
// Elliptic arc command
} else if(commands[i].type === SVGPathData.ARC) {
str += (commands[i].relative?'a':'A')
+ commands[i].rX + WSP + commands[i].rY
+ WSP + commands[i].xRot
+ WSP + commands[i].lArcFlag + WSP + commands[i].sweepFlag
+ WSP + commands[i].x + WSP + commands[i].y;
str += (commands[i].relative?'a':'A') +
commands[i].rX + WSP + commands[i].rY +
WSP + commands[i].xRot +
WSP + commands[i].lArcFlag + WSP + commands[i].sweepFlag +
WSP + commands[i].x + WSP + commands[i].y;
// Unkown command
} else {
this.emit('error', new Error('Unexpected command type "'
+ commands[i].type + '" at index ' + i + '.'));
this.emit('error', new Error('Unexpected command type "' +
commands[i].type + '" at index ' + i + '.'));
}

@@ -98,0 +98,0 @@ }

@@ -5,19 +5,20 @@ // Parse SVG PathData

// Access to SVGPathData constructor
var SVGPathData = require('./SVGPathData.js')
var SVGPathData = require('./SVGPathData.js');
// TransformStream inherance required modules
, TransformStream = require('readable-stream').Transform
, util = require('util')
var TransformStream = require('readable-stream').Transform;
var util = require('util');
// Private consts : Char groups
, WSP = [' ', '\t', '\r', '\n']
, DIGITS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
, SIGNS = ['-', '+']
, EXPONENTS = ['e', 'E']
, DECPOINT = ['.']
, FLAGS = ['0', '1']
, COMMA = [',']
, COMMANDS = ['m', 'M', 'z', 'Z', 'l', 'L', 'h', 'H', 'v', 'V', 'c', 'C',
's', 'S', 'q', 'Q', 't', 'T', 'a', 'A']
;
var WSP = [' ', '\t', '\r', '\n'];
var DIGITS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
var SIGNS = ['-', '+'];
var EXPONENTS = ['e', 'E'];
var DECPOINT = ['.'];
var FLAGS = ['0', '1'];
var COMMA = [','];
var COMMANDS = [
'm', 'M', 'z', 'Z', 'l', 'L', 'h', 'H', 'v', 'V', 'c', 'C',
's', 'S', 'q', 'Q', 't', 'T', 'a', 'A'
];

@@ -66,4 +67,4 @@ // Inherit of transform stream

// White spaces parsing
if(this.state&SVGPathDataParser.STATE_WSP
|| this.state&SVGPathDataParser.STATE_WSPS) {
if(this.state&SVGPathDataParser.STATE_WSP ||
this.state&SVGPathDataParser.STATE_WSPS) {
if(-1 !== WSP.indexOf(str[i])) {

@@ -80,4 +81,4 @@ this.state ^= this.state&SVGPathDataParser.STATE_WSP;

// Commas parsing
if(this.state&SVGPathDataParser.STATE_COMMA
|| this.state&SVGPathDataParser.STATE_COMMAS) {
if(this.state&SVGPathDataParser.STATE_COMMA ||
this.state&SVGPathDataParser.STATE_COMMAS) {
if(-1 !== COMMA.indexOf(str[i])) {

@@ -193,5 +194,5 @@ this.state ^= this.state&SVGPathDataParser.STATE_COMMA;

// Move to / line to / smooth quadratic curve to commands (x, y)
} else if(this.state&SVGPathDataParser.STATE_MOVE_TO
|| this.state&SVGPathDataParser.STATE_LINE_TO
|| this.state&SVGPathDataParser.STATE_SMOOTH_QUAD_TO) {
} else if(this.state&SVGPathDataParser.STATE_MOVE_TO ||
this.state&SVGPathDataParser.STATE_LINE_TO ||
this.state&SVGPathDataParser.STATE_SMOOTH_QUAD_TO) {
if(null === this.curCommand) {

@@ -303,4 +304,4 @@ this.curCommand = {

if(Number(this.curNumber) < 0) {
this.emit('error', new SyntaxError('Expected positive number, got "'
+ this.curNumber + '" at index "' + i + '"'));
this.emit('error', new SyntaxError('Expected positive number,' +
' got "' + this.curNumber + '" at index "' + i + '"'));
}

@@ -310,4 +311,4 @@ this.curCommand.rX = Number(this.curNumber);

if(Number(this.curNumber) < 0) {
this.emit('error', new SyntaxError('Expected positive number, got "'
+ this.curNumber + '" at index "' + i + '"'));
this.emit('error', new SyntaxError('Expected positive number,' +
' got "' + this.curNumber + '" at index "' + i + '"'));
}

@@ -325,4 +326,4 @@ this.curCommand.rY = Number(this.curNumber);

if('0' !== this.curNumber && '1' !== this.curNumber) {
this.emit('error', new SyntaxError('Expected a flag, got "'
+ this.curNumber +'" at index "' + i + '"'));
this.emit('error', new SyntaxError('Expected a flag, got "' +
this.curNumber +'" at index "' + i + '"'));
}

@@ -462,4 +463,4 @@ this.curCommand.sweepFlag = Number(this.curNumber);

} else {
this.emit('error', new SyntaxError('Unexpected character "' + str[i]
+ '" at index ' + i + '.'));
this.emit('error', new SyntaxError('Unexpected character "' + str[i] +
'" at index ' + i + '.'));
}

@@ -466,0 +467,0 @@ // White spaces can follow a command

@@ -5,8 +5,7 @@ // Transform SVG PathData

// Access to SVGPathData constructor
var SVGPathData = require('./SVGPathData.js')
var SVGPathData = require('./SVGPathData.js');
// TransformStream inherance required modules
, TransformStream = require('readable-stream').Transform
, util = require('util')
;
var TransformStream = require('readable-stream').Transform;
var util = require('util');

@@ -25,7 +24,7 @@ // Inherit of transform stream

if('function' !== typeof transformFunction) {
throw new Error('Please provide a transform callback to receive commands.')
throw new Error('Please provide a transform callback to receive commands.');
}
this._transformer = transformFunction.apply(null, [].slice.call(arguments, 1));
if('function' !== typeof this._transformer) {
throw new Error('Please provide a valid transform (returning a function).')
throw new Error('Please provide a valid transform (returning a function).');
}

@@ -164,4 +163,4 @@

'number' !== typeof e, 'number' !== typeof f) {
throw new Error('A matrix transformation requires parameters [a,b,c,d,e,f]'
+' to be set and to be numbers.');
throw new Error('A matrix transformation requires parameters' +
' [a,b,c,d,e,f] to be set and to be numbers.');
}

@@ -174,4 +173,4 @@ return function matrix(command) {

command.y : (command.relative ? 0 : prevY || 0)
) * c
+ (command.relative && 'undefined' !== typeof prevX ? 0 : e);
) * c +
(command.relative && 'undefined' !== typeof prevX ? 0 : e);
}

@@ -181,21 +180,21 @@ if('undefined' !== typeof command.y) {

origX : (command.relative ? 0 : prevX || 0)
) * b
+ command.y * d
+ (command.relative && 'undefined' !== typeof prevY ? 0 : f);
) * b +
command.y * d +
(command.relative && 'undefined' !== typeof prevY ? 0 : f);
}
if('undefined' !== typeof command.x1) {
command.x1 = command.x1 * a + command.y1 * c
+ (command.relative && 'undefined' !== typeof prevX ? 0 : e);
command.x1 = command.x1 * a + command.y1 * c +
(command.relative && 'undefined' !== typeof prevX ? 0 : e);
}
if('undefined' !== typeof command.y1) {
command.y1 = origX1 * b + command.y1 * d
+ (command.relative && 'undefined' !== typeof prevY ? 0 : f);
command.y1 = origX1 * b + command.y1 * d +
(command.relative && 'undefined' !== typeof prevY ? 0 : f);
}
if('undefined' !== typeof command.x2) {
command.x2 = command.x2 * a + command.y2 * c
+ (command.relative && 'undefined' !== typeof prevX ? 0 : e);
command.x2 = command.x2 * a + command.y2 * c +
(command.relative && 'undefined' !== typeof prevX ? 0 : e);
}
if('undefined' !== typeof command.y2) {
command.y2 = origX2 * b + command.y2 * d
+ (command.relative && 'undefined' !== typeof prevY ? 0 : f);
command.y2 = origX2 * b + command.y2 * d +
(command.relative && 'undefined' !== typeof prevY ? 0 : f);
}

@@ -215,4 +214,4 @@ prevX = ('undefined' !== typeof command.x ?

if('number' !== typeof a) {
throw new Error('A rotate transformation requires the parameter a'
+' to be set and to be a number.');
throw new Error('A rotate transformation requires the parameter a' +
' to be set and to be a number.');
}

@@ -223,6 +222,6 @@ return (function(toOrigin, doRotate, fromOrigin) {

};
})(SVGPathDataTransformer.TRANSLATE(-(x || 0), -(y || 0))
, SVGPathDataTransformer.MATRIX(Math.cos(a), Math.sin(a),
-Math.sin(a), Math.cos(a), 0, 0)
, SVGPathDataTransformer.TRANSLATE(x || 0, y || 0)
})(SVGPathDataTransformer.TRANSLATE(-(x || 0), -(y || 0)),
SVGPathDataTransformer.MATRIX(Math.cos(a), Math.sin(a),
-Math.sin(a), Math.cos(a), 0, 0),
SVGPathDataTransformer.TRANSLATE(x || 0, y || 0)
);

@@ -234,4 +233,4 @@ };

if('number' !== typeof dX) {
throw new Error('A translate transformation requires the parameter dX'
+' to be set and to be a number.');
throw new Error('A translate transformation requires the parameter dX' +
' to be set and to be a number.');
}

@@ -244,4 +243,4 @@ return SVGPathDataTransformer.MATRIX(1, 0, 0, 1, dX, dY || 0);

if('number' !== typeof dX) {
throw new Error('A scale transformation requires the parameter dX'
+' to be set and to be a number.');
throw new Error('A scale transformation requires the parameter dX' +
' to be set and to be a number.');
}

@@ -254,14 +253,14 @@ return SVGPathDataTransformer.MATRIX(dX, 0, 0, dY || dX, 0, 0);

if('number' !== typeof a) {
throw new Error('A skewX transformation requires the parameter x'
+' to be set and to be a number.');
throw new Error('A skewX transformation requires the parameter x' +
' to be set and to be a number.');
}
return SVGPathDataTransformer.MATRIX(1, 0, Math.atan(a), 1, 0, 0);
}
};
SVGPathDataTransformer.SKEW_Y = function skewYGenerator(a) {
if('number' !== typeof a) {
throw new Error('A skewY transformation requires the parameter y'
+' to be set and to be a number.');
throw new Error('A skewY transformation requires the parameter y' +
' to be set and to be a number.');
}
return SVGPathDataTransformer.MATRIX(1, Math.atan(a), 0, 1, 0, 0);
}
};

@@ -325,3 +324,3 @@ // Symetry througth the X axis

function a2c (x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
var PI = Math.PI
var PI = Math.PI;
// Borrowed from https://github.com/PPvG/svg-path/blob/master/lib/Path.js#L208

@@ -328,0 +327,0 @@ // that were borrowed from https://github.com/DmitryBaranovskiy/raphael/blob/4d97d4ff5350bb949b88e6d78b877f76ea8b5e24/raphael.js#L2216-L2304

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