UNPKG

fortify2-js

Version:

MOST POWERFUL JavaScript Security Library! Military-grade cryptography + 19 enhanced object methods + quantum-resistant algorithms + perfect TypeScript support. More powerful than Lodash with built-in security.

73 lines (70 loc) 2.6 kB
import { __processor__ } from 'nehonix-uri-processor'; import { bufferToBase64, bufferToString, bufferToBase64Url, bufferToBinary, bufferToBase58, bufferToHex } from './encoding.js'; import './memory/index.js'; function bufferDataConverter(input, outputFormat, options = {}) { const { onError, onBuffer, onResult } = options; try { let result = null; switch (outputFormat) { case "hex": result = bufferToHex(input); onResult?.(result); break; case "base64": result = bufferToBase64(input); onResult?.(result); break; case "base58": result = bufferToBase58(input); onResult?.(result); break; case "binary": result = bufferToBinary(input); onResult?.(result); break; case "buffer": result = null; onBuffer?.(input); break; case "base64url": result = bufferToBase64Url(input); onResult?.(result); break; case "utf8": result = bufferToString(input); onResult?.(result); break; default: try { // Convert Uint8Array to string for processor.encode() // Since processor.encode expects a string input, we need to convert binary data to string first let inputString; // Try UTF-8 decoding first (best for text data) try { inputString = new TextDecoder("utf-8", { fatal: true, }).decode(input); } catch { // If UTF-8 decoding fails (binary data), convert to Base64 first // This ensures the processor gets valid string input inputString = bufferToBase64(input); } result = __processor__.encode(inputString, outputFormat); onResult?.(result); } catch (error) { onError?.(error); throw error; } break; } return result; } catch (error) { onError?.(error); throw error; } } export { bufferDataConverter }; //# sourceMappingURL=dataConverter.js.map