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

highlight-ts

v9.12.1-2

Published

Highlight.JS in TypeScript (and ES6).

Readme

HighlightJS in TypeScript (and ES6)

License: BSD npm version npm downloads Build Status

This is a port of the highlight.js to a TypeScript (as well as ECMAScript 6).

NOTE: Currently not all languages are supported. PRs are welcome.

Usage example

import {
  Options,
  Highlighter,

  // import basic APIs
  registerLanguages,
  htmlRender,
  init,
  process,
  
  // import preferred languages
  CPlusPlus,
  TypeScript,
  JavaScript,
  Python,
  Lua,
  Markdown
} from 'highlight-ts';

// register languages
registerLanguages(
  CPlusPlus,
  TypeScript,
  JavaScript,
  Python,
  Lua,
  Markdown
);

const options: Options = {
  classPrefix: '',
  /* other options */
};

// initialize highlighter
const highlighter: Highlighter<string>
  = init(htmlRender, options);

const source = `
interface Point {
  x: number,
  y: number,
}

function distance(a: Point, b: Point): number {
  return Math.sqrt(
    (a.x - b.x) ** 2 +
    (a.y - b.y) ** 2);
}
`;

// render source with given language mode
const language = 'ts';
const html = process(highlighter, source, language);

// or highligh source using auto language detection
const languages = ['ts', 'js', 'md'];
const html = process(highlighter, source, languages);

// auto detection using all known language modes
const html = process(highlighter, source);

// display result
elm.innerHTML = `<pre>${html}</pre>`;

Differences from original

  • Complete re-implementation using modern JavaScript syntax and features.
  • No module-global state and configuration excluding the language modes registry.
  • ES6 Module Syntax to compatibility with modern bundlers like Rollup which support Tree-Shaking.
  • Support renderer API to render to HTML text as well as to a DOM-nodes directly or by VirtualDOM engines.
  • Compiled mode it is another object not same as a source what get a little bit lower memory usage.
  • Replaced some utility functions by ES6 syntax extensions which is provided by tslib for ES5 target.
  • Fixed some modes to get more correct or advanced highlight.

Renderer API

Currently the renderer API is quite simple:

export interface Renderer<Output> {
    text(chunk: string): Output;
    wrap(className: string, chunk: Output): Output;
    join(chunks: Output[]): Output;
}
  1. The text() call is using to render textual piece of source code.
  2. The wrap() call is using to wrap rendered chunk into span with specified class.
  3. The join() call is using to join several rendered chunks into single chunk.

By example we can implement HTML renderer like this:

import { Renderer } from 'highligh-ts';

const htmlRender: Renderer<string> = {
    text: (chunk: string) => chunk
        .replace(/&/g, '&amp;')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;'),
    join: (chunks: string[]) => chunks.join(''),
    wrap: (className: string, chunk: string) =>
        `<span class="${className}">${chunk}</span>`
};

HighlightJS API

See the types.ts source to understand highlight mode definition syntax.

Read the original highlightjs docs to get more help how to implement syntax highlighting modes.