npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tf2-currency

v1.1.2

Published

Set of tools that manage operations with tf2 currency.

Downloads

24

Readme

tf2-currency

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.

Advantages over tf2-currencies

  • Fully typed, written in typescript
  • Throughly tested, over 100 tests
  • More convenience methods for comparing/operating with currency

Installation

npm install tf2-currency or via yarn yarn add tf2-currency

Documentation

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

Instantiation

new Currency(currency: ICurrency)
  • currency represents plain currency object such as { keys: 12, metal: 52.11 }
Currency.fromScrap(scrap: number, conversion?: number): Currency

Creates a Currency class from scrap value

  • scrap value you are creating currency from
  • conversion rate to be used to convert into keys
Currency.fromKeys(keys: number, conversion?: number): Currency

Creates a Currency class from key value

  • keys floating point number to create currency from
  • conversion rate to be used to convert into metal
    • Required if keys is not an integer

Currency.prototype.toScrap(conversion?: number): number

Converts currency to scrap

  • conversion to convert keys to scrap
    • Required if keys are present

Currency.prototype.toKeys(conversion?: number): number

Converts currency to keys

  • conversion to convert metal to keys
    • Required if metal is present

Currency.prototype.toString(): string

Builds a currency string readable for humans

Currency.prototype.toJSON(): ICurrency

Returns plain currency object for json serialization

Currency.prototype.addScrap(scrap: number, conversion?: number): Currency

Adds scrap value to the currency

  • scrap value you are adding to the currency
  • conversion rate to be used to convert exceeding metal value into keys

Currency.prototype.addMetal(metal: number, conversion?: number): Currency

Adds metal value to the currency

  • metal value you are adding to the currency
  • conversion rate to be used to convert exceeding metal value into keys

Currency.prototype.addKeys(keys: number, conversion?: number): Currency

Adds key value to the currency

  • keys value you are adding to the currency
  • conversion rate to be used to convert exceeding metal value into keys
    • Required if keys is not an integer

Currency.prototype.addCurrency(currency: ICurrency, conversion?: number): Currency

Adds currency value to the currency

  • currency value you are adding to the currency
  • conversion rate to be used to convert exceeding metal value into keys

Currency.prototype.removeScrap(scrap: number, conversion?: number): Currency

Removes scrap value from the currency

  • scrap value you are removing from the currency
  • conversion rate to be used to convert key into scrap
    • Required when we go to negative values with scrap

Currency.prototype.removeMetal(metal: number, conversion?: number): Currency

Removes metal value from the currency

  • metal value you are removing from the currency
  • conversion rate to be used to convert key into metal
    • Required when we go to negative values with scrap

Currency.prototype.removeKeys(scrap: number, conversion?: number): Currency

Removes key value from the currency

  • keys value you are removing from the currency
  • conversion 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

Currency.prototype.removeCurrency(currency: ICurrency, conversion?: number): Currency

Removes currency value from the currency

  • currency value you are removing from the currency
  • conversion rate to be used to convert key into metal
    • Required when we go to negative values with scrap

Currency.prototype.isEqual(currency: ICurrency): boolean

Compares current currency object with supplied one

  • currency we are comparing to

Currency.prototype.isBigger(currency: ICurrency): boolean

Compares current currency object with supplied one

  • currency we are comparing to

Currency.prototype.isSmaller(currency: ICurrency): boolean

Compares current currency object with supplied one

  • currency we are comparing to

Currency.prototype.isBiggerOrEqual(currency: ICurrency): boolean

Compares current currency object with supplied one

  • currency we are comparing to

Currency.prototype.isSmallerOrEqual(currency: ICurrency): boolean

Compares current currency object with supplied one

  • currency we are comparing to

c(currency: Partial): Currency

Creates Currency object

  • currency from which we are creating the object

fixCurrency(currency: Partial): ICurrency

Fixes partial currency object

  • currency we are fixing