Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/peterpme/sub-in
🥙 A tiny (115B) find-and-replace utility for strings in Javascript
https://github.com/peterpme/sub-in
find-and-replace regex sub tiny
Last synced: 3 months ago
JSON representation
🥙 A tiny (115B) find-and-replace utility for strings in Javascript
- Host: GitHub
- URL: https://github.com/peterpme/sub-in
- Owner: peterpme
- Created: 2018-02-05T04:37:37.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-06T17:43:21.000Z (almost 7 years ago)
- Last Synced: 2024-09-18T13:49:56.371Z (4 months ago)
- Topics: find-and-replace, regex, sub, tiny
- Language: JavaScript
- Homepage: https://npm.im/sub-in
- Size: 44.9 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## 🥙 SubIn [![npm](https://img.shields.io/npm/v/sub-in.svg)](https://npm.im/sub-in) [![travis](https://travis-ci.org/peterpme/sub-in.svg?branch=master)](https://travis-ci.org/peterpme/sub-in)
A tiny (115B) find-and-replace utility for strings in Javascript.
# Installation
If you're using `Yarn`:
```sh
yarn add sub-in
```If you're using `npm`:
```sh
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)```es6
const greeting = 'Hey $0, how are you doing?'
subIn(greeting, ['Peter'])// Hey Peter, how are you doing?
``````es6
const friends = '$0, $1 and $2 are my friends.'
subIn(friends, ['Jake', 'Tom', 'Zack'])// Jake, Tom and Zack are my friends
```