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

@gmb/bitmark-parser-generator

v5.2.0

Published

A bitmark parser and generator using Peggy.js

Downloads

1,188

Readme

@gmb/bitmark-parser-generator

Build & Test

A bitmark parser and generator using Peggy.js.

Try out bitmark - visit the bitmark Playground

Features:

  • Convert bitmark to JSON, and vice-versa.
  • Programmatically create or modify bitmark.
  • Works in NodeJS or the browser.
  • Validate and prettify bitmark.
  • Fast, with a small browser footprint, less than 60kB.

List of supported bits

Installation

Package manager

Using yarn:

$ yarn add @gmb/bitmark-parser-generator

Using npm:

$ npm install @gmb/bitmark-parser-generator

CDN

Using jsDelivr CDN (ES6 UMD module):

<script src="https://cdn.jsdelivr.net/npm/@gmb/bitmark-parser-generator@latest/dist/browser/bitmark-parser-generator.min.js"></script>

Using unpkg CDN (ES6 UMD module):

<script src="https://unpkg.com/@gmb/bitmark-parser-generator@latest/dist/browser/bitmark-parser-generator.min.js"></script>

Replace latest with a specific version in either of the URLs above to use a specific version.

Basic Usage

Import

// Modules
import { BitmarkParserGenerator } from '@gmb/bitmark-parser-generator';

// CommonJS
const { BitmarkParserGenerator } = require('@gmb/bitmark-parser-generator');

// Browser UMD
const { BitmarkParserGenerator } = window.bitmarkParserGenerator;

Conversion

const bpg = new BitmarkParserGenerator();

// Convert bitmark markup to bitmark JSON
const json = await bpg.convert("[.article] Hello World");

// Convert bitmark JSON to bitmark markup
const bitmark = await bpg.convert('[{"bitmark": "[.article] Hello World","bit": { "type": "article", "format": "bitmark++", "bitLevel": 1, "body": "Hello World" }}]');

// Convert bitmark markup file to bitmark JSON
await bpg.convert("./input.bitmark", { output: "./output.json" });

// Convert bitmark JSON to bitmark markup
await bpg.convert("./input.json", { output: "./output.bitmark" });

Convertion Options

// Convert bitmark JSON to bitmark markup with options
await bpg.convert("./input.json", {
  bitmarkParserType: 'peggy',      // The parser type to use. 'peggy' or 'antlr'. Default: 'peggy'
  outputFormat: 'ast',             // Output AST rather than the default output. Default: automatic
  outputFile: "./output.ast.json", // Output to file rather than <stdout>. Default: <stdout>
  fileOptions: {
    append: true,                  // Append to output file. Default: overwrite
    encoding: 'utf8',              // Specify a file encoding. Default: 'utf8'
  },
  jsonOptions: {
    prettify: 2,                   // Prettify the JSON output. Default: not prettified
    stringify: false,              // Return JSON as a string. Default: plain JS object
    includeExtraProperties: false, // Include extra (non-standard) properties from the markup in the JSON: Default: ignore
    debugGenerationInline: false,  // [development only] Include debugging tags in the generated output. Default: false
  },
  bitmarkOptions: {
    explicitTextFormat: false,     // Include bitmark text format even when it is the default (bitmark++). Default: false
    prettifyJson: 2,               // Prettify the body JSON output. Default: not prettified
    cardSetVersion: 1,             // Output markup using the specified cardSet format. Default: 1
    debugGenerationInline: false,  // [development only] Include debugging tags in the generated output. Default: false
  }
});

Programmatic Bitmark Creation

import { BitmarkParserGenerator, Builder, Ast, BitType, TextFormat } from 'bitmark-parser-generator';

const bpg = new BitmarkParserGenerator();
const builder = new Builder();

// Create bitmark AST programatically
const ast = builder.bitmark({
  bits: [
    builder.bit({
      bitType: BitType.article,
      textFormat: TextFormat.bitmarkText,
      body: builder.body({
        bodyParts: [
          builder.bodyText({
            text: "Hello World!"
          })
        ]
      }),
    })
  ]
});

// Write the AST to bitmark markup
bpg.convert(ast, { output: "./output.bitmark" });

// Write the AST to bitmark JSON
bpg.convert(ast, { output: "./output.json", outputFormat: 'json' });

Breakscaping

A text can be breakscaped programmatically for inclusion in bitmark.

NOTE: It is recommended the bit builder documented above in Programmatic Bitmark Creation is used rather than hand-coding bitmark creation, because it guarantees the bitmark will be valid, and all breakscaping will be correct.

When breakscaping a text for inclusion in bitmark, the breakscaping applied depends on where that text appears in the bitmark. The following four text locations require different breakscaping:

| Bit Format | Text Location | |----------|-------------| | bitmark++ | body | | bitmark++ | tag | | text (not bitmark++) | body | | text (not bitmark++) | tag |

Also, if a plain text divider ==== text ==== is used, then text after the divider must be breakscaped using text:body even if the bit is bitmark++.

import { BitmarkParserGenerator, BodyTextFormat, TextLocation, InputType } from 'bitmark-parser-generator';

const bpg = new BitmarkParserGenerator();


const breakscaped = bpg.breakscapeText("This is the [!text] to be breakscaped", {
  inputFormat: InputType.string, // or "string"
  textFormat: BodyTextFormat.bitmarkPlusPlus, // or "bitmark++"
  textLocation: TextLocation.body, // or "body"
});
// breakscaped = "This is the [^!text] to be breakscaped"


const breakscaped = bpg.breakscapeText("This is the [!text] to be breakscaped", {
  inputFormat: InputType.string, // or "string"
  textFormat: BodyTextFormat.bitmarkPlusPlus, // or "bitmark++"
  textLocation: TextLocation.tag, // or "tag"
});
// breakscaped = "This is the [!text^] to be breakscaped"

Info

Information about the supported bits can be retreived via the info API

import { BitmarkParserGenerator } from 'bitmark-parser-generator';

const bpg = new BitmarkParserGenerator();

// Write supported bit info to the console
const info = bpg.info();
console.log(JSON.stringify(info, null, 2));

Upgrade

The bitmark-parser-generator can 'upgrade' bitmark markup or JSON. This will upgrade the markup / JSON to the latest version and remove any invalid code or markup.

THIS FEATURE SHOULD BE USED WITH CAUTION. IT WILL POTENTIALLY DELETE DATA.

If the input contains data that is invalid or unrecognised, it will be removed from the output. Therefore it is recommended to use this feature with source code control or another system for data backup.

const bpg = new BitmarkParserGenerator();

// Upgrade bitmark markup
const json = await bpg.convert("[.article] Hello World [$I will be removed as I am invalid]");

// Upgrade bitmark JSON
const bitmark = await bpg.convert('[{"bitmark": "[.article] Hello World","bit": { "type": "article", "format": "bitmark++",
"bitLevel": 1, "body": "Hello World", unknownProperty: "Will be removed" }}]');

// Upgrade bitmark markup file to another file
await bpg.convert("./input.bitmark", { output: "./output.bitmark" });

// Upgrade bitmark JSON file to another file
await bpg.convert("./input.json", { output: "./output.json" });

Version

// Get the bitmar-parser-generator version
const version = bpg.version();

Advanced Usage

More advanced usage is possible, such as implementing custom streaming output writers.

See the API Documentation for more information.

License

This open source software is licenced under the ISC licence.