Skip to content

Commit e1d7ad0

Browse files
Maikoltmigone
authored andcommitted
chore: add commify
Signed-off-by: Tomás Migone <[email protected]>
1 parent 83d7f29 commit e1d7ad0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/common-ts/src/attestations/attestations.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ export const decodeAttestation = (attestationData: string): Attestation => {
103103
attestationBytes,
104104
)
105105
const sig = Signature.from(
106-
hexlify(attestationBytes.slice(RECEIPT_SIZE_BYTES, RECEIPT_SIZE_BYTES + SIG_SIZE_BYTES))
106+
hexlify(
107+
attestationBytes.slice(RECEIPT_SIZE_BYTES, RECEIPT_SIZE_BYTES + SIG_SIZE_BYTES),
108+
),
107109
)
108110

109111
return {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import "ethers"
2+
3+
function commify(value: string): string {
4+
const match = value.match(/^(-?)([0-9]*)(\.?)([0-9]*)$/);
5+
if (!match || (!match[2] && !match[4])) {
6+
throw new Error(`bad formatted number: ${ JSON.stringify(value) }`);
7+
}
8+
9+
const neg = match[1];
10+
const whole = BigInt(match[2] || 0).toLocaleString("en-us");
11+
const frac = match[4] ? (match[4].match(/^(.*?)0*$/)?.[1] || "0") : "0";
12+
13+
return `${ neg }${ whole }.${ frac }`;
14+
}

0 commit comments

Comments
 (0)