Skip to content

peterpme/sub-in

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SubIn

🥙 SubIn npm travis

A tiny (115B) find-and-replace utility for strings in Javascript.

Installation

If you're using Yarn:

yarn add sub-in

If you're using npm:

npm install sub-in

Usage

Create a string with any number of placeholders: $0, $1, $2, $3, $4, etc. Placeholders are zero based:

  • $0 = ['Peter'] (Peter)
  • $1 = ['Tom', 'Peter'] (Peter)
  • $2 = ['Tom', 'John', 'Peter'] (Peter)
const greeting = 'Hey $0, how are you doing?'
subIn(greeting, ['Peter'])

// Hey Peter, how are you doing?
const friends = '$0, $1 and $2 are my friends.'
subIn(friends, ['Jake', 'Tom', 'Zack'])

// Jake, Tom and Zack are my friends

About

🥙 A tiny (115B) find-and-replace utility for strings in Javascript

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published