export function from(items) { if ($isUndefinedOrNull(items)) { throw new TypeError( "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object.", ); } // TODO: figure out why private symbol not found if ( typeof items === "string" || (typeof items === "object" && ($isTypedArrayView(items) || items instanceof ArrayBuffer || items instanceof SharedArrayBuffer || items instanceof String)) ) { switch ($argumentCount()) { case 1: { return new $Buffer(items); } case 2: { return new $Buffer(items, $argument(1)); } default: { return new $Buffer(items, $argument(1), $argument(2)); } } } var arrayLike = $toObject( items, "The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object.", ) as ArrayLike; if (!$isJSArray(arrayLike)) { const toPrimitive = $tryGetByIdWithWellKnownSymbol(items, "toPrimitive"); if (toPrimitive) { const primitive = toPrimitive.$call(items, "string"); if (typeof primitive === "string") { switch ($argumentCount()) { case 1: { return new $Buffer(primitive); } case 2: { return new $Buffer(primitive, $argument(1)); } default: { return new $Buffer(primitive, $argument(1), $argument(2)); } } } } if (!("length" in arrayLike) || $isCallable(arrayLike)) { throw new TypeError( "The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object.", ); } } // Don't pass the second argument because Node's Buffer.from doesn't accept // a function and Uint8Array.from requires it if it exists // That means we cannot use $tailCallFowrardArguments here, sadly return new $Buffer(Uint8Array.from(arrayLike).buffer); } export function isBuffer(bufferlike) { return bufferlike instanceof $Buffer; } ion> Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/escapeHTML.test.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-06-22Tweak test runner outputGravatar Jarred Sumner 1-90/+44
2022-06-22Cleanup some testsGravatar Jarred Sumner 2-8/+46
2022-06-22Update Dockerfile.baseGravatar Jarred Sumner 1-1/+1
2022-06-22Update WebKitGravatar Jarred Sumner 1-0/+0
2022-06-22cleanup websocket testGravatar Jarred Sumner 1-3/+6
2022-06-22Fix `WebSocket` when HTTP server is not runningGravatar Jarred Sumner 14-38/+103
2022-06-22Update build-idGravatar Jarred Sumner 1-1/+1
2022-06-22cleanupGravatar Jarred Sumner 6-719/+3
2022-06-22Update index.d.tsGravatar Jarred Sumner 1-0/+1
2022-06-22types for `bun:jsc`Gravatar Jarred Sumner 2-1/+37
2022-06-22Slightly customize the `events` polyfill so it uses ESMGravatar Jarred Sumner 1-1/+522
2022-06-22Fix memory bugs in escapeHTML & arrayBufferToStringGravatar Jarred Sumner 1-65/+61