{"name":"path-data-parser","version":"0.0.2","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":"3717bf009bba91795c7c76cfa4924c09558c3c76","_id":"path-data-parser@0.0.2","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-zuIKW5r6927H+yJAlUyD7pVcaazH/f2RJbfrE/3gtpQqy7sRyovyno+nlG8jpDFBtb6zwPm2Jp+6nxDDH2vd4A==","shasum":"fd8ed4785949ecc7f0c4b3aee2f82ddfea70d6fc","tarball":"http://registry-npm.ywwl.com/path-data-parser/download/path-data-parser-0.0.2.tgz","fileCount":17,"unpackedSize":29744,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJej/kCCRA9TVsSAnZWagAAkqcP/3v8LbojF6M1L8z8OGc1\nTEaLdseEh96pwP+VPOjWhgQ94J1U2xOEbtdyEBZdO+Dw0qTBGEGsLyJzE7xY\nfSnB31dAxP5p6lrEaQvIB0IXLS3c3ojsebZeSHTcwmMhT5UpP5mopenTd6Oz\nEcJwGrOTQ7Q8+eSBsAFmckspohfq4xx82Vuu4i4v5k5i1xyyMOvTM/ACQ5Vc\nf1Q+qDHB9uucfdRhEJZYkp/7FOTwGqkATQJP1y5z2ZLek/4Mcg5l29b5LhkC\nZhg8Tym9XJLHMTkz3Fl2aqauy4BeZiN1K+v1Rrn++jfiao8Vkiu6zTPWidqz\nt7+gEn8OjdZ1x1STgcKewj7B2S/5svuzGu6QtdhlYhL89BJzryDxMhhniTVm\nbJsTKvDxNcpQtgjBADXeENcdHTF6+tICHzWUcgbTtJgmnC6QXFbLGIOwju/C\n3R5Kp0X7aD+6+gQR76jtm3B69+6TahfrK58LMzQwWopzrGH2gaYSIwyFJqhW\nTXT+yLOg5Pc6pAlX/4x5rzd1Wdy2YTNfMmJBI3o66D5uqcJ2OCVDlLUlHQR5\nOUDZdLl94aE/o5RC0TGDnDLoi6Dujct5/q8Cz/y1LGkdiJJvXdqqy0lmTLgO\nCNCD8u+qDSNKYQfbh922Bz4dTManc7hqLfeJB46QlEgGb8n8eqUzOkEaxva9\nlR+s\r\n=7/Sf\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCID4k96DvclJbmUynINUBCQc4bMnBb+EBmLFJj39AoGDWAiEA/zXCrZ3BROGCG0F+Uuc8lGkd6wRKLuc0qyzlim+kOGs="}],"size":6216,"noattachment":false,"key":"/path-data-parser/-/path-data-parser-0.0.2.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.2_1586493698029_0.46766404841078146"},"_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":1586493698144,"_cnpm_publish_time":1586493698144,"dist-tags":{"latest":"0.1.0"}}