Skip to content

ETLaurent/replace-occurences

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Replaces Occurrences

What is this?

Just some code I wanted to keep.

How to use this?

Honestly, use String.prototype.replace() if you just need to replace few occurrences.

But...

You can do this:

const replaceOccurrences = require('replace-occurrences')

const string = 'My name is {{surname}}, {{name}} {{surname}}.'
const name = 'James'
const surname = 'Bond'

const result = replaceOccurrences(string, { name, surname })) // 'My name is Bond, James Bond.'

// instead of:

const result = string
  .replace(/\{\{name\}\}/g, name)
  .replace(/\{\{surname\}\}/g, surname)

TODO:

  • put it in the String prototype?

About

Useless code I want to keep

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published