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

au-text-highlight

v1.0.0

Published

提供文本关键字匹配,文本划词获得选区范围, 以及自动高亮相关文本等功能

Downloads

89

Readme

au-text-highlight

文本关键字匹配模块, 主要用于以后的文字高亮和关键字检索, 后续会探索更多用途

项目背景

在一些应用场景中,比如划词(翻译,评论,等其他功能),搜索引擎,文本高亮等,都需要对文本进行关键字匹配, 并做相关处理,这个模块就是为了解决这一系列问题而生的。

安装

npm install au-text-highlight

使用

使用方面很简单,本模块提供了以下几个函数

  • 用户划取一段内容时,获取选区的startIndex, endIndex,只需要传入包裹的dom元素即可
import { getSelectionRange } from 'au-text-highlight'

const results = getSelectionRange(dom)
  • 自动高亮相关的关键字,只需要传入关键字的开始位置和结束位置和dom元素[{start: number, end: number}]的数组即可
import { sectionRangeHighlight } from 'au-text-highlight'
const results = sectionRangeHighlight(dom, [{start: 0, end: 3}])
  • 匹配一段字符串中的关键字的开始位置和结束位置 (如果匹配到多个,都会放到数组里), 参数是一段字符串和关键字
import { auExtractText } from 'au-text-highlight'

 const results = auExtractText({text, keywords: '关键字'})

 results: [
   {
      keyword: '关键字',
      start: 0,
      end: 3,
    }
 ]

贡献

如果你有好的想法或者发现了bug,欢迎提issue或者提交PR,非常欢迎参与!