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-native-formatted-text

v0.1.5

Published

An easy way to dynamically add text format in react native

Downloads

351

Readme

react-native-formatted-text

An easy way to dynamically add text format in react native

  • Provides multiple approaches to locate text needs to be formatted
  • Easy to customize with any valid Text styles
  • Automatically detect and handle link or email in the string

Example

examples/App.js

Installation

If using yarn:

yarn add react-native-formatted-text

If using npm:

npm i react-native-formatted-text

Usage

import { FormattedText } from 'react-native-formatted-text';

Simply wrap the text in FormattedText tags. You may use ranges prop and to declare start and end index of the text.

<FormattedText ranges={{start: 6, end: 12, style: {color: 'red'}}}>
  Hello, World!
</FormattedText>

Another way is to use matches and provide a text or regex value.

<FormattedText
  matches={[
    {text: 'Hello', style: {color: 'red'}},
    {regex: /World/g, style: {color: 'blue'}},
  ]}>
  Hello, World!
</FormattedText>

Both ranges and matches accept Object for a single lookup or array for multiple setups.

Documentation

Base props

| Name | Description | Default | Type | | ---------------- | ----------------------------------------------- | ------------ | --------------- | | ranges | Declares matching range | [] | Array or Object of Range | | matches | Provides text or regex value for string matches | [] | Array or Object of Match | | enabledLinkTypes*| Enables automatic link checking | [] | Array or Object of LinkMatch |

* This feature uses naive regex to match url/email by design. If a more comprehensive matching is desired, use matches instead. One can also use more specialized libraries as react-native-hyperlink.

Range Object

| Name | Description | Type |
| ----------- | --------------------------------------------------- | ------------ | | start | Defines start index of text to format, inclusive | Int | | end | Defines end index of text to format, exclusive | Int | | style | Provides format style, can use any valid Text style | Object | | onPress | Defines the function of press event | Func |

Match Object

| Name | Description | Type |
| ----------- | --------------------------------------------------- | ------------ | | text | Defines the text to format | Int | | regex | Provides a regex to find text to format | Int | | style | Provides format style, can use any valid Text style | Object | | onPress | Defines the function of press event | Func |

Link Match Object

| Name | Description | Type |
| ----------- | --------------------------------------------------- | ------------------------- | | type | Set a link type to format | FORMATTED_LINK_MATCH_TYPE | | style | Provides format style, can use any valid Text style | Object | | onPress | Defines the function of press event | Func |

Contributing

Pull requests are welcome! Open a new GitHub issue for any bug or suggestion.

Author

Xiao Ma

Roadmap

  • Allow range overlapping
  • A more flexible matches approach that allows to format all matched text or ones before/after certain index
  • Provide a way to customize press feedback UI
  • Add more link detection type

License

MIT