1.6.9 • Published 5 months ago
money-lib v1.6.9
💰 money-lib 💰
TypeScript library to work with money
This is V2 API. V1 docs are here.
Simple API
Type safe
Correct rounding (Banker's by default)
Parsing a string
Custom currencies
Standalone utils
API
// Compare
cmp: (m) => 1 | 0 | -1;
// Equal
eq: (m) => boolean;
// Greater than
gt: (m) => boolean;
// Greater than or equal
gte: (m) => boolean;
// Less than
lt: (m) => boolean;
// Less than or equal
lte: (m) => boolean;
// Check if a Money is zero
is0: () => boolean;
// Check if a Money is positive
isPos: () => boolean;
// Check if a Money is negative
isNeg: () => boolean;
// Get min from multiple Money inputs
min: (...m) => m;
// Get max from multiple Money inputs
max: (...m) => m;
// Check if a Money is valid
validate: () => boolean;
// Split Money into a base and cents part
split: () => {
base: number;
cents: number;
};
// Add multiple Money inputs
add: (...m) => m;
// Subtract multiple Money inputs
sub: (...m) => m;
// Multiply Money by a number
mul: (multiplier: number, round?: (n: number) => number) => m;
// Divide Money by a number
div: (divider: number, round?: (n: number) => number) => m;
// Return the absolute value of a Money
abs: () => m;
// Format Money
fmt: (ops?: {
locale?: string;
cents?: boolean;
trailingZeros?: boolean;
withPlusSign?: boolean;
}) => string;
// Advanced Money formatter
fmts: (locale?: string) => {
base: string;
baseFormatted: string;
cents: string;
currencySymbol: string;
decimalSeparator: string;
sign: "+" | "-" | "";
};
// Parse a string into a Money object
parse: (
s: string,
currency: string,
locale?: string,
decimalSeparator?: "." | ","
) => m;
// Log a Money object to the console
debug: (prefix?: string) => m;
// Return the Money object
json: () => Money;
// Return the Money object as an int
int: () => Cents;
// Return the Money object as an int (alias for toInt)
cents: () => Cents;
// Return the Money object as a float
number: () => number;
// Return the Money object as a float (alias for number())
float: () => number;
// Return the Money object as a string
centStr: () => string;
// Return the Money object as a string
string: () => string;
TODO
- big numbers
- support fractions with more than 2 digits eg 1.9999 euros (currently rounds to 2 decimals) (eg for stock prices etc)
1.6.9
5 months ago
2.0.0-beta.9
7 months ago
2.0.0-beta.8
7 months ago
2.0.0-beta.7
7 months ago
2.0.0-beta.2
7 months ago
2.0.0-beta.1
7 months ago
2.0.0-beta.0
7 months ago
2.0.0-beta.6
7 months ago
2.0.0-beta.5
7 months ago
2.0.1
7 months ago
2.0.0-beta.4
7 months ago
2.0.0
7 months ago
2.0.0-beta.3
7 months ago
1.6.8
6 months ago
1.6.7
6 months ago
2.0.0-beta.10
7 months ago
1.6.6
7 months ago
1.6.5
7 months ago
1.6.4
8 months ago
1.6.3
8 months ago
1.2.0
11 months ago
1.1.0
11 months ago
1.0.1
11 months ago
1.0.0
11 months ago
1.6.2
9 months ago
1.6.1
9 months ago
1.6.0
9 months ago
1.3.3
10 months ago
1.5.0
9 months ago
1.4.1
9 months ago
1.3.2
10 months ago
1.4.0
9 months ago
1.3.1
11 months ago
1.3.0
11 months ago
0.0.5
1 year ago
0.0.7
11 months ago
0.0.4
1 year ago
0.0.3
1 year ago
0.0.2
1 year ago
0.0.1
1 year ago