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 🙏

© 2024 – Pkg Stats / Ryan Hefner

stophtml

v1.0.3

Published

Tokenizes an HTML string, extracting plain text while ignoring HTML tags

Downloads

173

Readme

stophtml

A utility for Node.js (0.32 kB) and the browser (0.43 kB) that extracts plain text from an HTML string while ignoring HTML tags. It's useful for Natural Language Processing (NLP) tasks that require only the textual content of HTML documents.

Install

npm install stophtml

Or yarn:

yarn add stophtml

Alternatively, you can also include this module directly in your HTML file from CDN:

UMD: https://cdn.jsdelivr.net/npm/stophtml/dist/index.umd.js
ESM: https://cdn.jsdelivr.net/npm/stophtml/+esm
CJS: https://cdn.jsdelivr.net/npm/stophtml/dist/index.cjs

Usage

import stophtml from 'stophtml'

const input = '<p>This is <b>bold</b> and <i>italic</i>.</p>'
const segments = stophtml(input)

console.log(segments)

API

stophtml(input: string): string[]

Tokenizes an HTML string, extracting plain text while ignoring HTML tags.

  • input: The input HTML string to tokenize.

Returns an array of plain text segments extracted from the HTML string.

Related

  • boox – Performing full-text search across multiple documents by combining TF-IDF score with inverted index weight.
  • stopmarkdown – Extracts plain text from an Markdown string.
  • nomark – Transforms hypertext strings (e.g., HTML, Markdown) into plain text for natural language processing (NLP) normalization.
  • stopword – Allows you to strip stopwords from an input text (supports a ton of languages).

Benchmark

✓ test/index.bench.ts (2) 1305ms
     name                 hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · stophtml     136,571.33  0.0064  0.3648  0.0073  0.0069  0.0241  0.0263  0.1222  ±0.70%    68286   fastest
   · htmlparser2   68,310.52  0.0131  2.0111  0.0146  0.0138  0.0348  0.0458  0.0769  ±0.96%    34156


 BENCH  Summary

  stophtml - test/index.bench.ts >
    2.00x faster than htmlparser2
import { bench } from 'vitest'
import { Parser } from 'htmlparser2'
import stophtml from 'stophtml'

const html = getHtml()

bench('stophtml', () => {
  stophtml(html)
})

bench('htmlparser2', () => {
  htmlparser2Parser(html)
})

function htmlparser2Parser(text: string) {
  const res: string[] = []

  const parser = new Parser({
    ontext(data) {
      res.push(data)
    }
  })

  parser.write(text)
  parser.end()

  return res.join(' ')
}

function getHtml() {
  return `<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Template</title>
</head>
<body>
    <h1>Welcome to my HTML Template</h1>
    <p>This is a paragraph within the HTML template.</p>
    <ul>
        <li>List item 1</li>
        <li>List item 2</li>
        <li>List item 3</li>
    </ul>
    <img src="https://example.com/image.jpg" alt="Example Image">
    <a href="https://example.com">Visit our website</a>
</body>
</html>
`
}

Contributing

We 💛  issues.

When committing, please conform to the semantic-release commit standards. Please install commitizen and the adapter globally, if you have not already.

npm i -g commitizen cz-conventional-changelog

Now you can use git cz or just cz instead of git commit when committing. You can also use git-cz, which is an alias for cz.

git add . && git cz

License

GitHub

A project by Stilearning © 2024.