Skip to content

Commit 2e4853f

Browse files
committed
chore: consistently use throwTypeError in functions.ts
1 parent 41b0dad commit 2e4853f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const gt = (a: unknown, b: unknown) => {
3535
return a > b
3636
}
3737

38-
throw new TypeError('Two numbers or two strings expected')
38+
throwTypeError('Two numbers or two strings expected')
3939
}
4040
const gte = (a: unknown, b: unknown) => isEqual(a, b) || gt(a, b)
4141
const lt = (a: unknown, b: unknown) => gt(b, a)

src/parse.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export function parse(query: string, options?: JSONQueryParseOptions): JSONQuery
113113
parseString() ??
114114
parseUnquotedString() ??
115115
parseInteger() ??
116-
throwError('Property expected')
116+
throwSyntaxError('Property expected')
117117
)
118118
}
119119

@@ -163,7 +163,10 @@ export function parse(query: string, options?: JSONQueryParseOptions): JSONQuery
163163
}
164164

165165
const key =
166-
parseString() ?? parseUnquotedString() ?? parseInteger() ?? throwError('Key expected')
166+
parseString() ??
167+
parseUnquotedString() ??
168+
parseInteger() ??
169+
throwSyntaxError('Key expected')
167170

168171
skipWhitespace()
169172
eatChar(':')
@@ -221,14 +224,14 @@ export function parse(query: string, options?: JSONQueryParseOptions): JSONQuery
221224
}
222225

223226
// end of the parsing chain
224-
throwError('Value expected')
227+
throwSyntaxError('Value expected')
225228
}
226229

227230
const parseEnd = () => {
228231
skipWhitespace()
229232

230233
if (i < query.length) {
231-
throwError(`Unexpected part '${query.substring(i)}'`)
234+
throwSyntaxError(`Unexpected part '${query.substring(i)}'`)
232235
}
233236
}
234237

@@ -244,12 +247,12 @@ export function parse(query: string, options?: JSONQueryParseOptions): JSONQuery
244247

245248
const eatChar = (char: string) => {
246249
if (query[i] !== char) {
247-
throwError(`Character '${char}' expected`)
250+
throwSyntaxError(`Character '${char}' expected`)
248251
}
249252
i++
250253
}
251254

252-
const throwError = (message: string, pos = i) => {
255+
const throwSyntaxError = (message: string, pos = i) => {
253256
throw new SyntaxError(`${message} (pos: ${pos})`)
254257
}
255258

0 commit comments

Comments
 (0)