MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / _getBytes

Function _getBytes

lib.commonjs/utils/data.js:11–28  ·  view source on GitHub ↗
(value, name, copy)

Source from the content-addressed store, hash-verified

9 */
10const errors_js_1 = require("./errors.js");
11function _getBytes(value, name, copy) {
12 if (value instanceof Uint8Array) {
13 if (copy) {
14 return new Uint8Array(value);
15 }
16 return value;
17 }
18 if (typeof (value) === "string" && value.match(/^0x(?:[0-9a-f][0-9a-f])*$/i)) {
19 const result = new Uint8Array((value.length - 2) / 2);
20 let offset = 2;
21 for (let i = 0; i < result.length; i++) {
22 result[i] = parseInt(value.substring(offset, offset + 2), 16);
23 offset += 2;
24 }
25 return result;
26 }
27 (0, errors_js_1.assertArgument)(false, "invalid BytesLike value", name || "value", value);
28}
29/**
30 * Get a typed Uint8Array for %%value%%. If already a Uint8Array
31 * the original %%value%% is returned; if a copy is required use

Callers 2

getBytesFunction · 0.70
getBytesCopyFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected