Registry / development / svg-to-swiftui-core

svg-to-swiftui-core

JSON →
library0.4.0jsnpmunverified

svg-to-swiftui-core v0.4.0 is a JavaScript/TypeScript library that converts raw SVG code into SwiftUI Shape structs that can be directly used in SwiftUI projects. It currently supports SVG <path> (partial), <circle>, <rect>, and <ellipse> elements. The package depends on svg-parser and svg-pathdata for parsing. It is designed for Node.js environments and provides an ESM-only API via the default export. The library is in early development (pre-1.0) with limited command support and no styling or animation features.

npm install svg-to-swiftui-core
INSTALL
IMPORT
SIG · SVG-TO-SWIFTUI-COR
S
svg-to-swiftui-core
developmentjavascriptv0.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

convert
import { convert } from 'svg-to-swiftui-core'
const convert = require('svg-to-swiftui-core')
Package is ESM-only; require() will fail with ERR_REQUIRE_ESM
default
import svg2swiftui from 'svg-to-swiftui-core'
Default export is not documented; prefer named import.
convert
import type { ConvertOptions } from 'svg-to-swiftui-core'
import { ConvertOptions } from 'svg-to-swiftui-core' (not a runtime value)
Type import for TypeScript options type.

Converts an SVG circle string to a SwiftUI Shape struct and writes it to a file.

import { convert } from 'svg-to-swiftui-core'; import * as fs from 'fs'; const svgString = '<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40"/></svg>'; try { const swiftCode = convert(svgString); console.log(swiftCode); fs.writeFileSync('CircleShape.swift', swiftCode, 'utf8'); } catch (err) { console.error('Conversion failed:', err.message); }
Debug
Known issues
gotchaLibrary only supports SVG <path> with limited commands (M, L, H, V, Z); many path commands (C, S, Q, T, A) are not implemented. Using unsupported paths will cause errors or incomplete conversion.
fix
Ensure SVG paths only use M, L, H, V, Z commands; avoid curves and arcs.
affects: >=0.0.0
breakingESM-only package; require() will throw ERR_REQUIRE_ESM
fix
Use import instead of require, or use dynamic import().
affects: >=0.0.0
gotchaThe convert function expects raw SVG string; does not support file paths or DOM nodes.
fix
Read SVG file or fetch SVG content as string before calling convert.
affects: >=0.0.0
deprecatedPackage is still pre-1.0 (v0.4.0); API may change incompatibly. No deprecations yet.
fix
Lock version to current minor version and test upgrades.
affects: <1.0.0
Errors
Common errors & fixes
SyntaxError: Unexpected token 'export'
Using require() on ESM-only package
fix
Use dynamic import: const { convert } = await import('svg-to-swiftui-core');
TypeError: convert is not a function
Importing default instead of named export
fix
Use import { convert } from 'svg-to-swiftui-core' instead of import convert from 'svg-to-swiftui-core'
Error: Unsupported SVG command: C
SVG path contains curve command not yet implemented
fix
Simplify SVG path to only use M, L, H, V, Z commands.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies
svg-parserrequiredParses raw SVG into HAST
svg-pathdatarequiredParses SVG path d attribute
Agent activity
35 hits · last 30 days
node
30
OpenAI (training)
1
Resources
svg-to-swiftui-core — npm install svg-to-swiftui-core · libregistry