Skip to content

berezh/react-string-format

Repository files navigation

react-string-format

Formats string using string, number, and react components as paramaters

Usage

Installation:

npm install react-string-format

Import

import { format } from 'react-string-format';

String

format('first: {0}; second: {1}', 'hello', 'word');
// result:
'first: hello; second: word'

Number

format('first: {0}; second: {1}', 1, 2);
// result:
'first: 1; second: 2'

React component

format('hiperlink: {0}, span tag: {1}', <a href="#">Click Me</a>, <span>Bla-bla</span>);
// result:
<React.Fragment>
    <React.Fragment key={0}>hiperlink: </React.Fragment>
    <React.Fragment key={1}>
        <a href="#">Click Me</a>
    </React.Fragment>
    <React.Fragment key={2}>, span tag: </React.Fragment>
    <React.Fragment key={3}>
        <span>Bla-bla</span>
    </React.Fragment>
</React.Fragment>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published