react-string-format
v1.2.0
Published
Formats string using string, number, and react components as paramaters
Downloads
29,709
Maintainers
Readme
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>