Passed
Push — main ( e10de5...6fe2c7 )
by Pedro
03:02
created

src/extend.cjs.ts   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 24
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

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
ccs 8
cts 8
cp 1
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
 * Synchronously 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 1
export const extend = (decimalClass: Partial<Decimal.Constructor>) => {
14 4
    if (!decimalClass || typeof decimalClass.isDecimal !== "function") {
15 1
        throw new TypeError("Invalid Decimal argument.");
16
    }
17
18 1
    globalThis.__Decimal__Class__Global__ = decimalClass as Decimal.Constructor;
19 1
    require("./index");
20 1
    delete globalThis.__Decimal__Class__Global__;
21 1
    return decimalClass as typeof Decimal;
22
};
23
export default extend;
24