diff --git a/lib/minify.js b/lib/minify.js index a68cbf3a..8760be13 100644 --- a/lib/minify.js +++ b/lib/minify.js @@ -1,10 +1,24 @@ "use strict"; var to_ascii = typeof atob == "undefined" ? function(b64) { - return new Buffer(b64, "base64").toString(); + if (Buffer.from && Buffer.from !== Uint8Array.from) { + // Node >= 4.5.0 + return Buffer.from(b64, "base64").toString(); + } else { + // Node < 4.5.0, old API, manual safeguards + if (typeof b64 !== "string") throw new Errror("\"b64\" must be a string"); + return new Buffer(b64, "base64").toString(); + } } : atob; var to_base64 = typeof btoa == "undefined" ? function(str) { - return new Buffer(str).toString("base64"); + if (Buffer.from && Buffer.from !== Uint8Array.from) { + // Node >= 4.5.0 + return Buffer.from(str, "ascii").toString("base64"); + } else { + // Node < 4.5.0, old API, manual safeguards + if (typeof str !== "string") throw new Errror("\"str\" must be a string"); + return new Buffer(str).toString("base64"); + } } : btoa; function read_source_map(code) {