@kubb/parser-ts 5.0.0-beta.9 → 5.0.0-beta.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,14 +1,21 @@
1
- Copyright (c) 2026 Stijn Van Hulle
2
-
3
- This repository contains software under two licenses:
1
+ MIT License
4
2
 
5
- 1. Most of the code in this repository is licensed under the
6
- MIT License — see licenses/LICENSE-MIT for the full license text.
3
+ Copyright (c) 2026 Stijn Van Hulle
7
4
 
8
- 2. The following components are licensed under the
9
- GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later)
10
- see licenses/LICENSE-AGPL-3.0 for the full license text:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
11
 
12
- - packages/agent (published as @kubb/agent)
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
13
14
 
14
- Each package's own LICENSE file or package.json specifies its applicable license.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,17 +1,16 @@
1
1
  <div align="center">
2
- <h1>@kubb/parser-ts</h1>
3
2
  <a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
4
- <img width="180" src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/logo.png" alt="Kubb logo">
3
+ <img src="https://kubb.dev/og.png" alt="Kubb banner">
5
4
  </a>
6
5
 
7
6
  [![npm version][npm-version-src]][npm-version-href]
8
7
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
9
- [![Coverage][coverage-src]][coverage-href]
8
+ [![Stars][stars-src]][stars-href]
10
9
  [![License][license-src]][license-href]
11
- [![Sponsors][sponsors-src]][sponsors-href]
10
+ [![Node][node-src]][node-href]
12
11
 
13
12
  <h4>
14
- <a href="https://kubb.dev/" target="_blank">Documentation</a>
13
+ <a href="https://kubb.dev" target="_blank">Documentation</a>
15
14
  <span> · </span>
16
15
  <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
17
16
  <span> · </span>
@@ -19,7 +18,13 @@
19
18
  </h4>
20
19
  </div>
21
20
 
22
- TypeScript and TSX source file parser for Kubb. Converts AST nodes and raw TypeScript code into formatted source strings using the TypeScript compiler API.
21
+ <br />
22
+
23
+ # @kubb/parser-ts
24
+
25
+ ### TypeScript source file parser for Kubb
26
+
27
+ Converts AST nodes and raw TypeScript code into formatted source strings using the TypeScript compiler API. Handles both `.ts` and `.tsx` output.
23
28
 
24
29
  ## Installation
25
30
 
@@ -34,11 +39,33 @@ npm install @kubb/parser-ts
34
39
  ## Usage
35
40
 
36
41
  ```typescript
37
- import { print, createImport, createExport } from '@kubb/parser-ts'
42
+ import { defineConfig } from 'kubb'
43
+ import { parserTs, parserTsx } from '@kubb/parser-ts'
44
+
45
+ export default defineConfig({
46
+ input: './petstore.yaml',
47
+ output: { path: './src/gen' },
48
+ parsers: [parserTs(), parserTsx()],
49
+ })
50
+ ```
51
+
52
+ Pass an `extension` map to rewrite the extensions emitted in `import`/`export` statements. Keys are the source extension, values the output, and an empty string drops it. Use `{ '.ts': '.js' }` for ESM when the consumer transpiles to JavaScript:
53
+
54
+ ```typescript
55
+ export default defineConfig({
56
+ input: { path: './petstore.yaml' },
57
+ output: { path: './src/gen' },
58
+ parsers: [parserTs({ extension: { '.ts': '.js' } }), parserTsx()],
59
+ })
60
+ ```
61
+
62
+ To render compiler AST nodes to source text from inside a plugin, call `print` on a parser instance:
63
+
64
+ ```typescript
65
+ import { parserTs } from '@kubb/parser-ts'
38
66
  import ts from 'typescript'
39
67
 
40
- // Print a TypeScript source file from compiler AST nodes
41
- const source = print([
68
+ const source = parserTs().print(
42
69
  ts.factory.createVariableStatement(
43
70
  [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
44
71
  ts.factory.createVariableDeclarationList(
@@ -46,51 +73,28 @@ const source = print([
46
73
  ts.NodeFlags.Const,
47
74
  ),
48
75
  ),
49
- ])
76
+ )
50
77
  // → export const hello = 'world'
51
-
52
- // Create an import declaration
53
- const importNode = createImport({ name: 'axios', path: 'axios' })
54
-
55
- // Create an export declaration
56
- const exportNode = createExport({ name: 'MyType', path: './types' })
57
78
  ```
