substitute-substrings
Substitutes substrings.
Node Repository
https://www.npmjs.com/package/@pelevesque/substitute-substrings
Installation
npm install @pelevesque/substitute-substrings
Tests
Standard Style & Unit Tests
npm test
Unit Tests & Coverage
npm run cover
Usage
Requiring
const substituteSubstrings = require('@pelevesque/substitute-substrings')
Single Substitution
const str = 'abbc'
const substitutions = ['b', '2']
const result = substituteSubstrings(str, substitutions)
// result === 'a22c'
Substrings are not swapped like with https://github.com/pelevesque/swap-substrings
const str = 'ac'
const substitutions = ['a', 'c']
const result = substituteSubstrings(str, substitutions)
// result === 'cc'
Multiple Substitutions
const str = 'abbcabcc'
const substitutions = [
['a', '1'],
['b', '2'],
['c', '3']
]
const result = substituteSubstrings(str, substitutions)
// result === '12231233'
const str = 'a long stormy night and a little boy named jim'
const substitutions = [
['a ', 'the '],
['night', 'day'],
['jim', 'oscar'],
['long', 'short'],
['little', 'very tall']
]
const result = substituteSubstrings(str, substitutions)
// result === 'the short stormy day and the very tall boy named oscar'