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

vue-search-highlight

v1.1.7

Published

Vue文本关键字高亮组件,v1.1.0开始支持HTML内容跨标签匹配关键字。

Downloads

41

Readme

vue-search-highlight

Vue文本关键字高亮组件,v1.1.0开始支持HTML内容跨标签匹配关键字。

安装

# 使用yarn
yarn add vue-search-highlight

# 使用npm
npm install vue-search-highlight​

引入组件

像使用普通组件一样使用vue-search-highlight。

import SearchHighlight from 'vue-search-highlight'
// 注册为子组件
components: {
  'search-highlight': SearchHighlight
},​

组件props

| 名称 | 说明 | | --- | --- | | content | 需要展示的文本,搜索即在这个文本中进行。 | | keyword | 搜索关键字 | | highlightStyle | 所有关键词高亮的样式, 默认'background: #ffff00' | | currentStyle | 当前搜索到的关键词样式, 默认default: 'background: #ff9632' | | regExp | 启用正则匹配,会用关键词构建一个正则表达式来匹配。启用时请确保keyword能正确构造正则表达式,并且不会匹配空串,否则组件将不会匹配任何内容 |

组件事件

| 事件名 | 说明 | | --- | --- | | @current-change | 返回值:当前关键词索引(从1开始)。关键词改变的时候,如果搜索到内容,会返回1,搜索不到则返回0。 | | @match-count-change | 返回值:文本匹配关键词总数。 |

组件方法,可以通过ref调用

主要提供了关键词滚动到可视区域的方法: | 方法名 | 参数 | 说明 | | --- | --- | --- | | searchNext | 无 | 下一个关键词滚动到可视区域 | | searchLast | 无 | 上一个关键词滚动到可视区域 | | scrollTo | index | 滚动到第index(从1开始)个关键词 |

使用示例:

效果在线预览:https://wintc.top/laboratory/#/search-highlight

代码示例

<search-highlight
  class="search-highlight"
  ref="search"
  @current-change="currentChange"
  @match-count-change="matchCountChange"
  :content="content"
  :keyword="keyword">
</search-highlight>

<script>
import SearchHighlight from 'vue-search-highlight'

export default {
  components: {
    SearchHighlight
  },
  data () {
    return {
      currentIdx: 0,
      matchCount: 0,
      keyword: '明月',
      content: `
            春江花月夜
                [唐] 张若虚
      春江潮水连海平,海上明<b>月</b>共潮生。
      滟滟随波千万里,何处春江无月明!
      江流宛转绕芳甸,月照花林皆似霰;
      空里流霜不觉飞,汀上白沙看不见。
      江天一色无纤尘,皎皎空中孤月轮。
      江畔何人初见月?江月何年初照人?
      人生代代无穷已,江月年年望相似。
      不知江月待何人,但见长江送流水。
      白云一片去悠悠,青枫浦上不胜愁。
      谁家今夜扁舟子?何处相思明<b>月</b>楼?
      可怜楼上月徘徊,应照离人妆镜台。
      玉户帘中卷不去,捣衣砧上拂还来。
      此时相望不相闻,愿逐月华流照君。
      鸿雁长飞光不度,鱼龙潜跃水成文。
      昨夜闲潭梦落花,可怜春半不还家。
      江水流春去欲尽,江潭落月复西斜。
      斜月沉沉藏海雾,碣石潇湘无限路。
      不知乘月几人归,落月摇情满江树。`,
    }
  },
  methods: {
    searchNext () {
      this.$refs.search.searchNext()
    },
    searchLast () {
      this.$refs.search.searchLast()
    },
    matchCountChange (count) {
      this.matchCount = count
    },
    currentChange (idx) {
      this.currentIdx = idx
    },
    checkKeydown (event) {
      if (event.shiftKey) {
        this.searchLast()
      } else {
        this.searchNext()
      }
    }
  }
}
</script>