{"name":"path-data-parser","version":"0.0.1","description":"Yet another SVG path parser. This one's tiny","main":"lib/index.js","module":"lib/index.js","types":"lib/index.d.ts","scripts":{"build":"rm -rf lib && tsc","lint":"tslint -p tsconfig.json","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/pshihn/path-data-parser.git"},"keywords":["SVG","PATH","SVGPATH","pathdata","parser"],"author":{"name":"Preet Shihn"},"license":"MIT","bugs":{"url":"https://github.com/pshihn/path-data-parser/issues"},"homepage":"https://github.com/pshihn/path-data-parser#readme","devDependencies":{"tslint":"^6.1.1","typescript":"^3.8.3"},"gitHead":"d79e7395a964d7798e0a7789a681bebefd43e32d","_id":"path-data-parser@0.0.1","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-HnasQcgdOop8oTltyohyP1CO38ma3X4Kv2+VqzohgO0SRUUTeyzHlM8PC4noqcEpyyD5nRfBBbubZpIHSzXojQ==","shasum":"e529279db466dce0bc49312c2081ec4b54a4176d","tarball":"http://registry-npm.ywwl.com/path-data-parser/download/path-data-parser-0.0.1.tgz","fileCount":17,"unpackedSize":29717,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJej/iqCRA9TVsSAnZWagAAwZ4P/jNCqNah61eTwXt1/sQ0\nf/gu2nBTQ1li19U+DT+co6MUHZ9XD0uUvimTWsNwCM0eetRl4X4CczpVVZFz\nqC1BuIOiio1swoTD/v5OTWaejggG+di7HeIdguAFFcCJcOWySa3MfNSwrG/0\nFL9jIV24SycdLevOgsMKxR90iZ0tCoBlUZBDBqPGHrVA8WeRgH1c7j8uYAwI\nxm7eXSIkPnJ21JGzx4K5M1VdKWbDYJm5V7mELxj5wrBQ6gsIH3IOe6RX9e5U\nddyRbXnDNhSvZKllp3VfdBPYYlGNw8qoM7rUejNacMgTp8/HKKKTpEoyWQkI\n9ua46zZs6iyHK/viusqdGVXP7YwYMCtZQo+9Lw0LlSbi7pGsjizJKMEomTdD\nSLE93EOreZvMyKIpPIQQpFZqUJQU7DAx+e5WTIRn6piofq4Q9UF7HUnsxHZI\nKEJLKvhEnKtvpt8Cl+/5nKaw51NhHa6tFAvjWdX08bsIE+unGIZsPA+Mx2Dh\nF+YjBnsiuJniNCEz7Ly5vgW/5rNehHuPvRxKwtFgCV+CGV/IFoZ1HjZOG3KP\nFxWcQF+0VA4J+Rnj/uZQm8BgQxDrKivi3ZFnJ+RSNb1ayrD9MAwhVbrrw8z6\nTGZ2iq0vNh9Zuglv5/e8OC76fBYWIlCMCtu9MKeN/re2wJKzAOBVtbxOPfNl\nbHjo\r\n=uD2L\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDhU/+R82+yoxxZzdoHPL5rnnIO20gLGaXd1gaFUMzfNAIgah/atKZjs9/iWNd2Ategs4Mlyc++Mk6IfXTS24/T1LY="}],"size":6216,"noattachment":false,"key":"/path-data-parser/-/path-data-parser-0.0.1.tgz"},"maintainers":[{"name":"shihn","email":"preetshihn@gmail.com"}],"_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/path-data-parser_0.0.1_1586493609779_0.9018511332420274"},"_hasShrinkwrap":false,"readme":"# path-data-parser\n\nI know there are a bunch of SVG path parsers out there, but here's one that I have been using for a few years now. It's small, tree-shakable and provides four simple functions that I have needed in several graphics projects.\n\n## Install\n\nFrom npm\n\n```\nnpm install --save path-data-parser\n```\n\nThe code is shipped as ES6 modules. \n\n## Methods\n\nThe module exposes 4 methods\n\n### pasrePath(d: string): Segment[]\n\nThis is the main method that parses the SVG path data. You pass in the path string and it returns an array of `Segments`. A segment has a `key` which is the commands, e.g. `M` or `h` or `C`; and `data` which is an array of numbers used by the command\n\n```javascript\nSegment {\n  key: string;\n  data: number[];\n}\n```\n\nexample:\n\n```javascript\nimport { parsePath } from 'path-data-parser';\nconst segments = parsePath('M10 10 h 80 v 80 h -80 C Z');\n```\n\n### serialize(segments: Segment[]): string\n\nThis is essentially the opposite of the `parsePath` command. It outputs a path string from an array of `Segment` objects.\n\n```javascript\nimport { parsePath, serialize, absolutize } from 'path-data-parser';\n\nconst segments = parsePath('M10 10 h 80 v 80 h -80 Z');\nconst absoluteSegments = absolutize(segments); // Turns relative commands to absolute\nconst outputPath = serialize(absoluteSegments);\nconsole.log(outputPath); // M 10 10 H 90 V 90 H 10 Z\n```\n\n### absolutize(segments: Segment[]): Segment[]\n\nTranslates relative commands to absolute commands. i.e. all commands that use relative positions (lower-case ones), turns into absolute position commands (upper-case ones).\nSee the `serialize` example above. \n\n### normalize(segments: Segment[]): Segment[]\n\nNormalize takes a list of _absolute segments_ and outputs a list of segments with only four commands: `M, L, C, Z`. So every segment is described as move, line, or a bezier curve (cubic). \n\nThis is useful when translating SVG paths to non SVG mediums - Canvas, or some other graphics platform. Most such platforms will support lines and bezier curves. It also simplifies the cases to consider when modifying these segments.\n\n```javascript\nimport { parsePath, serialize, absolutize, normalize } from 'path-data-parser';\n \nconst segments = parsePath(' M 10 80 Q 52.5 10, 95 80 T 180 80');\nconst absoluteSegments = absolutize(segments);\nconst normalizedSegments = normalize(absoluteSegments);\n// M 10 80 C 38.33 33.33, 66.67 33.33, 95 80 C 123.33 126.67, 151.67 126.67, 180 80\n \n```\n\n## License\n[MIT License](https://github.com/pshihn/path-data-parser/blob/master/LICENSE)\n","publish_time":1586493609943,"_cnpm_publish_time":1586493609943,"dist-tags":{"latest":"0.1.0"}}