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-text-format

v2.0.32

Published

React Component to find and parse links, emails, phone numbers, credit cards and keywords to required format.

Downloads

4,500

Readme

react-text-format

React Component to find and parse links, emails, phone numbers, image's URL, credit cards and keywords to required format.

NPM JavaScript Style Guide Hire me

View live demo here

Installation

yarn add react-text-format

or

npm install react-text-format --save

Basic Usage

import ReactTextFormat from 'react-text-format';

React.render(
    <ReactTextFormat>
      This is demo link http://www.google.com
      This is demo email <span data-email="[email protected]">[email protected]</span>

      This is demo image https://preview.ibb.co/hqhoyA/lexie-barnhorn-1114350-unsplash.jpg

      This is demo credit Card 5555555555554444
      This is demo phone Number 123.456.7890
      This is demo phone Number (212) 555 1212
      This is demo phone Number (212) 555-1212
      This is demo phone Number 212-555-1212 ext. 101
      This is demo phone Number 212 555 1212 x101

      This is an anchor <a href="http://formatter.com">http://formatter.com</a>;
    </ReactTextFormat>,
  document.body
);
Output:

Generated Avatar

Advance Usage

import ReactTextFormat from 'react-text-format';

customLinkDecorator = (
    decoratedHref: string,
    decoratedText: string,
    linkTarget: string
  ): React.Node => {
    return (
      <a
        href={decoratedHref}

        target={linkTarget}
        rel='noopener'
        className='customLink'
      >
        {decoratedText}
      </a>
    )
  }

customImageDecorator = (
    decoratedURL: string
    ): React.Node => {
    return (
      <div>
        <img src={decoratedURL}  rel='noopener' width="100" className='customImage' />
      </div>
)
}

customEmailDecorator = (
    decoratedHref: string,
    decoratedText: string
    ): React.Node => {
    return (
      <a href={decoratedHref}  className='customEmail'>
        {decoratedText}
      </a>
    )
}

customPhoneDecorator = (
    decoratedText: string
    ): React.Node => {
    return (
      <a href={`tel:${decoratedText}`} className='customPhone'>
        {decoratedText}
      </a>
    )
}

customCreditCardDecorator = (
    decoratedText: string
    ): React.Node => {
    return (
      <i  className='customCreditCard'>
        <b>{decoratedText}</b>
      </i>
    )
}

customTermDecorator = (decoratedText: string): React.Node => {
  return (
    <b  className="keyword">
      {decoratedText}
    </b>
  );
};

React.render(
    <ReactTextFormat
          allowedFormats={['URL', 'Email', 'Image', 'Phone', 'CreditCard']}
          linkDecorator={customLinkDecorator}
          emailDecorator={customEmailDecorator}
          phoneDecorator={customPhoneDecorator}
          creditCardDecorator={customCreditCardDecorator}
          imageDecorator={customImageDecorator}
          terms={["Link", "phone", "image", "Anchor", "email", "Credit"]}
          >
            This is demo link http://www.google.com
            This is encoded Link http://go%2Emsn%2Ecom/nl/133942%2Easp
            This is demo email <span data-email="[email protected]">[email protected]</span>

            This is demo image
            https://preview.ibb.co/hqhoyA/lexie-barnhorn-1114350-unsplash.jpg

            This is demo credit Card 5555555555554444

            This is demo phone Number 123.456.7890
            This is demo phone Number (212) 555 1212
            This is demo Phone Number (212) 555-1212
            This is demo phone Number 212-555-1212 ext. 101
            This is demo phone Number 212 555 1212 x101

            This is an anchor <a href="http://formatter.com">http://formatter.com</a>;
        </ReactTextFormat>,
        document.body
);
Output:

Generated Avatar

Props

|Name | Type | Default | |---|---|---| |allowedFormats| Array ['URL', 'Email', 'Image', 'Phone', 'CreditCard', 'Term']| ['URL', 'Email', 'Phone', 'Term'] | |linkTarget| String (_blank | _self | _parent | _top | framename) | _self | |terms| Array of strings | [] | |linkDecorator| React.Node (decoratedHref: string, decoratedText: string, linkTarget: string) | Output Format: <a href="{URL}" target="{target}" rel='noopener' className='rtfLink'> <URL> </a>
|emailDecorator| React.Node (decoratedHref: string, decoratedText: string) | Output Format:<a href="mailto: {EMAIL ADDRESS}" className='rtfEmail'> {EMAIL ADDRESS} </a> | |phoneDecorator| React.Node (decoratedText: string) | Output Format<a href="tel:{PHONE NUMBER}" className='rtfEmail'> {PHONE NUMBER} </a> | |creditCardDecorator| React.Node (decoratedText: string) | Output Format: <span className='rtfCreditCard'> {CREDIT CARD NUMBER} </span> | |imageDecorator| React.Node (decoratedURL: string) | Output Format: <img src="{URL OF IMAGE}" rel='noopener' className='rtfImage' /> | |termDecorator| React.Node (decoratedText: string) | Output Format: <span className='rtfTerm'>{decoratedText}</span> |