UNPKG

mongoku

Version:

[![CI](https://github.com/huggingface/Mongoku/actions/workflows/ci.yml/badge.svg)](https://github.com/huggingface/Mongoku/actions/workflows/ci.yml)

39 lines (37 loc) 1.13 kB
const text_encoder = new TextEncoder(); function get_relative_path(from, to) { const from_parts = from.split(/[/\\]/); const to_parts = to.split(/[/\\]/); from_parts.pop(); while (from_parts[0] === to_parts[0]) { from_parts.shift(); to_parts.shift(); } let i = from_parts.length; while (i--) from_parts[i] = ".."; return from_parts.concat(to_parts).join("/"); } function base64_encode(bytes) { if (globalThis.Buffer) { return globalThis.Buffer.from(bytes).toString("base64"); } let binary = ""; for (let i = 0; i < bytes.length; i++) { binary += String.fromCharCode(bytes[i]); } return btoa(binary); } function base64_decode(encoded) { if (globalThis.Buffer) { const buffer = globalThis.Buffer.from(encoded, "base64"); return new Uint8Array(buffer); } const binary = atob(encoded); const bytes = new Uint8Array(binary.length); for (let i = 0; i < binary.length; i++) { bytes[i] = binary.charCodeAt(i); } return bytes; } export { base64_encode as a, base64_decode as b, get_relative_path as g, text_encoder as t }; //# sourceMappingURL=utils-BQzn9ikS.js.map