Passed
Push — main ( 5cacf5...da0f78 )
by Pedro
02:28
created

src/extend.ts   A

Complexity

Total Complexity 4
Complexity/F 2

Size

Lines of Code 28
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 12
mnd 2
bc 2
fnc 2
dl 0
loc 28
ccs 8
cts 8
cp 1
rs 10
bpm 1
cpm 2
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A extend.ts ➔ extend 0 16 2
1
/*
2
 * decimal.js-i18n v0.2.6
3
 * Full internationalization support for decimal.js.
4
 * MIT License
5
 * Copyright (c) 2022 Pedro José Batista <[email protected]>
6
 * https://github.com/pjbatista/decimal.js-i18n
7
 */
8
/* eslint-disable @typescript-eslint/no-unsafe-return */
9
import type Decimal from ".";
10
11
/**
12
 * This function is the only export of this module, and can be used to extend custom builds of `decimal.js`.
13
 *
14
 * @param decimalClass Decimal class/constructor to be extended.
15
 * @returns The augmented class/constructor.
16
 */
17 1
export function extend(decimalClass: Partial<Decimal.Constructor>) {
18 4
    if (!decimalClass || typeof decimalClass.isDecimal !== "function") {
19 1
        throw new TypeError("Invalid argument Decimal argument.");
20
    }
21
22 1
    globalThis.__Decimal__Class__Global__ = decimalClass as Decimal.Constructor;
23 1
    require(".");
24 1
    delete globalThis.__Decimal__Class__Global__;
25 1
    return decimalClass as typeof Decimal;
26
}
27
export default extend;
28