Skip to content

Commit

Permalink
support a compatibility with interpolation format for rails and i18n-js
Browse files Browse the repository at this point in the history
  • Loading branch information
toshiwo committed Feb 26, 2016
1 parent 37e42b8 commit b6b2490
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* https://github.com/Matt-Esch/string-template/index.js
*/

const RE_NARGS = /\{([0-9a-zA-Z]+)\}/g
const RE_NARGS = /(%|)\{([0-9a-zA-Z]+)\}/g


/**
Expand All @@ -24,7 +24,7 @@ export default function (string, ...args) {
args = {}
}

return string.replace(RE_NARGS, (match, i, index) => {
return string.replace(RE_NARGS, (match, prefix, i, index) => {
let result

if (string[index - 1] === '{' &&
Expand Down
7 changes: 7 additions & 0 deletions test/specs/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ describe('format', () => {
name: 'kazupon', email: '[email protected]'
}), 'name: kazupon, email: [email protected]')
})

it('should be replace with object value', () => {
let template = 'name: %{name}, email: %{email}'
assert(format(template, {
name: 'kazupon', email: '[email protected]'
}), 'name: kazupon, email: [email protected]')
})
})

context('Array', () => {
Expand Down

0 comments on commit b6b2490

Please sign in to comment.