Skip to content

Commit f54f580

Browse files
kamalyusufvanska
authored andcommitted
throw Error objects
1 parent 61eeab2 commit f54f580

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

.changeset/forty-files-do.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+
Throw Error objects

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function stringInterpolation<
5454
raw: rawOutput = false,
5555
}: StringInterpolationOptions<OptionRaw> = {}
5656
): StringInterpolationReturn<VariableValue, OptionRaw> {
57-
if (!string && sanity) throw "Empty string"
57+
if (!string && sanity) throw new Error("Empty string")
5858

5959
// Find all variables within string
6060
const stringVariables = matchAllPolyfill(string, pattern)
@@ -68,11 +68,11 @@ export function stringInterpolation<
6868
const variableKeys = Object.keys(variables)
6969
// Checks whether variables parsed from string exist in passed argument
7070
if (stringVariables.length !== variableKeys.length)
71-
throw "Variable count mismatch"
71+
throw new Error("Variable count mismatch")
7272
for (const regExpMatchArray of stringVariables) {
7373
const variableKeyInString = regExpMatchArray[1]
7474
if (variableKeyInString && !variableKeys.includes(variableKeyInString))
75-
throw `Variable '${variableKeyInString}' not found`
75+
throw new Error(`Variable '${variableKeyInString}' not found`)
7676
}
7777
}
7878

0 commit comments

Comments
 (0)