New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

svg-path-interpolator

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-path-interpolator - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

src/math/calculators.js

31

package.json
{
"author": "Justin Wilaby",
"name": "svg-path-interpolator",
"version": "0.1.1",
"version": "0.2.0",
"license": "MIT",
"main": "src/index.js"
"description": "The SVG Path Interpolator produces point data representing interpolated values within an SVG path.",
"repository": {
"type": "git",
"url": "https://github.com/justinwilaby/svg-path-interpolator.git"
},
"bin": {
"svgpi": "./bin/svgpi.js"
},
"main": "src/SVGPathInterpolator.js",
"files": [
"src"
],
"keywords": [
"svg",
"points",
"paths",
"drawing",
"interpolate",
"calculate",
"animate",
"bézier",
"bezier",
"curves",
"polygon"
],
"dependencies": {
"sax": "^1.2.1"
}
}

60

README.md
# SVG Path Interpolator
The SVG Path Interpolator produces point data representing interpolated values within an SVG path. This is handy when you need to calculate complex paths for animation or drawing APIs beforehand. Complex paths that include Bézier curves are converted to polygons with a configurable segment sampling size producing more points with greater precision or fewer points for speed. Polygon path data can be used to animate, draw or for hit detection in games.
## Install
```bash
npm install svg-path-interpolator --save
```
or as a cli
```bash
npm install -g svg-path-interpolator
```
## Usage
See the `sample.config.json` for configuration options
```js
For Node cli users, create a config.json somewhere in your project. See the `sample.config.json` for configuration options.
```json
{
"files": [
"sample.svg"
],
"outputDirectory": "out/",
"trim": true,
"joinPathData": false,
"minDistance": 0.5,

@@ -20,9 +25,32 @@ "roundToNearest": 0.25,

```
### files
The `files` array identifies the files to process.
### outputDirectory
`outputDirectory` identifies where to write the path data. If omitted, all path data is written to stdout.
### trim
When `trim` is `true`, paths that were translated are normalized and will begin at 0,0
Then from your terminal, type
```bash
svgpi ./path/to/config.json ./path/to/target.svg ./output/fileName.json
```
For ES6 users, create a new instance of the SVGPathInterpolator
```js
import SVGPathInterpolator from 'SVGPathInterpolator';
const svgString = `
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
width="792px" height="612px" viewBox="0 0 792 612" enable-background="new 0 0 792 612" xml:space="preserve">
<g>
<path id="path3789" d="M287.168,442.411
c-8.65,0-15.652,7.003-15.652,15.653
c0,8.65,7.003,15.69,15.652,15.69
s15.653-7.04,15.653-15.69
"/>
</g>
</svg>
`;
const config = {
joinPathData: false,
minDistance: 0.5,
roundToNearest: 0.25,
sampleFrequency: 0.001
};
const interpolator = new SVGPathInterpolator(config);
const pathData = interpolator.processSvg(svgString);
```
### joinPathData
When `joinPathData` is `true`, all path data is joined in a single array as the output. When `false`, each path is separated by the path `id` attribute in a json object as the output. If no `id` attribute exists on the path, a unique id is created.
### minDistance

@@ -34,5 +62,5 @@ `minDistance` is the minimum distance between the current and previous points when sampling. If a sample results in a distance less than the specified value, the point is discarded.

`sampleFrequency` determines the increment of `t` when sampling. If `sampleFrequency` is set to `.001` , since `t` iterates from 0 to 1, there will be 1000 points sampled per command but only points that are greater than `minDistance` are captured.
### pretty
### pretty (cli only)
When `true`, `pretty` creates formatted json output
### prettyIndent
### prettyIndent (cli only)
Then number of spaces to indent when `pretty` is `true`

@@ -39,0 +67,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