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

text-lighter

v1.0.1

Published

通用的文本高亮包

Readme

HighLight Utility HighLight

这是一个用于高亮文本的 JavaScript 工具,也就意味着在Vue,React这样的现代框架也能使用。该工具可以在指定的 DOM 元素中查找并高亮显示指定的文本,支持自定义高亮效果。

非常轻量,只需几行代码就能实现下面的高亮效果

image

安装 🛠️

npm i text-lighter

功能 ✨

highLight 📌

`highLight(dom: HTMLElement, str: string, options: options)`

在指定的 DOM 元素中高亮指定的文本字符串。此函数使用 CSS 自定义高亮 API 将文本匹配区域高亮显示。

参数:

  • dom (HTMLElement): 需要进行高亮操作的 DOM 元素。

  • str (string): 需要高亮的文本字符串。此函数会查找所有匹配该文本的部分进行高亮。

  • options (object): 高亮配置项,包含以下参数:

    选项 ⚙️

    • isCaseSensitive (boolean, 默认值: false): 是否区分大小写。如果为 false,搜索时会忽略大小写。
    • cssName (string, 默认值: "default"): 用于标识该高亮的名称。可以通过此名称来管理不同的高亮效果。
    • ignoreText (string[], 默认值: []): 一个字符串数组,指定在搜索过程中要忽略的文本。可以避免某些不需要高亮的文本被匹配。

示例:

import { highLight } from 'highlighttext';

// 获取 DOM 元素
const element = document.getElementById('content');

// 高亮文本 'JavaScript'
highLight(element, 'JavaScript', {
  isCaseSensitive: false,
  cssName: 'js-highlight',
  ignoreText: ['不要高亮这个文本'],
});
//css 声明高亮的样式
::highlight(js-highlight) {
  background-color: #f06;
  color: white;
}

cancelAllHighLight 📌

取消所有通过 highLight 函数应用的高亮效果。

示例:

import { cancelAllHighLight } from 'highlighttext';

// 取消所有高亮
cancelAllHighLight();

cancelNameHighLight 📌

`cancelNameHighLight(cssName: string)`

取消指定 cssName 名称的高亮效果。

参数:

  • cssName (string): 要删除的高亮名称。

示例:

import { cancelNameHighLight } from 'highlighttext';

// 取消指定名称的高亮
cancelNameHighLight('js-highlight');

许可证 📜

此项目使用 MIT 许可证