-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
80 lines (73 loc) · 2.9 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
declare module 'vend-number' {
import { BigNumber } from 'bignumber.js'
interface Stringable {
toString(): string
}
// RoundingMode is not exported in bignumber.js 5.0.0 so have to copy and paste the declaration from bignumber.js to
// here in order to use the type. RoundingMode is available in bignumber.js 6.0.0+
enum RoundingMode {
/** Rounds away from zero */
ROUND_UP = 0,
/** Rounds towards zero */
ROUND_DOWN = 1,
/** Rounds towards Infinity */
ROUND_CEIL = 2,
/** Rounds towards -Infinity */
ROUND_FLOOR = 3,
/**
* Rounds towards nearest neighbour. If equidistant, rounds away from zero
*/
ROUND_HALF_UP = 4,
/**
* Rounds towards nearest neighbour. If equidistant, rounds towards zero
*/
ROUND_HALF_DOWN = 5,
/**
* Rounds towards nearest neighbour. If equidistant, rounds towards even neighbour
*/
ROUND_HALF_EVEN = 6,
/**
* Rounds towards nearest neighbour. If equidistant, rounds towards `Infinity`
*/
ROUND_HALF_CEIL = 7,
/**
* Rounds towards nearest neighbour. If equidistant, rounds towards `-Infinity`
*/
ROUND_HALF_FLOOR = 8,
/**
* The remainder is always positive. Euclidian division: `q = sign(n) * floor(a / abs(n))`
*/
EUCLID = 9
}
export const ROUNDING_MODES = {
ROUND_UP: RoundingMode.ROUND_UP,
ROUND_DOWN: RoundingMode.ROUND_DOWN,
ROUND_CEIL: RoundingMode.ROUND_CEIL,
ROUND_FLOOR: RoundingMode.ROUND_FLOOR,
ROUND_HALF_UP: RoundingMode.ROUND_HALF_UP,
ROUND_HALF_DOWN: RoundingMode.ROUND_HALF_DOWN,
ROUND_HALF_EVEN: RoundingMode.ROUND_HALF_EVEN,
ROUND_HALF_CEIL: RoundingMode.ROUND_HALF_CEIL,
ROUND_HALF_FLOOR: RoundingMode.ROUND_HALF_FLOOR,
} as const
export default class VendNumber extends BigNumber {
constructor (value?: Stringable)
static readonly ROUNDING_MODES: typeof ROUNDING_MODES
static vn(value?: Stringable): VendNumber
static round(value?: Stringable, decimalPoints?: number, roundingMode?: RoundingMode): string
static add(...values: Stringable[]): number
static subtract(...values: Stringable[]): number
static multiply(...values: Stringable[]): number
static divide(...values: Stringable[]): number
static sumBy<T, K extends keyof T>(collection: T[], property: K, decimalPoints: number): string
static isFinite(value: any): boolean
}
export function vn(value?: Stringable): VendNumber
export function round(value?: Stringable, decimalPoints?: number, roundingMode?: RoundingMode): string
export function add(...values: Stringable[]): number
export function subtract(...values: Stringable[]): number
export function multiply(...values: Stringable[]): number
export function divide(...values: Stringable[]): number
export function sumBy<T, K extends keyof T>(collection: T[], property: K, decimalPoints: number): string
export function isFinite(value: any): boolean
}