Skip to content

Commit

Permalink
Merge pull request #23 from toshiwo/support_a_compatibility_with_inte…
Browse files Browse the repository at this point in the history
…rpolation_format_for_rails

support a compatibility with interpolation format for rails and i18n-js
  • Loading branch information
kazupon committed Feb 29, 2016
2 parents 3d890c6 + b6b2490 commit c0b54b2
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 c0b54b2

Please sign in to comment.