Total Complexity | 2 |
Complexity/F | 0 |
Lines of Code | 24 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | /*! |
||
2 | * Copyright (c) 2022 Pedro José Batista, licensed under the MIT License. |
||
3 | * See the LICENSE.md file in the project root for more information. |
||
4 | */ |
||
5 | import type Decimal from "."; |
||
6 | |||
7 | /** |
||
8 | * Asynchronously extend a Decimal-like constructor with the internationalization support of `decimal.js-i18n`. |
||
9 | * |
||
10 | * @param decimalClass Decimal class/constructor to be extended. |
||
11 | * @returns The augmented class/constructor. |
||
12 | */ |
||
13 | export const extend = async (decimalClass: Partial<Decimal.Constructor>) => { |
||
14 | if (!decimalClass || typeof decimalClass.isDecimal !== "function") { |
||
15 | throw new TypeError("Invalid Decimal argument."); |
||
16 | } |
||
17 | |||
18 | globalThis.__Decimal__Class__Global__ = decimalClass as Decimal.Constructor; |
||
19 | await import("./index"); |
||
20 | delete globalThis.__Decimal__Class__Global__; |
||
21 | return decimalClass as typeof Decimal; |
||
22 | }; |
||
23 | export default extend; |
||
24 |