🚀 Socket Launch Week Day 4:Socket MCP Adds Org Alerts, Threat Feed Review, and Package Inspection.Learn more
Sign In

@kubb/parser-ts

Package Overview
Dependencies
Maintainers
1
Versions
490
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kubb/parser-ts

TypeScript and TSX source file parser for Kubb. Converts AST nodes and raw TypeScript code into formatted source strings using the TypeScript compiler API.

Source
npmnpm
Version
5.0.0-beta.64
Version published
Weekly downloads
64K
-12.08%
Maintainers
1
Weekly downloads
 
Created
Source
Kubb banner

npm version npm downloads Stars License Node

Documentation · Report Bug · Request Feature


@kubb/parser-ts

TypeScript source file parser for Kubb

Converts AST nodes and raw TypeScript code into formatted source strings using the TypeScript compiler API. Handles both .ts and .tsx output.

Installation

bun add @kubb/parser-ts
# or
pnpm add @kubb/parser-ts
# or
npm install @kubb/parser-ts

Usage

import { defineConfig } from 'kubb'
import { parserTs, parserTsx } from '@kubb/parser-ts'

export default defineConfig({
  input: { path: './petstore.yaml' },
  output: { path: './src/gen' },
  parsers: [parserTs, parserTsx],
})

To render compiler AST nodes to source text from inside a plugin, call print on the parser instance:

import { parserTs } from '@kubb/parser-ts'
import ts from 'typescript'

const source = parserTs.print(
  ts.factory.createVariableStatement(
    [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
    ts.factory.createVariableDeclarationList(
      [ts.factory.createVariableDeclaration('hello', undefined, undefined, ts.factory.createStringLiteral('world'))],
      ts.NodeFlags.Const,
    ),
  ),
)
// → export const hello = 'world'

API

parserTs

Parser instance for .ts and .js files. Pass to defineConfig({ parsers: [...] }) to emit TypeScript source files.

  • parserTs.parse(file, options?) — serialize a FileNode to TypeScript source.
  • parserTs.print(...nodes) — convert TypeScript compiler Node instances to a formatted source string.

parserTsx

Parser instance for .tsx and .jsx files. Same API as parserTs with JSX support.

Supporting Kubb

Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:

My sponsors

License

MIT

Keywords

codegen

FAQs

Package last updated on 17 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts