Skip to content

Commit

Permalink
refactor(src): create string-surround module
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
dustinspecker committed Apr 7, 2016
1 parent 6750d0a commit b78901a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"lib"
],
"dependencies": {
"is-plain-obj": "^1.1.0"
"is-plain-obj": "^1.1.0",
"string-surround": "^1.0.0"
},
"devDependencies": {
"ava": "^0.14.0",
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'
import isPlainObj from 'is-plain-obj'
import stringSurround from 'string-surround'

/**
* Replace a string's contents occurrences of keys of an object with the value of that key
Expand All @@ -19,7 +20,7 @@ module.exports = (str, obj, delimeter = '') => {
}

return Object.keys(obj).reduce((acc, key) => {
const regex = new RegExp(`${delimeter}${key}${delimeter}`, 'g')
const regex = new RegExp(stringSurround(key, delimeter), 'g')

return acc.replace(regex, obj[key])
}, str)
Expand Down

0 comments on commit b78901a

Please sign in to comment.