Set of tools that manage operations with tf2 currency. Inspired by tf2-currencies made by Nicklason. Made as a drop in replacement for your plain currency object.
- Fully typed, written in typescript
- Throughly tested, over 100 tests
- More convenience methods for comparing/operating with currency
npm install tf2-currency
or via yarn yarn add tf2-currency
Following classes, types and functions are exported:
export {
Currency, // Currency class that manages operations
CurrencyError, // Error thrown by Currency class
ICurrency, // Interface for currency
c, // Create Currency object faster
fixCurrency, // Fix partial currency objects
}
currency
represents plain currency object such as{ keys: 12, metal: 52.11 }
Creates a Currency class from scrap value
scrap
value you are creating currency fromconversion
rate to be used to convert into keys
Creates a Currency class from key value
keys
floating point number to create currency fromconversion
rate to be used to convert into metal- Required if keys is not an integer
Converts currency to scrap
conversion
to convert keys to scrap- Required if keys are present
Converts currency to keys
conversion
to convert metal to keys- Required if metal is present
Builds a currency string readable for humans
Returns plain currency object for json serialization
Adds scrap value to the currency
scrap
value you are adding to the currencyconversion
rate to be used to convert exceeding metal value into keys
Adds metal value to the currency
metal
value you are adding to the currencyconversion
rate to be used to convert exceeding metal value into keys
Adds key value to the currency
keys
value you are adding to the currencyconversion
rate to be used to convert exceeding metal value into keys- Required if keys is not an integer
Adds currency value to the currency
currency
value you are adding to the currencyconversion
rate to be used to convert exceeding metal value into keys
Removes scrap value from the currency
scrap
value you are removing from the currencyconversion
rate to be used to convert key into scrap- Required when we go to negative values with scrap
Removes metal value from the currency
metal
value you are removing from the currencyconversion
rate to be used to convert key into metal- Required when we go to negative values with scrap
Removes key value from the currency
keys
value you are removing from the currencyconversion
rate to be used to convert key decimal to metal- Required when we go to negative values with scrap or when keys is not an integer
Removes currency value from the currency
currency
value you are removing from the currencyconversion
rate to be used to convert key into metal- Required when we go to negative values with scrap
Compares current currency object with supplied one
currency
we are comparing to
Compares current currency object with supplied one
currency
we are comparing to
Compares current currency object with supplied one
currency
we are comparing to
Compares current currency object with supplied one
currency
we are comparing to
Compares current currency object with supplied one
currency
we are comparing to
Creates Currency
object
currency
from which we are creating the object
Fixes partial currency
object
currency
we are fixing