Skip to content

Programmatic API

The package exports two functions from src/convert.ts (re-exported by src/index.ts):

  • convert — read a file from disk, write a .vue file.
  • convertCode — convert an in-memory string (used by the playground and tests).

Only from: "react" and to: "vue" are valid. Anything else throws.

convert(options)

ts
export type ConvertOptions = {
  from: "react"
  to: "vue"
  inputPath: string
  outputDir?: string
}

export function convert(options: ConvertOptions): void
  • inputPath: path to a .tsx / .jsx / .ts / .js source file (resolved with path.resolve).
  • outputDir: optional; if omitted, the .vue is written beside the input file.

Errors

Throws if from / to are not exactly react / vue:

txt
Only --from react --to vue is supported in this version.

convertCode(options)

ts
export type ConvertCodeOptions = {
  from: "react"
  to: "vue"
  sourceCode: string
  filename?: string
}

export function convertCode(options: ConvertCodeOptions): string
  • sourceCode: full source of a single React component file.
  • filename: optional; defaults to "component.tsx". Used for parse error context and as the virtual path passed to the parser.

Returns the full Vue SFC as a string (including <script setup> and <template>).

Errors

Throws if from / to are not supported:

txt
Only React to Vue conversion is supported in this version.

Parsing or codegen failures surface as standard Error messages from the implementation.

ESM import

The published bundle is ESM ("type": "module").

ts
import { convert, convertCode } from "cross-framework"

TypeScript types

The repo currently builds with tsup and dts is not emitted in tsup.config.ts. Consumers can still use TypeScript and may add their own ambient types or enable allowJs / skipLibCheck as needed; adding .d.ts generation is a possible future improvement.

Questions? parsajiravand@gmail.com · MIT License · BRANDING.md for name / fork policy · https://cross-framework.netlify.app/ · https://cross-framework-doc.netlify.app/