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

react-linkify-all

v1.4.6

Published

Modal pop up on hover, clickable links in text - everything is here. This is NPM package that converts text with links into an array of React components. Customizable. Built-in support of emails, Telegram, Twitter mentions. Own pattern can be used to link

Downloads

117

Readme

react-linkify-all

Preview

Try it on CodeSandBox: https://codesandbox.io/s/compassionate-meitner-y8d9l9

Popup functionality:

Code:

Description

Modal pop up on hover, clickable links in text - everything is here. This is NPM package that converts text with links into an array of React components. Customizable. Built-in support of emails, Telegram, Twitter mentions. Modal pop up can be implemented as it shown above. Own pattern can be used to linkify everything

Installation

npm i react-linkify-all

Basic Usage

import { Linkify } from 'react-linkify-all'
...
<Linkify links twitters emails>Some text with links.net, @twitters and [email protected]</Linkify>

Available props: emails, instagrams, links, tgs, twitters
And their corresponding components: <Emails/>, <Instagrams/>, <Links/>, <Tgs/>, <Twitters/>

Also you can use method linkify() to linkify(an example is given below).

Example with react components:

Code:

Result HTML:

Nesting is not supported yet: use <Linkify links twitters emails... /> to summarize effects

Own components and patterns

You could use your own component for links:

const component = (match, i, link) => {
    return <a href={link} style={{color:"yellow"}}>#{i}. {match}</a>;
}
...
<Linkify ... component={component}>...</Linkify>

The "i" parameter can be used to number links(there is a counter for each type of link) Parameters "match" and "link" may differ.

Example #1:

<Links>site.com</Links>

match: site.com
link: https://site.com
i: 1

Creating own patterns

Every pattern for linkify is set by an object:

const option = {
    regex: RegExp, //          /(...)/g,
    component?: (match, i, link) => ReactElement,
    linkFn?: (match:string) => string
}

WARNING: be sure to put parentheses around the regular expression. In addition, every internal capturing group should be not captured. RegEx should capture only the entrie word you need.

The default component is:

const defaultComponent = (match, i, link) => <a href={link}>{match}</a>;

"linkFn" is a function for converting a match into a link. In Example #1 above, linkFn is:

const example = match => match.substring(0, 4) === 'http' ? match : 'https://'+match

(It is used to handle matches like site.com and https://site.com)

Using own patterns

const option = {
    regex: new RegExp("((?<=\\B)@[a-zA-Z0-9_]{5,32}(?=\\b))", "g"),
    component: (match, i, link) => <a href={link}>{match}</a>,
    linkFn: match => "https://twitter.com/"+match.substring(1)
  };
...
<Linkify options={option}>...</Linkify>

This example will wrap every Twitter profile mention into <a/> tag.

Also, you can combine options:

<Linkify options={[option1, option2, ..., optionN]}>...</Linkify>

They will be applied consistently

Example with linkify() method

import { linkify } from 'react-linkify-all';
...
const Card = (text) => {
    const option = ...;
    const result = linkify(text, option);
    return <div>{result}</div>;
}

Contacts

If you find react-linkify-all to be useful in your project, please consider to star and support it: https://github.com/suvmer/react-linkify-all
If you want to contact me, send an email to [email protected]
I'm also available on Telegram: https://t.me/suvmers