@kubb/parser-ts 5.0.0-beta.6 → 5.0.0-beta.7
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/README.md +112 -0
- package/package.json +4 -5
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>@kubb/parser-ts</h1>
|
|
3
|
+
<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">
|
|
5
|
+
</a>
|
|
6
|
+
|
|
7
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
8
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
9
|
+
[![Coverage][coverage-src]][coverage-href]
|
|
10
|
+
[![License][license-src]][license-href]
|
|
11
|
+
[![Sponsors][sponsors-src]][sponsors-href]
|
|
12
|
+
|
|
13
|
+
<h4>
|
|
14
|
+
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
15
|
+
<span> · </span>
|
|
16
|
+
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
17
|
+
<span> · </span>
|
|
18
|
+
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
|
|
19
|
+
</h4>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
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.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
bun add @kubb/parser-ts
|
|
28
|
+
# or
|
|
29
|
+
pnpm add @kubb/parser-ts
|
|
30
|
+
# or
|
|
31
|
+
npm install @kubb/parser-ts
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { print, createImport, createExport } from '@kubb/parser-ts'
|
|
38
|
+
import ts from 'typescript'
|
|
39
|
+
|
|
40
|
+
// Print a TypeScript source file from compiler AST nodes
|
|
41
|
+
const source = print([
|
|
42
|
+
ts.factory.createVariableStatement(
|
|
43
|
+
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
44
|
+
ts.factory.createVariableDeclarationList(
|
|
45
|
+
[ts.factory.createVariableDeclaration('hello', undefined, undefined, ts.factory.createStringLiteral('world'))],
|
|
46
|
+
ts.NodeFlags.Const,
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
])
|
|
50
|
+
// → 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
|
+
```
|
|
58
|
+
|
|
59
|
+
## API
|
|
60
|
+
|
|
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.
|
|
72
|
+
|
|
73
|
+
### `parserTsx`
|
|
74
|
+
|
|
75
|
+
Parser instance for `.tsx` files. Use with Kubb's file system to emit TSX source files.
|
|
76
|
+
|
|
77
|
+
### `createImport(options)`
|
|
78
|
+
|
|
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.
|
|
88
|
+
|
|
89
|
+
## Supporting Kubb
|
|
90
|
+
|
|
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:
|
|
92
|
+
|
|
93
|
+
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
94
|
+
|
|
95
|
+
<p align="center">
|
|
96
|
+
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
97
|
+
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
|
|
98
|
+
</a>
|
|
99
|
+
</p>
|
|
100
|
+
|
|
101
|
+
<!-- Badges -->
|
|
102
|
+
|
|
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
|
|
108
|
+
[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/
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/parser-ts",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
4
|
-
"description": "TypeScript and TSX file parser for Kubb
|
|
3
|
+
"version": "5.0.0-beta.7",
|
|
4
|
+
"description": "TypeScript and TSX source file parser for Kubb. Converts AST nodes and raw TypeScript code into formatted source strings using the TypeScript compiler API.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"code-generator",
|
|
7
6
|
"codegen",
|
|
8
7
|
"kubb",
|
|
9
8
|
"parser",
|
|
@@ -43,11 +42,11 @@
|
|
|
43
42
|
},
|
|
44
43
|
"dependencies": {
|
|
45
44
|
"typescript": "^6.0.3",
|
|
46
|
-
"@kubb/core": "5.0.0-beta.
|
|
45
|
+
"@kubb/core": "5.0.0-beta.7"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"@internals/utils": "0.0.0",
|
|
50
|
-
"@kubb/ast": "5.0.0-beta.
|
|
49
|
+
"@kubb/ast": "5.0.0-beta.7"
|
|
51
50
|
},
|
|
52
51
|
"engines": {
|
|
53
52
|
"node": ">=22"
|