1.0.3 • Published 4 years ago

@pelevesque/swap-substrings v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Build Status Coverage Status JavaScript Style Guide

swap-substrings

Swaps substrings.

Node Repository

https://www.npmjs.com/package/@pelevesque/swap-substrings

Installation

npm install @pelevesque/swap-substrings

Tests

CommandDescription
npm test or npm run testAll Tests Below
npm run coverStandard Style
npm run standardCoverage
npm run unitUnit Tests

Usage

Requiring

const swapSubstrings = require('@pelevesque/swap-substrings')

Swap Substrings

const str = 'bad bed led lad'
const swaps = ['a', 'e']
const result = swapSubstrings(str, swaps)
// result === 'bed bad lad led'
const str = 'dog treats for dogs, cat treats for cats'
const swaps = ['dog', 'cat']
const result = swapSubstrings(str, swaps)
// result === 'cat treats for cats, dog treats for dogs'

Swap Many Substring Pairs

const str = 'a fairly large man says oh oh oh to the bird'
const swaps = [
  ['a ', 'the '],
  ['man', 'bird'],
  ['large', 'small'],
  ['oh', 'tweet']
]
const result = swapSubstrings(str, swaps)
// result === 'the fairly small bird says tweet tweet tweet to a man'

Substitute Substrings (Replacement is not in the String)

const str = 'I like hamsters'
const swaps = ['hamsters', 'squirrels']
const result = swapSubstrings(str, swaps)
// result === 'I like squirrels'