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

crypto-token-calculator

v0.2.5

Published

To be used on screens or APIs in which the user can choose the quantity or percentage of tokens to purchase. These functions receive the token configuration as minimum value for purchase, minimum value of each installment, and it returns the percentage pu

Downloads

124

Readme

Crypto Token Calculator

To be used on screens or APIs in which the user can choose the quantity or percentage of tokens to purchase. These functions receive the token configuration as minimum value for purchase, minimum value of each installment, and it returns the percentage purchased, the cost and how many tokens this will result in. It does not depend on the currency used as you must send it in the currency you are working in.

Functions

All the functions returns CalcResultInterface that has:

CalcResultInterface

desirePercent: (number) Percent between 0 and 1, that means a desired percentage for total amount of tokens available

coust: (number) Value of this operation. Remember, all values are based on the same currency.

tokens: (number) Amount of tokens resulting from this operation

TokenInfoInterface

minValue: (number) Minimum value in currency allowed to buy this token

availableTokens: (number) Total quantity of current available tokens

valuePerToken: (number) Coust per 1 unit of this token in currency

slotUnitValue: (number) Group amount of token values that are allowed to purchase, for example, if slotUnitValue is 5, you can only purchase using multiples of 5 coins to purchase this token.

calcTokenPercent

Receives tokenInfo and the desired percentage (desirePercent) of tokens and returns CalcResultInterface.

Ideal if you are using a bar to symbolize the percentage of tokens desired for purchase.

Or you need to check whether the value sent corresponds to an accepted value.

Usage

import { TokenInfoInterface, calcTokenPercent } from "crypto-token-calculator";

const token: TokenInfoInterface = {
  minValue: 100,
  availableTokens: 1000000,
  slotUnitValue: 100,
  valuePerToken: 1,
};

const percentDesired:Number = 0.5000001;
const result = calcTokenPercent(token, percentDesired);

console.log(result);

//output: { desirePercent: 0.5001, coust: 500100, tokens: 500100 }

calcTokenValue

Receives tokenInfo and the total value (desiredValue) of tokens and returns CalcResultInterface.

Ideal if you are using a bar to symbolize the percentage of tokens desired for purchase.

Or you need to check whether the value sent corresponds to an accepted value.

Usage

import { TokenInfoInterface, calcTokenValue } from "crypto-token-calculator";

const token: TokenInfoInterface = {
  minValue: 100,
  availableTokens: 1000000,
  slotUnitValue: 100,
  valuePerToken: 1,
};

const desiredValueToBuy: number = 5000;
const result = calcTokenValue(token, desiredValueToBuy);

console.log(result);

//output: { desirePercent: 0.005, coust: 5000, tokens: 5000 }