npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

kotlin-parser

v0.0.12

Published

Kotlin parser powered by WebAssembly, with syntax trees, incremental parsing and semantic token classification.

Downloads

1,227

Readme

kotlin-parser

A Kotlin parser powered by WebAssembly, with syntax trees, incremental document updates and syntax-based semantic token classification. No JVM or Kotlin installation is required at runtime.

Installation

pnpm add kotlin-parser

The package is ESM-only and includes TypeScript declarations. Node.js usage is tested with Node 26.12.1. Browser consumers need a modern engine supporting Kotlin/Wasm (including Wasm GC); the project's Vite playground demonstrates browser and Worker integration.

Parse Kotlin source

import { tokenize, parseFile, parseScript } from 'kotlin-parser/wasm';

const source = 'val answer = 42';
const tokens = JSON.parse(tokenize(source));
const tree = JSON.parse(parseFile(source));
const scriptTree = JSON.parse(parseScript('println(42)'));

console.log(tokens, tree, scriptTree);

These APIs return JSON strings. Tokens contain kind, start and end; tree nodes contain kind, start, end, children and error. Source offsets use UTF-16 code units, with exclusive end offsets. Whitespace and comments are retained. Use parseFile for .kt and parseScript for .kts.

Importing kotlin-parser/wasm initializes the WASM module; its functions are synchronous afterward. For lazy initialization:

const parser = await import('kotlin-parser/wasm');
const tree = JSON.parse(parser.parseFile('class Example'));

Incremental documents

import {
  openDocument, editDocument, documentClassifications, closeDocument,
} from 'kotlin-parser/wasm';

const id = openDocument('val answer = 42', false); // false = .kt, true = .kts
try {
  const updatedTree = JSON.parse(editDocument(id, 13, 15, '43'));
  const spans = documentClassifications(id);
  // Int32Array records: [start, end, tokenTypeIndex, modifierBits].
  console.log(updatedTree, spans);
} finally {
  closeDocument(id);
}

Edits use offsets in the current document. documentTree(id) reads the current tree; applyDocumentEdit(id, start, end, text) updates it without serializing a tree. Close documents when no longer needed to release their retained state.

Editor utilities

import { tokenTypes, tokenModifiers, replacement } from 'kotlin-parser/editor';

const edit = replacement('val x = 1', 'val x = 2');
// { start: 8, end: 9, text: '2' }
console.log(tokenTypes, tokenModifiers, edit);

This lightweight entry does not load WASM. tokenTypes and tokenModifiers describe the classification records: the token index selects a token type, and bit i in the modifier mask selects tokenModifiers[i]. replacement computes one contiguous text replacement between two source snapshots.

There is no root export: import kotlin-parser/wasm or kotlin-parser/editor explicitly.

Scope

The current syntax baseline is Kotlin 2.4.21. Parsing and classification are syntactic; this package does not perform compiler type checking or general symbol resolution. Additional exports provide document symbols and limited navigation. See the architecture and tested compatibility scope.

Apache-2.0. See upstream attribution. Report issues in the project repository.