https://github.com/lukem512/normalize-svg-coords
Normalize coordinates in an SVG path to a specified range
https://github.com/lukem512/normalize-svg-coords
clip mask path svg
Last synced: 5 months ago
JSON representation
Normalize coordinates in an SVG path to a specified range
- Host: GitHub
- URL: https://github.com/lukem512/normalize-svg-coords
- Owner: lukem512
- Created: 2017-03-30T11:08:02.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-08T10:41:39.000Z (almost 6 years ago)
- Last Synced: 2024-11-14T01:02:42.400Z (5 months ago)
- Topics: clip, mask, path, svg
- Language: JavaScript
- Size: 18.6 KB
- Stars: 17
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# normalize-svg-coords
[](https://travis-ci.org/lukem512/normalize-svg-coords)  [](https://www.npmjs.com/package/normalize-svg-coords) [](https://www.npmjs.com/package/normalize-svg-coords) [](https://www.npmjs.com/package/normalize-svg-coords)
Normalize coordinates in an SVG path to a specified range.
## Install
```
npm i --save normalize-svg-coords
```## Usage
```js
const normalize = require('normalize-svg-coords');const normalizedPath = normalize({
viewBox: '0 0 400 460',
path: 'M150.883 169.12c11.06-.887 20.275-7.079 24.422-17.256',
min: 0,
max: 1,
asList: false
})console.log(normalizedPath) // M0.3772 0.3677c0.0277 -0.0019 0.0507 -0.0154 0.0611 -0.0375
```Specify a range, `min` to `max`, and provide the `path` and the corresponding
`viewBox`. The coordinates of the resulting path will all be within the
specified range whilst maintaining the shape.The `viewBox` parameter may be passed as a `string` of 4 integers in the order
`xmin ymin xmax ymax` with spaces (` `) or commas (`,`) as a delimiter. The
`viewBox` may also be passed as an `object` or an `array`. If no `viewBox` is specified then one is inferred using [`svg-path-bounds`](https://npmjs.com/package/svg-path-bounds).Set the `asList` parameter to `true` to output the normalized path as a segmented list.
```js
console.log(normalizedPath) // ['M', '0.3772', '0.3677'], ['c', '0.0277', '-0.0019', '0.0507', '-0.0154', '0.0611', '-0.0375']]
```## Related Modules
[extract-svg-viewbox](https://github.com/lukem512/extract-svg-viewbox)
## License
MIT © Luke Mitchell