forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.js
More file actions
17 lines (16 loc) · 671 Bytes
/
Copy pathmodels.js
File metadata and controls
17 lines (16 loc) · 671 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// src/models/common.ts
var DECIMAL_AMOUNT_PATTERN = /^\d+(\.\d+)?$/;
function normalizeMoneyAmount(input) {
if (typeof input.amount !== "string" || !DECIMAL_AMOUNT_PATTERN.test(input.amount)) {
throw new RangeError(
`MoneyAmount.amount must be a base-10 decimal string, got ${JSON.stringify(input.amount)}.`
);
}
const [wholeRaw = "", fractionRaw = ""] = input.amount.split(".");
const whole = wholeRaw.replace(/^0+(?=\d)/, "");
const fraction = fractionRaw.slice(0, 2).padEnd(2, "0");
return { ...input, amount: `${whole}.${fraction}` };
}
export { normalizeMoneyAmount };
//# sourceMappingURL=models.js.map
//# sourceMappingURL=models.js.map