MCPcopy Create free account
hub / github.com/subquery/subql / hexStripZeros

Function hexStripZeros

packages/utils/src/buffer/buffer.ts:27–41  ·  view source on GitHub ↗
(value: HexString)

Source from the content-addressed store, hash-verified

25
26// This is a clone from ethers.util hexStripZeros, in order to match polkadot util hex value with ethers
27export function hexStripZeros(value: HexString): string {
28 if (!isHex(value)) {
29 throw new Error(`invalid hex string ${value}`);
30 }
31 const str = value.toString().substring(2);
32 let offset = 0;
33 while (offset < str.length && str[offset] === '0') {
34 offset++;
35 }
36 const trimmed = `0x${str.substring(offset)}`;
37 if (trimmed === '0x') {
38 return '0x0';
39 }
40 return trimmed;
41}

Callers 2

buffer.spec.tsFile · 0.90
getDataFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected