Skip to content

Commit 01abfb7

Browse files
committed
fix: respect closest closing brackets (#14)
1 parent a09cb71 commit 01abfb7

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

.changeset/popular-donkeys-grin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"typed-string-interpolation": patch
3+
---
4+
5+
fix: respect closest closing brackets (#14)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ stringInterpolation(str, variables, options)
9595
```ts
9696
type Options = {
9797
raw?: boolean // default: false
98-
pattern?: RegExp // default: /\{{([^{]+)}}/g
98+
pattern?: RegExp // default: /\{\{([^}]+)\}\}/g
9999
sanity?: boolean // default: true
100100
}
101101
```

src/__tests__/stringInterpolation.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,11 @@ describe("stringInterpolation()", () => {
133133
stringInterpolation("Hello {{world}}", {} as any, { sanity: false }),
134134
).toStrictEqual(["Hello ", undefined])
135135
})
136+
test("Respect the closest closing brackets", () => {
137+
expect(
138+
stringInterpolation('{"someKey":{"anotherKey":"{{valueToChange}}"}}', {
139+
valueToChange: 10,
140+
}),
141+
).toBe('{"someKey":{"anotherKey":"10"}}')
142+
})
136143
})

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function stringInterpolation<
3232
string: string,
3333
variables: Record<PropertyKey, VariableValue>,
3434
{
35-
pattern = /\{{([^{]+)}}/g,
35+
pattern = /\{\{([^}]+)\}\}/g,
3636
sanity = true,
3737
raw = false,
3838
}: StringInterpolationOptions<OptionRaw> = {},

0 commit comments

Comments
 (0)