{"id":15381317,"url":"https://github.com/pshihn/path-data-parser","last_synced_at":"2026-03-11T14:07:09.434Z","repository":{"id":42890103,"uuid":"254490948","full_name":"pshihn/path-data-parser","owner":"pshihn","description":"Yet another SVG Path Parser","archived":false,"fork":false,"pushed_at":"2023-01-22T18:26:47.000Z","size":30,"stargazers_count":23,"open_issues_count":3,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T19:09:23.303Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pshihn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-09T22:25:31.000Z","updated_at":"2025-01-23T05:41:41.000Z","dependencies_parsed_at":"2023-02-12T17:31:17.421Z","dependency_job_id":null,"html_url":"https://github.com/pshihn/path-data-parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pshihn%2Fpath-data-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pshihn%2Fpath-data-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pshihn%2Fpath-data-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pshihn%2Fpath-data-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pshihn","download_url":"https://codeload.github.com/pshihn/path-data-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249135809,"owners_count":21218365,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T14:26:45.820Z","updated_at":"2026-03-11T14:07:04.412Z","avatar_url":"https://github.com/pshihn.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpshihn%2Fpath-data-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpshihn%2Fpath-data-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpshihn%2Fpath-data-parser/lists"}