diff --git a/src/index.test.ts b/src/index.test.ts index 570236b..7b7d27d 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1275,7 +1275,9 @@ test('doesnt iterate to keys that dont exist', () => { test('deserialize in place', () => { const serialized = SuperJSON.serialize({ a: new Date() }); const deserializedCopy = SuperJSON.deserialize(serialized); - const deserializedInPlace = SuperJSON.deserialize(serialized, { inPlace: true }); + const deserializedInPlace = SuperJSON.deserialize(serialized, { + inPlace: true, + }); expect(deserializedInPlace).toBe(serialized.json); expect(deserializedCopy).not.toBe(serialized.json); expect(deserializedCopy).toEqual(deserializedInPlace); diff --git a/src/index.ts b/src/index.ts index 9a11ad7..4fcd0bd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -60,10 +60,13 @@ export default class SuperJSON { return res; } - deserialize(payload: SuperJSONResult, options?: { inPlace?: boolean }): T { + deserialize( + payload: SuperJSONResult, + options?: { inPlace?: boolean } + ): T { const { json, meta } = payload; - let result: T = options?.inPlace ? json : copy(json) as any; + let result: T = options?.inPlace ? json : (copy(json) as any); if (meta?.values) { result = applyValueAnnotations(result, meta.values, meta.v ?? 0, this); diff --git a/src/is.test.ts b/src/is.test.ts index 5f8e5e4..8137630 100644 --- a/src/is.test.ts +++ b/src/is.test.ts @@ -92,3 +92,14 @@ test('Regression: null-prototype object', () => { expect(isPlainObject(Object.create(null))).toBe(true); expect(isPrimitive(Object.create(null))).toBe(false); }); + +test('isURL without URL global', () => { + const originalURL = globalThis.URL; + // @ts-ignore + delete globalThis.URL; + + expect(() => isURL('https://example.com')).not.toThrow(); + expect(isURL('https://example.com')).toBe(false); + + globalThis.URL = originalURL; +}); diff --git a/src/is.ts b/src/is.ts index 438ea49..8d7c5a9 100644 --- a/src/is.ts +++ b/src/is.ts @@ -84,4 +84,5 @@ export type TypedArray = InstanceType; export const isTypedArray = (payload: any): payload is TypedArray => ArrayBuffer.isView(payload) && !(payload instanceof DataView); -export const isURL = (payload: any): payload is URL => payload instanceof URL; +export const isURL = (payload: any): payload is URL => + typeof URL !== 'undefined' && payload instanceof URL; diff --git a/src/pathstringifier.test.ts b/src/pathstringifier.test.ts index b6ef6e4..e5fcd3e 100644 --- a/src/pathstringifier.test.ts +++ b/src/pathstringifier.test.ts @@ -22,12 +22,12 @@ describe('parsePath', () => { expect(parsePath(input, false)).toEqual(expectedOutput); }); - it.each([ - 'test\\a.b', - 'foo.bar.baz\\', - ])('parsePath(%p) is rejected', (input) => { - expect(() => parsePath(input, false)).toThrowError(); - }); + it.each(['test\\a.b', 'foo.bar.baz\\'])( + 'parsePath(%p) is rejected', + input => { + expect(() => parsePath(input, false)).toThrowError(); + } + ); }); describe('escapeKey', () => {