File size: 711 Bytes
391a73c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.binary = void 0;
exports.encode = encode;
exports.decode = decode;
exports.is = is;
const index_js_1 = require("../bytes/index.js");
function encode(data) {
    const bytes = (0, index_js_1.toUint8Array)(data);
    let result = "";
    for (const byte of bytes) {
        result += String.fromCharCode(byte);
    }
    return result;
}
function decode(text) {
    const result = new Uint8Array(text.length);
    for (let i = 0; i < text.length; i++) {
        result[i] = text.charCodeAt(i) & 0xff;
    }
    return result;
}
function is(text) {
    return typeof text === "string";
}
exports.binary = { encode, decode, is };