UNPKG

minterjs-util

Version:
32 lines (30 loc) 789 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.bufferToCoin = bufferToCoin; exports.coinToBuffer = coinToBuffer; /** * Make 10 bytes padded Buffer from coin symbol string * @param {string} [coinSymbol=''] * @returns {Buffer} */ function coinToBuffer() { var coinSymbol = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; var buf = Buffer.alloc(10); Buffer.from(coinSymbol.toUpperCase()).copy(buf, 0, 0, 10); return buf; } /** * Convert 10 bytes padded Buffer to string of coin symbol * @param {Buffer} buf * @return {string} */ function bufferToCoin(buf) { var sliceEnd = buf.length; while (buf[sliceEnd - 1] === 0) { sliceEnd -= 1; } buf = buf.slice(0, sliceEnd); return buf.toString('utf8'); }