Skip to content

Commit adcf3eb

Browse files
authored
fix(index): return undefined on error instead of null (#133)
1 parent 14f7766 commit adcf3eb

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function safeParse (text, reviver) {
113113
try {
114114
return _parse(text, reviver, { safe: true })
115115
} catch (_e) {
116-
return null
116+
return undefined
117117
} finally {
118118
Error.stackTraceLimit = stackTraceLimit
119119
}

test/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,10 @@ test('safeParse', t => {
432432
t.end()
433433
})
434434

435-
t.test('returns null on invalid object string', t => {
435+
t.test('returns undefined on invalid object string', t => {
436436
t.strictEqual(
437437
j.safeParse('{"a": 5, "b": 6'),
438-
null
438+
undefined
439439
)
440440
t.end()
441441
})

types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ declare namespace parse {
3737
*
3838
* @param text The JSON text string.
3939
* @param reviver The `JSON.parse()` optional `reviver` argument.
40-
* @returns The parsed object, or `null` if there was an error or if the JSON contained possibly insecure properties.
40+
* @returns The parsed object, or `undefined` if there was an error or if the JSON contained possibly insecure properties.
4141
*/
4242
export function safeParse (text: string | Buffer, reviver?: Reviver | null): any
4343

0 commit comments

Comments
 (0)