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

prehighlight

v0.0.4

Published

Highlight the first few letters of the word

Readme

prehighlight processes either an HTML string or a DOM node to bold the first few letters of each English word.

case

Install

pnpm install prehighlight

Usage

Highlighting an HTML string:

const html = `
    <div>
        <p>The DOM, or Document Object Model</p>
        <p>dangerous</p>
        <p>This is very <i>important</i></p>
    </div>
`
const res = prehighlight(html)
/*
res:
<div>
    <p><b>T</b>he <b>DO</b>M, <b>o</b>r <b>Docu</b>ment <b>Obj</b>ect <b>Mo</b>del</p>
    <p><b>dange</b>rous</p>
    <p><b>Th</b>is <b>i</b>s <b>ve</b>ry <i><b>impor</b>tant</i></p>
</div>
*/

Highlighting a DOM node:

const dom = new DOMParser().parseFromString(
  '<body>hello world</body>',
  'text/html'
)
const res = prehighlight(dom.body)
/*
res:
<b>he</b>llo <b>wo</b>rld
*/

API

prehighlight

Parameters:

  • html?: string | Node – An HTML string or a DOM node.
  • options?: HighlightOptions – Configuration options (see below).

Returns:

  • string | Node – Returns a string by default. To return a DOM node instead, set returnDom: true in the config.

HighlightOptions

--inplace?: boolean

If true, modifies the provided DOM node in-place. Only works when the html parameter is a DOM node. Using this with an HTML string will throw an error. When enabled, the return type is a Node.

--returnDom?: boolean

If true, returns a DOM node. Defaults to returning the innerHTML under the <body> tag as a string. Set to true to get the node itself.

--returnDomFragment?: boolean

Only effective if returnDom is true. This flag alone won’t work—must be used together: { returnDom: true, returnDomFragment: true }. When enabled, returns a document fragment instead of a full DOM node.

--returnWholeBody?: boolean

By default, if the input is <body><div>hello</div></body>, the returned value will be <div><b>he</b>llo</div>, excluding the <body> tag. Setting this to true will include the <body> tag in the output, i.e. <body><div><b>he</b>llo</div></body>.

--highlightPrefixLength?: (word: string) => number

A function to determine how many letters of a word should be highlighted. The default implementation as follows. For certain special words, such as don't, mother-in-law, and and/or, non-letter symbols are used as splitting points when passed into highlightPrefixLength. For example, don't will be split into don and t.

function highlightPrefixLength(word: string): number {
  if (isSpecificWord(word)) {
    return 1
  }
  else if (word.length <= 2) {
    return 1
  }
  else if (word.length <= 5) {
    return 2
  }
  else {
    return Math.ceil(word.length / 2)
  }
}

isSpecificWord

Determines whether a word is part of a predefined list of common English words. If it is, only the first letter is highlighted. The word list includes:

[
  'the',
  'and',
  'in',
  'on',
  'at',
  'by',
  'with',
  'about',
  'against',
  'between',
  'into',
  'through',
  'during',
  'before',
  'after',
  'above',
  'below',
  'to',
  'from',
  'up',
  'down',
  'over',
  'under',
  'again',
  'further',
  'then',
  'once',
  'here',
  'there',
  'when',
  'where',
  'why',
  'how',
  'all',
  'any',
  'both',
  'each',
  'few',
  'more',
  'most',
  'other',
  'some',
]