diff --git a/src/index.spec.ts b/src/index.spec.ts index 713046a..40da508 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -247,7 +247,10 @@ describe("javascript-stringify", () => { }); describeIf("Buffer", typeof (Buffer as any) === "function", () => { - it("should stringify", test(Buffer.from("test"), "new Buffer('test')")); + it( + "should stringify", + test(Buffer.from("test"), "Buffer.from('dGVzdA==', 'base64')") + ); }); describeIf("BigInt", typeof (BigInt as any) === "function", () => { diff --git a/src/object.ts b/src/object.ts index 2939d1b..6391fed 100644 --- a/src/object.ts +++ b/src/object.ts @@ -8,7 +8,7 @@ import { arrayToString } from "./array"; */ export const objectToString: ToString = (value, space, next, key) => { if (typeof (Buffer as unknown) === "function" && Buffer.isBuffer(value)) { - return `new Buffer(${next(value.toString())})`; + return `Buffer.from(${next(value.toString("base64"))}, 'base64')`; } // Use the internal object string to select stringify method.