{"id":16439086,"url":"https://github.com/saintplay/svg-polygon-points","last_synced_at":"2025-09-11T21:47:47.759Z","repository":{"id":57150054,"uuid":"113954456","full_name":"saintplay/svg-polygon-points","owner":"saintplay","description":"Tiny library to manipulate SVG Polygon points","archived":false,"fork":false,"pushed_at":"2018-01-05T02:09:59.000Z","size":81,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-03T06:08:29.926Z","etag":null,"topics":["manipulation","points","polygon","svg"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/saintplay.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":"2017-12-12T06:52:16.000Z","updated_at":"2018-10-21T02:11:54.000Z","dependencies_parsed_at":"2022-09-03T18:01:19.597Z","dependency_job_id":null,"html_url":"https://github.com/saintplay/svg-polygon-points","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/saintplay/svg-polygon-points","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saintplay%2Fsvg-polygon-points","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saintplay%2Fsvg-polygon-points/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saintplay%2Fsvg-polygon-points/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saintplay%2Fsvg-polygon-points/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saintplay","download_url":"https://codeload.github.com/saintplay/svg-polygon-points/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saintplay%2Fsvg-polygon-points/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262319536,"owners_count":23293042,"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":["manipulation","points","polygon","svg"],"created_at":"2024-10-11T09:07:50.293Z","updated_at":"2025-07-03T05:05:09.913Z","avatar_url":"https://github.com/saintplay.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# svg-polygon-points\n\n\u003e Tiny library to manipulate [SVG Polygon Points](https://www.w3.org/TR/SVG/shapes.html#PolygonElementPointsAttribute)\n\n## Install ##\n\n    npm install --save svg-polygon-points\n\nor\n\n    yarn add svg-polygon-points\n\n\n## Functions ##\n\n- add –  WIP\n- [`Bounding Box`](#bounding-box) – Calculate the bouding box dimensions of a polygon\n- [`Offset`](#offset) – Offset the polygon\n- [`Rotate`](#rotate) - Rotates the polygon clockwise\n- scale - WIP\n- [`Start In`](#start-in) – Draw a polygon like HTML canvas\n- [`From Geo JSON`](#from-geo-json) – Transform GeoJSON coords to SVG Polygon's points\n- [`To Geo JSON`](#to-geo-json) – Returns the respective GeoJSON Array Coords\n\n\n## Usage ##\n\n\n### Bounding Box ###\n\n`boundingBox(points)`  \nGet the bounding box\n\n#### {String} points - The polygon points to manipulate.\n\n#### Returns {Object} a { left, top, right, bottom, width, height. center } Object\n\n```js\nconst boundingBox = require('svg-polygon-points').boundingBox;\n// or\nimport { boundingBox } from 'svg-polygon-points';\n\nconst points = \"28,224 256,224 256,352 128,352\"\nboundingBox(points)\n/*=\u003e {\n    left: 28,\n    top: 224,\n    right: 256,\n    bottom: 352,\n    width: 228,\n    height: 128,\n    center: {\n      x: 192,\n      y: 288\n    }\n  }\n*/\n```\n\n### Offset ###\n\n`offset(points, angle, horizontalOffset, verticalOffset)`  \nOffsets the polygon points \n\n#### {String} points - The polygon points to manipulate.\n#### {Number} horizontalOffset - The horizontal offset\n#### {Number} verticalOffset - The horizontal offset\n\n#### Returns {String} a polygons points string\n\n```js\nconst offset = require('svg-polygon-points').offset;\n// or\nimport { offset } from 'svg-polygon-points';\n\nconst points = \"0,0 128,0 128,128 0,128\"\noffset(points, 100, 50)\n//=\u003e \"100,50 228,50 228,178 100,178\"\n```\n\n### Rotate ###\n\n`rotate(points, angle, [center])`  \nRotates the polygon clockwise  \n\n#### {String} points - The polygon points to manipulate.\n#### {Number} angle - The angle degrees to rotate\n#### {Number} center - An { x, y } coord, If not especified, center of the bounding box will be used\n\n#### Returns {String} a polygons points string\n\n```js\nconst rotate = require('svg-polygon-points').rotate;\n// or\nimport { rotate } from 'svg-polygon-points';\n\nconst points = \"0,0 48,0 48,64 96,64 96,128 0,128\"\nrotate(points, 90)\n//=\u003e \"112,16 112,64 48,64 48,112 -16,112 -16,16\"\n```\n\n### Start In ###\n\n`startIn(coord)`  \nCreates a Draw Object  \n\n#### {Object} coord - A { x, y } Object\n\n#### Returns {Draw} a Draw Object\n\n#### Draw methods\n\n- **drawTo({ direction, length })**\n- **toPoints()**\n\n```js\nconst startIn = require('svg-polygon-points').startIn;\n// or\nimport { startIn } from 'svg-polygon-points';\n\nconst points = startIn({ x: 50, y: 50 })\n  .drawTo({ direction: 'right', length: 150 })\n  .drawTo({ direction: 'down', length: 150 })\n  .drawTo({ direction: 'right', length: 150 })\n  .drawTo({ direction: 'down', length: 150 })\n  .drawTo({ direction: 'left', length: 150 })\n  .toPoints()\n//=\u003e \"50,50 200,50 200,200 350,200 350,350 50,350\"\n```\n\n### From Geo JSON ###\n\n`fromGeoJSON(points)`  \nTransform GeoJSON coords to SVG Polygon's points\n\n#### {Array} a GeoJSON Coordinates Array\n#### returns {String} the polygon points.\n\n\n```js\nconst fromGeoJSON = require('svg-polygon-points').fromGeoJSON;\n// or\nimport { fromGeoJSON } from 'svg-polygon-points';\n\nconst coords = \"[ [[100,50], [228,50], [228,178], [100,178]] ]\"\nfromGeoJSON(coords)\n//=\u003e \"100,50 228,50 228,178 100,178\"\n```\n\n### To Geo JSON ###\n\n`toGeoJSON(points)`  \nReturns the respective GeoJSON Array Coords  \n\n#### {String} points - The polygon points to manipulate.\n\n#### Returns {Array} a Coordinates Array\n\n```js\nconst toGeoJSON = require('svg-polygon-points').toGeoJSON;\n// or\nimport { toGeoJSON } from 'svg-polygon-points';\n\nconst points = \"0,0 128,0 128,128 0,128\"\ntoGeoJSON(points)\n//=\u003e [ [[100,50], [228,50], [228,178], [100,178]] ]\n```\n\n## License ##\n\nMIT © [Diego Jara](saintplay96@gmail.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaintplay%2Fsvg-polygon-points","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaintplay%2Fsvg-polygon-points","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaintplay%2Fsvg-polygon-points/lists"}