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

v0.1.0

Published

A wrapper component of RN Text component, use regular expression to match and change the style, props of partial text content.

Downloads

2

Readme

react-native-style-text

A wrapper component of RN Text, you can use this component just like RN Text component.

You can use sting or regular expression to match text content, change its style and props.

Installation

yarn add react-native-style-text

or

npm i react-native-style-text

Demo

Usage

Example 1:

<StyleText
  style={{ color: 'black', fontSize: 16 }}
  matchText={[
    {
      match: 'Privacy Policy',
      textProps: {
        style: { color: 'blue', textDecorationLine: 'underline' },
        onPress: () => {
          ToastAndroid.show(
            'Jump to "Privacy Policy Page"',
            ToastAndroid.SHORT
          );
        },
      },
    },
    {
      match: 'Terms of Use',
      textProps: {
        style: { color: 'blue', textDecorationLine: 'underline' },
        onPress: () => {
          ToastAndroid.show(
            'Jump to "Terms of Use Page"',
            ToastAndroid.SHORT
          );
        },
      },
    },
  ]}
>
  Please accept the Privacy Policy and Terms of Use.
</StyleText>

Example 2:

<StyleText
  style={{ fontSize: 16, color: 'gray' }}
  matchText={[
    {
      match: /Tesla/gi,
      textProps: {
        style: { color: 'red', fontSize: 18 },
      },
    },
    {
      match: /Elon Musk/gi,
      textProps: {
        style: { color: 'black', fontSize: 18 },
      },
    },
  ]}
>
  Tesla chief executive Elon Musk has sold around $5bn of shares in the
  electric carmaker. It comes days after he asked his 63 million Twitter
  followers whether he should sell 10% of his stake in Tesla. The
  company's shares fell by around 16% in the two days after the poll
  came came out in favour of him selling shares, before regaining some
  ground Wednesday. Tesla is the world's most valuable carmaker, with a
  market valuation of more than $1tn. Mr Musk's trust sold almost 3.6
  million shares in Tesla, worth around $4bn.
</StyleText>

Example 3:

<StyleText
  style={{ fontSize: 16, color: 'gray' }}
  matchText={{
    match: /\d+.?\d*?/gi,
    textProps: {
      style: { color: '#FF1493' },
    },
  }}
>
  The ad in the Sunday paper clearly says it's only $2.99 for a baker's
  dozen. But the store clerk insisted on giving me only 12 doughnuts. So
  I finally had to call the manager. I was right a baker's dozen is 13.
</StyleText>

Props

| Prop | Type | Default | Require | Description | | ----------------- | ------ | ----------- | ------- | ---------------------------------------------------------- | | TextProps |TextProps | null | N | Props of RN Text component, like "style", "numberOfLines", eg. https://reactnative.dev/docs/text#props | | matchText | object / Array | null | N | Match the content you want and set the text props for it. |

Example of matchText:

{
    match: /Github/gi,
    style: {
        fontWeight: 'bold'
    }
}

or

[
    {
        match: 'Privacy Policy',
        style: { color: 'blue' }
    },
    {
        match: /Github/gi,
        style: { 
            fontWeight: 'bold',
            onPress: () => {}
        }
    }
]

How it works

If I want to make the below keyword "react" to be red.

<Style>react native style text from <Text>Github</Text></Style>

to

["react native style text from ", <Text>Github</Text>];

to

[<Text style={{ color: 'red' }}>react</Text>, " native style text from ", <Text>Github</Text>]

at last, use the RN Text component to render it.

<Text>[balabala]</Text>

License

MIT