swc/bundler/tests/.cache/untrusted/3cb4695a7e5b75801a20659eea940e02d21b8af6.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

67 lines
2.0 KiB
TypeScript

// Loaded from https://dev.jspm.io/npm:jszip@3.5.0/lib/nodejsUtils.dew.js
import _buffer from "/npm:@jspm/core@1/nodelibs/buffer.js";
var exports = {},
_dewExec = false;
export function dew() {
if (_dewExec) return exports;
_dewExec = true;
var Buffer = _buffer.Buffer;
exports = {
/**
* True if this is running in Nodejs, will be undefined in a browser.
* In a browser, browserify won't include this file and the whole module
* will be resolved an empty object.
*/
isNode: typeof Buffer !== "undefined",
/**
* Create a new nodejs Buffer from an existing content.
* @param {Object} data the data to pass to the constructor.
* @param {String} encoding the encoding to use.
* @return {Buffer} a new Buffer.
*/
newBufferFrom: function (data, encoding) {
if (Buffer.from && Buffer.from !== Uint8Array.from) {
return Buffer.from(data, encoding);
} else {
if (typeof data === "number") {
// Safeguard for old Node.js versions. On newer versions,
// Buffer.from(number) / Buffer(number, encoding) already throw.
throw new Error("The \"data\" argument must not be a number");
}
return new Buffer(data, encoding);
}
},
/**
* Create a new nodejs Buffer with the specified size.
* @param {Integer} size the size of the buffer.
* @return {Buffer} a new Buffer.
*/
allocBuffer: function (size) {
if (Buffer.alloc) {
return Buffer.alloc(size);
} else {
var buf = new Buffer(size);
buf.fill(0);
return buf;
}
},
/**
* Find out if an object is a Buffer.
* @param {Object} b the object to test.
* @return {Boolean} true if the object is a Buffer, false otherwise.
*/
isBuffer: function (b) {
return Buffer.isBuffer(b);
},
isStream: function (obj) {
return obj && typeof obj.on === "function" && typeof obj.pause === "function" && typeof obj.resume === "function";
}
};
return exports;
}