UNPKG

binaryarray

Version:
36 lines (35 loc) 1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Make it a number from hex string * @param num * @param digit * @returns hexstring */ exports.numberToHexString = function (num, digit) { var template = Array.from(Array(digit), function () { return 0; }).join(''); var hexstring = num.toString(16).toUpperCase(); return (template + hexstring).slice(-digit); }; /** * Create an initialized typed-array * @param size array length * @param init_val initialize value * @returns initialized typed-arrray */ exports.createArray = function (size, init_val) { if (init_val === void 0) { init_val = 0; } var w = new Uint32Array(size); for (var i = 0; i < size; ++i) { w[i] = init_val; } return w; }; /** * max value of object propaties * @param spec enum-like Object * @returns max value */ exports.getSpecMax = function (spec) { return Object.keys(spec).reduce(function (r, k) { return Math.max(r, spec[k]); }, 0) + 1; };