{"id":15355837,"url":"https://github.com/fibo/svgx","last_synced_at":"2025-07-19T13:08:39.579Z","repository":{"id":65503757,"uuid":"57226317","full_name":"fibo/SVGx","owner":"fibo","description":"is a universal SVG renderer","archived":false,"fork":false,"pushed_at":"2019-07-08T14:13:58.000Z","size":224,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-04T21:06:36.478Z","etag":null,"topics":["react","server-side-rendering","svg"],"latest_commit_sha":null,"homepage":"http://g14n.info/SVGx","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/fibo.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":"2016-04-27T15:54:27.000Z","updated_at":"2024-02-23T19:57:30.000Z","dependencies_parsed_at":"2023-01-26T11:15:30.579Z","dependency_job_id":null,"html_url":"https://github.com/fibo/SVGx","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2FSVGx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2FSVGx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2FSVGx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibo%2FSVGx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fibo","download_url":"https://codeload.github.com/fibo/SVGx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219842555,"owners_count":16556535,"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":["react","server-side-rendering","svg"],"created_at":"2024-10-01T12:25:52.130Z","updated_at":"2024-10-16T03:21:48.809Z","avatar_url":"https://github.com/fibo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SVGx\n\n\u003e is a universal SVG renderer\n\n[Description](#description) |\n[Installation](#installation) |\n[Usage](#usage) |\n[Api](#api) |\n[License](#license)\n\n[![NPM version](https://badge.fury.io/js/svgx.svg)](http://badge.fury.io/js/svgx)\n[![No deps](https://img.shields.io/badge/dependencies-none-green.svg)](https://github.com/fibo/SVGx)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![Change log](https://img.shields.io/badge/change-log-blue.svg)](http://g14n.info/SVGx/changelog)\n\n## Description\n\nThanks to React it is feasible to achieve server side rendering SVG. However,\nthere is a pit fall: doctype is missing. This package prepends a doctype to generated SVG.\n\nActually, this package is also a recipe to *render and test SVG server side*.\n\nYou can try this [example.js][example_js] script, by launching commands\n\n```bash\ngit clone https://github.com/fibo/SVGx.git\ncd SVGx\nnpm install\nnpm run example\n```\n\nIt generates the following SVG output\n\n![SVG example][example_svg]\n\n## Installation\n\nWith [npm](https://npmjs.org/) do\n\n```bash\nnpm install svgx\n```\n\n## Usage\n\nInstalling `react` and `react-dom` is up to you: `svgx` does not declare\nthem as dependencies, cause you could use a different version or even\nother React-like engine. Same logic applies to awesome babel packages, you\ncould use any other transpiler.\n\nAnyway, to get the job done, you can do\n\n```bash\nnpm install react react-dom babel-cli babel-env --save-dev\n```\n\nThen run the following script with babel.\n\n```javascript\n#!/usr/bin/env babel-node\n\nimport React from 'react'\nimport reactDom from 'react-dom/server'\nimport svgx from 'svgx'\n\nconst render = svgx(reactDom.renderToStaticMarkup)\n\nconst jsx = (\n  \u003csvg\n    xmlns='http://www.w3.org/2000/svg'\n    xmlnsXlink='http://www.w3.org/1999/xlink'\n    width={200} height={200}\n  \u003e\n    \u003ccircle cx={100} cy={100} r={50} /\u003e\n  \u003c/svg\u003e\n)\n\nconst svgOutput = render(jsx)\n\nconsole.log(svgOutput)\n```\n\n**NOTA BENE**: Attributes `xmlns` and `xmlnsXlink` are **mandatory** to get a valid SVG file.\n\n## API\n\n### `svgxRender = svgx(jsxRender)`\n\n\u003e Get your svgx wrapper.\n\n```javascript\n/**\n  * @param {Function} jsxRender function, for instance `reactDom.renderToStaticMarkup`\n  * @return {Function} svgxRender wrapper\n  */\n```\n\n### `svgxRender(jsx[, opts])`\n\n\u003e Wrapper for static JSX render function: it works server side.\n\n```javascript\n/**\n  * @param {ReactElement} jsx to be rendered.\n  * @param {Object} [opts] Options can be omitted, just ignore them and it will work fine.\n  * @param {String} [opts.doctype] defaults to a common SVG doctype. You can remove it by setting it to the blank string `''` or any other doctype you need.\n  * @return {String} markup in SVG format\n  */\n```\n\n## License\n\n[MIT](http://g14n.info/mit-license/)\n\n[example_js]: https://github.com/fibo/SVGx/blob/master/example.js\n[example_svg]: https://g14n.info/SVGx/example.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffibo%2Fsvgx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffibo%2Fsvgx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffibo%2Fsvgx/lists"}