{"_id":"path-data-parser","_rev":"4127052","name":"path-data-parser","description":"Yet another SVG path parser. This one's tiny","dist-tags":{"latest":"0.1.0"},"maintainers":[{"name":"shihn","email":""}],"time":{"modified":"2026-03-01T18:25:32.000Z","created":"2020-04-10T04:40:09.943Z","0.1.0":"2020-04-11T08:34:44.676Z","0.0.2":"2020-04-10T04:41:38.144Z","0.0.1":"2020-04-10T04:40:09.943Z"},"users":{},"author":{"name":"Preet Shihn"},"repository":{"type":"git","url":"git+https://github.com/pshihn/path-data-parser.git"},"versions":{"0.1.0":{"name":"path-data-parser","version":"0.1.0","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 parser","SVG","path parser","SVGPATH","pathdata","svg 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":"93d3fa8448c50d1b6443b06b8c71202ee0967e25","_id":"path-data-parser@0.1.0","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"shasum":"8f5ba5cc70fc7becb3dcefaea08e2659aba60b8c","size":7360,"noattachment":false,"key":"/path-data-parser/-/path-data-parser-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/path-data-parser/download/path-data-parser-0.1.0.tgz"},"maintainers":[{"name":"shihn","email":""}],"_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/path-data-parser_0.1.0_1586594084534_0.5980694628865246"},"_hasShrinkwrap":false,"publish_time":1586594084676,"_cnpm_publish_time":1586594084676,"_cnpmcore_publish_time":"2021-12-17T02:50:22.952Z"},"0.0.2":{"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":{"shasum":"fd8ed4785949ecc7f0c4b3aee2f82ddfea70d6fc","size":6216,"noattachment":false,"key":"/path-data-parser/-/path-data-parser-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/path-data-parser/download/path-data-parser-0.0.2.tgz"},"maintainers":[{"name":"shihn","email":""}],"_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,"publish_time":1586493698144,"_cnpm_publish_time":1586493698144,"_cnpmcore_publish_time":"2021-12-17T02:50:23.161Z"},"0.0.1":{"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":{"shasum":"e529279db466dce0bc49312c2081ec4b54a4176d","size":6216,"noattachment":false,"key":"/path-data-parser/-/path-data-parser-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/path-data-parser/download/path-data-parser-0.0.1.tgz"},"maintainers":[{"name":"shihn","email":""}],"_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,"publish_time":1586493609943,"_cnpm_publish_time":1586493609943,"_cnpmcore_publish_time":"2021-12-17T02:50:23.387Z"}},"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","_attachments":{},"homepage":"https://github.com/pshihn/path-data-parser#readme","bugs":{"url":"https://github.com/pshihn/path-data-parser/issues"},"license":"MIT"}