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

@sutrata/parser

v0.3.0

Published

Reference parser for Sutra, a plain-text screenplay format for world languages: AST, byte-faithful round-trip, Fountain import/export, Indic romanization.

Readme

@sutrata/parser

The reference parser for Sutra, a plain-text screenplay format based on Fountain and designed for world languages. Sutra stores Latin, Devanagari, Tamil, Telugu, Kannada, Malayalam, Bengali, Gujarati, Gurmukhi, Odia, Sinhala and other scripts natively, in logical order.

  • Parses Sutra text into a typed AST, and serializes it back byte for byte: parse a file and serialize it unchanged, and you get identical text.
  • Imports and exports Fountain.
  • Romanizes Indic scripts to Latin (ISO 15919, plus a readable and a diacritic-free colloquial variant) for export.
  • Has no UI dependencies. It runs in Node and in the browser, and is ESM only.

This is the parser used by Sutrata, a multilingual screenplay editor. The format itself is defined in the Sutra format specification, which anyone is free to implement.

Install

npm install @sutrata/parser

What Sutra looks like

---
title:
  en: Last Train
  hi: आख़िरी ट्रेन
lang: hi
page: A4
---

## INT. रेलवे स्टेशन - रात {#sc1}
& synopsis: मीरा और विक्रम सच जानते हैं।
& actors: मीरा, विक्रम

प्लेटफ़ॉर्म खाली है।

@मीरा
( धीरे से )
हम ट्रेन छूट गए, है ना?

>> CUT TO:

In this example:

  • YAML frontmatter holds the title page (the title can be given in several languages).
  • ## starts a scene heading, and {#sc1} gives the scene a stable ID.
  • & lines are scene metadata.
  • @ marks a character cue; the cue is followed by an optional parenthetical and the dialogue.
  • >> marks a transition.

See the format spec for the full grammar.

Usage

Parse and serialize

import { parse, serialize } from '@sutrata/parser'

const doc = parse(source)          // DocumentNode
doc.frontmatter?.data              // { title: { en: 'Last Train', hi: 'आख़िरी ट्रेन' }, lang: 'hi', ... }
doc.children                       // ContentNode[]: sections, scene headings, action, dialogue, ...

serialize(doc) === source          // true: round-trip is byte-faithful

Every node keeps the source text it was parsed from, and serialize writes that text back. Metadata keys, frontmatter keys and scene attributes that the parser doesn't recognise are preserved, not dropped, so files written by newer tools survive a round trip through older ones.

Source spans

import { parseWithSpans } from '@sutrata/parser'

const { document, frontmatter, children } = parseWithSpans(source)
source.slice(children[0].start, children[0].end)   // the first top-level node's text

children[i] is where document.children[i] sits in source: a scene runs from its heading line to the end of its last block. Only blank lines lie between spans, so cutting at the start of every # and ## heading splits a document into parts that join back byte for byte. Offsets are string indices into the original source, CRLF line endings included.

Fountain

import { importFountain, fountainDocToSutra, exportFountain } from '@sutrata/parser'

const { document, warnings } = importFountain(fountainText)
const sutraText = fountainDocToSutra(document)

const { text, warnings: lost } = exportFountain(parse(sutraText))
// Fountain has no equivalent for some Sutra features (scene metadata, for example).
// `lost` lists what was dropped, e.g.
// 'metadata dropped in Fountain export for scene "INT. रेलवे स्टेशन - रात"'

Romanization

import { romanize, romanizeSutra } from '@sutrata/parser'

romanize('हम ट्रेन छूट गए, है ना?', { variant: 'strict', languages: ['hi'] })
// 'hama ṭrēna chūṭa gaē, hai nā?'     (ISO 15919)
romanize('हम ट्रेन छूट गए, है ना?', { variant: 'readable', languages: ['hi'] })
// 'ham ṭren chūṭ gae, hai nā?'
romanize('हम ट्रेन छूट गए, है ना?', { variant: 'colloquial', languages: ['hi'] })
// 'ham tren chhoot gae, hai naa?'

// Romanize a whole Sutra document, or only its dialogue, and get Sutra back:
const romanized = romanizeSutra(source, { scope: 'dialogue', variant: 'readable' })

Romanization only converts to Latin; there is no way back to the native script. It's meant for exports, such as a romanized PDF for actors who don't read the script.

Other exports

  • parseFrontmatter / serializeFrontmatter: work on the frontmatter block on its own.
  • documentLanguages(frontmatterData): returns the document's languages, from lang and lang-secondary.
  • tokenize(line): the lexer for a single line.
  • All AST node types: DocumentNode, ContentNode, SceneHeadingNode, CharacterNode, and the rest.

License

Apache-2.0. The Sutra format specification is licensed CC BY 4.0.