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

keywordhighlight

v1.0.6

Published

一个可以把文本多个关键字高亮的react组件

Downloads

29

Readme

KeywordsHighLight

多关键字高亮的 react 组件,正则关键字也能高亮 npm address keywordhighlight

How To Use

npm install -S keywordhighlight

import React from 'react';
import { render } from 'react-dom';
import KeywordsHighlight from 'keywordhighlight';

render(
  <KeywordsHighlight
    str="321字符串 stringObject 的 replace() 方法执行的是查找并替换的操作。它将在 stringObject 中查找与 regexp 相匹配的子字符串,然后用 replacement 来替换这些子串。如果 regexp 具有全局标志 g,那么 replace() 方法将替换所有匹配的子串。否则,它只替换第一个匹配子串。replacement 可以是字符串,也可以是函数。如果它是字符串,那么每个匹配都将由字符串替换。但是 replacement 中的 $ 字符具有特定的含义。如下表所示,它说明从模式匹配得到的字符串将用于替换。123"
    keywords={[
      /stringObject/,
      '替换',
      ['查找', text => <span style={{ color: 'yellow' }}>{text}</span>],
      [/replacement|匹配/, text => <span style={{ color: 'gray' }}>{text}</span>],
      ['regexp', 'green'],
      ['$', { fontWeight: 700, color: 'red' }],
      [/\d+/, 'orange'],
    ]}
  />,
  document.getElementById('app'),
);

params

 * str:为输入文本
 * keywords:是一个数组,数组元素可以是如下4种类型
    1 string|RegExp:要高亮的关键字或正则表达式。
    2 [string|RegExp,string]:第一个元素为要高亮的关键字或正则表达式,第二个元素为高亮颜色。
    3 [string|RegExp,object]:第一个元素为要高亮的关键字或正则表达式,第二个元素为高亮元素的style。
    4 [string|RegExp,fun]:第一个元素为要高亮的关键字或正则表达式,第二个元素高亮元素的render函数。
 * highlightClassName:高亮元素的全局类名。
 * normalClassName: 不高亮元素的全局类名。
 * highlightColor: 高亮元素的全局颜色。
 * normalColor: 不高亮元素的全局颜色。
 * regExpOption: 正则表达式的flags,默认gi。
 > 注意:RegExp不支持flags参数。

run effect

run effect