MCPcopy Create free account
hub / github.com/abue-ammar/tinycast / encode

Function encode

Scripts/raycast-runtime/src/buffer.js:61–83  ·  view source on GitHub ↗
(text, encoding)

Source from the content-addressed store, hash-verified

59}
60
61function encode(text, encoding) {
62 switch (normalizeEncoding(encoding)) {
63 case "base64":
64 case "base64url":
65 return base64ToBytes(String(text).replace(/-/g, "+").replace(/_/g, "/"));
66 case "hex":
67 return hexToBytes(text);
68 case "latin1":
69 return latin1ToBytes(String(text));
70 case "utf16le": {
71 const source = String(text);
72 const out = new Uint8Array(source.length * 2);
73 for (let i = 0; i < source.length; i++) {
74 const code = source.charCodeAt(i);
75 out[i * 2] = code & 0xff;
76 out[i * 2 + 1] = code >> 8;
77 }
78 return out;
79 }
80 default:
81 return utf8Encode(String(text));
82 }
83}
84
85function compareBytes(a, b) {
86 const shared = Math.min(a.length, b.length);

Callers 8

fromMethod · 0.70
allocMethod · 0.70
byteLengthMethod · 0.70
writeMethod · 0.70
_serializeMethod · 0.50
requestMethod · 0.50
notificationMethod · 0.50
declineMethod · 0.50

Calls 6

base64ToBytesFunction · 0.90
utf8EncodeFunction · 0.90
normalizeEncodingFunction · 0.85
hexToBytesFunction · 0.85
latin1ToBytesFunction · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected