Add u8aFixLength (#84)

This commit is contained in:
Jaco Greeff
2018-02-12 17:10:40 +01:00
committed by GitHub
parent a206f5c5bf
commit 5c270164ec
5 changed files with 91 additions and 1 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ const { ZEROS_256 } = require('./constants');
console.log('fixed', hexFixLength('0x0012', 8)) // => 0x12
*/
module.exports = function hexFixLength (value: string, bitLength: number = -1, withPadding: boolean = false): string {
const strLength = bitLength / 4;
const strLength = Math.ceil(bitLength / 4);
const hexLength = strLength + 2;
if (bitLength === -1 || value.length === hexLength || (!withPadding && value.length < hexLength)) {