Package Exports
- svg-shapes
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (svg-shapes) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
SVG shapes
Get point data from SVG shapes. Convert point data to an SVG path.
Current shapes supported:
- Polyline
- Rect (note: no rx/ry support yet)
Installation
npm install svg-shapes
Usage
Polyline
import { getPoints, toPath } from 'svg-shapes';
const points = getPoints( 'polyline', {
points: '20,30 50,90 20,90 50,30',
});
console.log( points );
// [
// { x: 20, y: 30 },
// { x: 50, y: 90 },
// { x: 20, y: 90 },
// { x: 50, y: 30 },
// ]
const path = toPath( points );
console.log( path );
// 'M20,30L50,90H20L50,30'
Rect
import { getPoints, toPath } from 'svg-shapes';
const points = getPoints( 'rect', {
height: 20,
width: 50,
x: 10,
y: 10,
});
console.log( points );
// [
// { x: 10, y: 10 },
// { x: 60, y: 10 },
// { x: 60, y: 30 },
// { x: 10, y: 30 },
// { x: 10, y: 10 },
// ]
const path = toPath( points );
console.log( path );
// 'M10,10H60V30H10Z'