UNPKG

@iota/bcs

Version:

BCS - Canonical Binary Serialization implementation for JavaScript

77 lines (76 loc) 2.41 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var utils_exports = {}; __export(utils_exports, { decodeStr: () => decodeStr, encodeStr: () => encodeStr, splitGenericParameters: () => splitGenericParameters }); module.exports = __toCommonJS(utils_exports); var import_b58 = require("./b58.js"); var import_b64 = require("./b64.js"); var import_hex = require("./hex.js"); function encodeStr(data, encoding) { switch (encoding) { case "base58": return (0, import_b58.toBase58)(data); case "base64": return (0, import_b64.toBase64)(data); case "hex": return (0, import_hex.toHex)(data); default: throw new Error("Unsupported encoding, supported values are: base64, hex"); } } function decodeStr(data, encoding) { switch (encoding) { case "base58": return (0, import_b58.fromBase58)(data); case "base64": return (0, import_b64.fromBase64)(data); case "hex": return (0, import_hex.fromHex)(data); default: throw new Error("Unsupported encoding, supported values are: base64, hex"); } } function splitGenericParameters(str, genericSeparators = ["<", ">"]) { const [left, right] = genericSeparators; const tok = []; let word = ""; let nestedAngleBrackets = 0; for (let i = 0; i < str.length; i++) { const char = str[i]; if (char === left) { nestedAngleBrackets++; } if (char === right) { nestedAngleBrackets--; } if (nestedAngleBrackets === 0 && char === ",") { tok.push(word.trim()); word = ""; continue; } word += char; } tok.push(word.trim()); return tok; } //# sourceMappingURL=utils.js.map