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

als-highlight

v1.0.0

Published

Lightweight dependency-free syntax highlighter for HTML/CSS/JS with inline themes and optional toolbar.

Downloads

7

Readme

als-highlight

A lightweight, dependency-free syntax highlighter for HTML, CSS, and JavaScript that returns pure HTML.
No runtime CSS required (all colors are inline styles), and it ships with a curated set of editor-inspired themes.

  • No dependencies
  • Browser & Node friendly
  • Inline coloring (no extra stylesheets)
  • Optional toolbar with Copy / Wrap and line numbers
  • Themes inspired by Monokai, Dracula, One Dark, GitHub, etc.

Installation

npm i als-highlight

or via script tag (IIFE bundle):

<script src="https://unpkg.com/[email protected]/index.js"></script>
or
<script src="https://unpkg.com/[email protected]/index.min.js"></script>
<script>
  const h = new Highlighter('Monokai');
  const html = h.renderBlock('js', 'const x=1');
  document.body.insertAdjacentHTML('beforeend', html);
</script>

Package provides three entry points:

  • ESM: index.mjs
  • CJS: index.cjs
  • IIFE (browser): index.js (global window.Highlighter)

Quick Start

import Highlighter from 'als-highlight';

const h = new Highlighter('Monokai');    // or pass a custom colors object

// Raw highlighting (returns <pre><code>...</code></pre>)
const jsHtml   = Highlighter.highlightJs('const x = 42;', Highlighter.codeThemes.Monokai);
const cssHtml  = Highlighter.highlightCss('.box{color:#0af}', Highlighter.codeThemes.Monokai);
const htmlHtml = Highlighter.highlightHtml('<div id="x">Hi</div>', Highlighter.codeThemes.Monokai);

// Ready-to-use block with toolbar & line numbers
const block = h.renderBlock('js', `function sum(a,b){ return a+b }`, {
  wrapButton: true,
  copyButton: true,
  lineNumbers: true,
  maxWidth: '90vw',
  maxHeight: '50vh',
  padding: '.5rem',
});
document.body.insertAdjacentHTML('beforeend', block);

API

Static Themes

Highlighter.codeThemes  // object with many built-in themes
Highlighter.colors      // default theme (Monokai)

Available built-in themes include: Monokai, Dracula, One Dark, One Light, Solarized Dark/Light, Nord, Gruvbox Dark/Light, Material Palenight, Night Owl, Ayu Dark/Mirage, GitHub Dark/Light, Tokyo Night, Rosé Pine Moon, Cobalt2, VS Dark+, Oceanic Next.

Each theme is a color palette:

{
  bgc, c,        // background, default foreground
  definer,       // declarations: function/class/const/let/var/...
  reserved,      // keywords/operators/punct
  literal,       // numbers/booleans/null/etc
  string,        // strings/template strings
  comment,       // comments
  method,        // function/selector/method names
  params         // params/self/this
}

Static Highlight Functions

Highlighter.highlightJs(source, colors)    // => <pre><code>...</code></pre>
Highlighter.highlightCss(source, colors)   // => <pre><code>...</code></pre>
Highlighter.highlightHtml(source, colors)  // => <pre><code>...</code></pre>

colors is either one of the built-in palettes (Highlighter.codeThemes.Monokai) or a custom object with the same keys.

Constructor

const h = new Highlighter(colorsOrThemeName = Highlighter.colors);
  • colorsOrThemeName can be a string (theme name) or a colors object.

renderBlock(lang, code, opts)

Returns a ready-to-insert block with an optional toolbar and line numbers.

  • lang: 'js' | 'css' | 'html'
  • code: string
  • opts (all optional):
    • wrapButton (default true)
    • copyButton (default true)
    • lineNumbers (default true)
    • maxWidth (default '90vw')
    • maxHeight (default '50vh')
    • padding (default '.5rem')

Example:

const block = h.renderBlock('css', '.box{color:#0af}', { lineNumbers: false });

Notes & Limitations

  • JavaScript regex detection uses a safe heuristic to avoid false positives.
  • HTML parser is lightweight and supports:
    • tags, comments, CDATA, void elements
    • <script> & <style> bodies are re-highlighted with JS/CSS highlighters
    • basic attributes parsing (quoted/unquoted, boolean)
  • All colors are inline; you don’t need external CSS.
  • If you provide a custom colors object, ensure it has all keys (bgc, c, definer, reserved, literal, string, comment, method, params).

License

MIT