Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

Commit c0b54b2

Browse files
committed
Merge pull request #23 from toshiwo/support_a_compatibility_with_interpolation_format_for_rails
support a compatibility with interpolation format for rails and i18n-js
2 parents 3d890c6 + b6b2490 commit c0b54b2

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/format.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* https://github.com/Matt-Esch/string-template/index.js
55
*/
66

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

99

1010
/**
@@ -24,7 +24,7 @@ export default function (string, ...args) {
2424
args = {}
2525
}
2626

27-
return string.replace(RE_NARGS, (match, i, index) => {
27+
return string.replace(RE_NARGS, (match, prefix, i, index) => {
2828
let result
2929

3030
if (string[index - 1] === '{' &&

test/specs/format.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ describe('format', () => {
1111
name: 'kazupon', email: 'foo@domain.com'
1212
}), 'name: kazupon, email: foo@domain.com')
1313
})
14+
15+
it('should be replace with object value', () => {
16+
let template = 'name: %{name}, email: %{email}'
17+
assert(format(template, {
18+
name: 'kazupon', email: 'foo@domain.com'
19+
}), 'name: kazupon, email: foo@domain.com')
20+
})
1421
})
1522

1623
context('Array', () => {

0 commit comments

Comments
 (0)