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

dyna-currencies

v2.0.6

Published

Currency converter

Downloads

38

Readme

About

dyna-currencies is a currency converter.

Currently it doesn't fetch currency rates from any service. You have to provide the currency rates.

Written in Typescript, runs everywhere.

Usage

import {DynaCurrencies} from 'dyna-currencies';

const dynaCurrencies = new DynaCurrencies();

dynaCurrencies.updateRates({"usd": 1, "eur": 0.85});

let usdPrice = dynaCurrencies.convert(2.45, 'eur', 'usd', true);

console.log(usdPrice); // 2.88 

Methods

updateRates(rates: ICurrencyRates): void

Update the partially. You can pass so many rates you want (not all of them).

When no rates are updated, the many convert functions return null.

clear(): void

Clears all rates (added/updated with update).

convert(value: number, fromCurrency: string, toCurrency: string, round: boolean = false): number | null

Set round to true to round the currency according to the decimals of the target currency.

convertToLabel(value: number, fromCurrency: string, toCurrency: string): IDynaLabelCurrency | null

Converts the currency, and the output instead of a number is the IDynaLabelCurrency interface where is friendly for the Yahoo Intl.

convertDynaPrice(price: IDynaPrice, toCurrency: string): IDynaPrice | null

It converts a DynaPrice object.

getCurrencyRatesDic(): ICurrencyRates

Get all currencies as a dictionary.

getCurrencies(): ICurrency[]

Get all currencies to array for drop-down controls, etc..

getCurrencyRatesByCountry(countryCode: string): ICurrency[]

Get all currencies that a country can hold.

getCurrencyByCountry(countryCode: string): ICurrency | null

Get the main currency for a country.

Return null when no rates are loaded or when it countryCode is wrong.

Properties

count: number

It returns the number of all updated rates.

hasRates: boolean

It returns all the updated rates.

lastUpdate: Date

When updated last time

Interfaces

interface ICurrencyRates { [currencyName: string]: number | undefined; }

interface ICurrencies { [currencyName: string]: ICurrency; }

interface ICurrency { code: string; symbol: string; name: string; namePlural: string; symbolNative: string; decimalDigits: number; rounding: number; }

interface ICountries { [currencyName: string]: ICountry | undefined; }

interface ICountry { name: string; native: string; phone: string; continent: string; capital: string; currency: string; languages: string[]; }

interface IDynaLabelCurrency extends IDynaLabel { values: { value: number; decimals: number; currencyName: string; currencyNamePlural: string; currencyCode: string; currencySymbol: string; currencySymbolNative: string; } }

interface IDynaLabel { // object used for ui labels, where the content of it is used also for translations text?: string; // the text will be applied if the tk not found (as default text) tk?: string; // the translation key values?: { // values are used inside the translated text (obtained by the tk) [key: string]: string | number; }; }