https://github.com/ton-community/tlb-parser
Parse TL-B definitions into TypeScript objects
https://github.com/ton-community/tlb-parser
tlb ton typescript
Last synced: 2 months ago
JSON representation
Parse TL-B definitions into TypeScript objects
- Host: GitHub
- URL: https://github.com/ton-community/tlb-parser
- Owner: ton-community
- License: mit
- Created: 2022-11-06T16:38:31.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-12-05T14:40:40.000Z (3 months ago)
- Last Synced: 2025-12-07T11:59:43.597Z (3 months ago)
- Topics: tlb, ton, typescript
- Language: TypeScript
- Homepage:
- Size: 565 KB
- Stars: 26
- Watchers: 3
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: contributing.md
- License: LICENSE
Awesome Lists containing this project
README
# tlb-parser
[](https://www.npmjs.com/package/@ton-community/tlb-parser)
[](https://github.com/ton-community/tlb-parser/actions/workflows/qa.yml)
## Installation
```bash
npm install @ton-community/tlb-parser
```
## Usage
Create a file with TLB scheme according to the [documentation](https://docs.ton.org/develop/data-formats/tl-b-language). This is an example of such a file (call it `example.tlb`):
```
t$_ x:# y:(uint 5) = A;
```
Then do:
```bash
npx tlb-parser example.tlb
```
Or you can use the tool from inside JS or TS code.
```typescript
import { ast, NodeVisitor, ASTRootBase } from "@ton-community/tlb-parser";
class TestVisitor extends NodeVisitor {
public visited: { [key: string]: number };
constructor() {
super();
this.visited = {};
}
override genericVisit(node: nodes.ASTRootBase): void {
if (this.visited[node.constructor.name] === undefined) {
this.visited[node.constructor.name] = 0;
}
this.visited[node.constructor.name] += 1;
return super.genericVisit(node);
}
}
const scheme = `
t$_ x:# y:(uint 5) = A;
`;
const tree = ast(scheme);
const visitor = new TestVisitor();
visitor.visit(tree);
console.log(
util.inspect(
visitor.visited,
{showHidden: false, depth: null, colors: true},
),
);
console.log(
util.inspect(
tree,
{showHidden: false, depth: null, colors: true},
),
);
```
## Related
- IntelliJ plugin: https://github.com/ton-blockchain/intellij-ton