You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
830 B
24 lines
830 B
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.trim = trim;
|
|
function trim(hexOrBytes, { dir = 'left' } = {}) {
|
|
let data = typeof hexOrBytes === 'string' ? hexOrBytes.replace('0x', '') : hexOrBytes;
|
|
let sliceLength = 0;
|
|
for (let i = 0; i < data.length - 1; i++) {
|
|
if (data[dir === 'left' ? i : data.length - i - 1].toString() === '0')
|
|
sliceLength++;
|
|
else
|
|
break;
|
|
}
|
|
data =
|
|
dir === 'left'
|
|
? data.slice(sliceLength)
|
|
: data.slice(0, data.length - sliceLength);
|
|
if (typeof hexOrBytes === 'string') {
|
|
if (data.length === 1 && dir === 'right')
|
|
data = `${data}0`;
|
|
return `0x${data.length % 2 === 1 ? `0${data}` : data}`;
|
|
}
|
|
return data;
|
|
}
|
|
//# sourceMappingURL=trim.js.map
|