@ton-community/tlb-parser
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

tlb-parser

Installation

npm install @ton-community/tlb-parser

Usage

Create a file with TLB scheme according to the documentation. This is an example of such a file (call it example.tlb):

t$_ x:# y:(uint 5) = A;

Then do:

npx tlb-parser example.tlb

Or you can use the tool from inside JS or TS code.

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

Package Sidebar

Install

npm i @ton-community/tlb-parser

Weekly Downloads

5

Version

0.1.3

License

MIT

Unpacked Size

138 kB

Total Files

49

Last publish

Collaborators

  • thekiba
  • ikardanov
  • shahary
  • krigga
  • altox7
  • talkol