src/extend.esm.ts   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 24
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 12
mnd 2
bc 2
fnc 0
dl 0
loc 24
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
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