58
79
 
59
80
  ## API
60
81
 
61
- ### `print(nodes, options?)`
62
-
63
- Converts an array of TypeScript compiler `Node` instances into a formatted source string. Returns the printed source code.
64
-
65
- ### `safePrint(nodes, options?)`
66
-
67
- Same as `print` but catches formatting errors and returns the unformatted output as a fallback.
68
-
69
- ### `parserTs`
70
-
71
- Parser instance for `.ts` files. Use with Kubb's file system to emit TypeScript source files.
82
+ ### `parserTs(options?)`
72
83
 
73
- ### `parserTsx`
84
+ Factory returning a parser instance for `.ts` and `.js` files. Pass to `defineConfig({ parsers: [...] })` to emit TypeScript source files. The optional `extension` map rewrites the extensions written in `import`/`export` statements and defaults to `{ '.ts': '.ts' }`.
74
85
 
75
- Parser instance for `.tsx` files. Use with Kubb's file system to emit TSX source files.
86
+ The returned instance exposes `parse(file)` to serialize a `FileNode` to TypeScript source and `print(...nodes)` to convert TypeScript compiler `Node` instances to a formatted source string.
76
87
 
77
- ### `createImport(options)`
88
+ ### `parserTsx(options?)`
78
89
 
79
- Factory helper that creates a TypeScript `ImportDeclaration` node.
80
-
81
- ### `createExport(options)`
82
-
83
- Factory helper that creates a TypeScript `ExportDeclaration` node.
84
-
85
- ### `validateNodes(nodes)`
86
-
87
- Validates an array of TypeScript AST nodes for correctness before printing.
90
+ Factory returning a parser instance for `.tsx` and `.jsx` files. Same API and `extension` option as `parserTs`, with JSX support.
88
91
 
89
92
  ## Supporting Kubb
90
93
 
91
- Kubb is an open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
94
+ Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
92
95
 
93
96
  - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
97
+ - [See sponsorship tiers and our sponsors](https://kubb.dev/sponsors)
94
98
 
95
99
  <p align="center">
96
100
  <a href="https://github.com/sponsors/stijnvanhulle">
@@ -98,15 +102,19 @@ Kubb is an open source project with its ongoing development made possible entire
98
102
  </a>
99
103
  </p>
100
104
 
105
+ ## License
106
+
107
+ [MIT](https://github.com/kubb-labs/kubb/blob/main/licenses/LICENSE-MIT)
108
+
101
109
  <!-- Badges -->
102
110
 
103
- [npm-version-src]: https://img.shields.io/npm/v/@kubb/parser-ts?flat&colorA=18181B&colorB=f58517
104
- [npm-version-href]: https://npmjs.com/package/@kubb/parser-ts
105
- [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/parser-ts?flat&colorA=18181B&colorB=f58517
106
- [npm-downloads-href]: https://npmjs.com/package/@kubb/parser-ts
107
- [license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
111
+ [npm-version-src]: https://shieldcn.dev/npm/v/@kubb/parser-ts.svg?variant=secondary&size=xs&theme=zinc&mode=dark
112
+ [npm-version-href]: https://npmx.dev/package/@kubb/parser-ts
113
+ [npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/parser-ts.svg?variant=secondary&size=xs&theme=zinc&mode=dark
114
+ [npm-downloads-href]: https://npmx.dev/package/@kubb/parser-ts
115
+ [stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
116
+ [stars-href]: https://github.com/kubb-labs/kubb
117
+ [license-src]: https://shieldcn.dev/npm/license/@kubb/parser-ts.svg?variant=secondary&size=xs&theme=zinc
108
118
  [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
109
- [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
110
- [coverage-href]: https://www.npmjs.com/package/@kubb/parser-ts
111
- [sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
112
- [sponsors-href]: https://github.com/sponsors/stijnvanhulle/
119
+ [node-src]: https://shieldcn.dev/npm/node/@kubb/parser-ts.svg?variant=secondary&size=xs&theme=zinc&mode=dark
120
+ [node-href]: https://npmx.dev/package/@kubb/parser-ts