Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# stringinject

Inject an array, or an object of items in to a string replacing selected values.

## Install ##
## Install

``` bash
npm install stringinject
```

## Usages ##
## Usages

### Arrays ###
### Arrays

```javascript
import stringInject from 'stringinject';
Expand All @@ -23,12 +24,22 @@ var string = stringInject("This is a {0} string for {1}", ["test", "stringInject
// This is a test string for stringInject
```

### Objects ###
### Objects

You can also pass in an object with keys that exist as placeholders within the string. It will then find the placeholder based on your key and replace it with the value of that key from your object.

```javascript
var str = stringInject("My username is {username} on {platform}", { username: "tjcafferkey", platform: "GitHub" });

// My username is tjcafferkey on Github
```
```

### Formatting

You can also specify some basic numeric formatting. A TypeError will be thrown if a value can't be parsed.

```javascript
var string = stringInject("Values can be parseInt: {0:d} or parseFloat: {1:f}", [1.9, 2.1]);

// Values can be parseInt: 1 or parseFloat: 2.1
```
Loading