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

lucca-currency-converter

v0.0.1

Published

To run the program : * First install all dependencies with ```npm install``` * Then build the program with Run 'LuccaDevises converter.txt' to launch the program on converter.txt file. ALl files will be compiled from ts to js files in bin/ folder.

Downloads

3

Readme

Launch program

To run the program :

  • First install all dependencies with npm install
  • Then build the program with Run 'LuccaDevises converter.txt' to launch the program on converter.txt file. ALl files will be compiled from ts to js files in bin/ folder.

CurrencyConverter

The aim of this project is to build a program that could convert a given amount from one currency to an other.

For that, we will give the program one file in parameter that respects these conditions :

  • 1st line should have the currency we want to convert, the amount to convert and the currency targeted (ex: EUR;550;JPY)
  • 2nd line should have the number of intermediates currencies and exchange rates we will give at line 3rd and more (ex: 6)
  • 3rd line and more should contains all intermediates currencies. Each intermediate exchange rate should hve a started currency, a targeted currency and an exchange rate (ex: EUR;CHU;1.103 JPY; CHU; 1.4) The program will use all these intermediates currencies and exchange rates to successfully convert the init currency to the targeted one.

Specificities

The program have some rules to respect :

  • If there is more than 1 path to convert the init currency to the targeted one, the program should calculate the conversion using the shortest path.
  • Currencies will be 3 char (no numbers)
  • Second line is an integer
  • Each exchange rate will have 4 decimals maximum
  • THe final total must be integer rounded
  • It is possible to calculate an "inverted" exchange rate (ex: Calculate JPY->CHU when we only have "CHU;JPY;value") by calculating inverted value (1/value)

Graph theory

To find the shortest path of given data, we have to use an algorithm. I chose to use Dijkstra algorithm because it is made to find the shortest path, easy to use and must be used when we have no estimation from each node to target. Plus, it can calculate the shortest path of bi-directional graphs.

In this program, we will calculate the final total thanks to 2 graphs :

  • The first one will have equals weight (all edges = 1) so the shortest path calculate the path with the less steps (if we have put exchange rates as weight, it would have calculated the path with less weight of exchange rate, which has no real sense here)

I choose to not use another library for building the graphs and edges because this is a little test, I think it is better to keep the project with as few dependencies as possible.

Maybe it would be better to use a library which should be more complete than handmade the graph, so I will be happy to debate about this with you if you think that way.

Running tests

Run npm test to execute the tests. I use Moccha and expectjs to run the tests.

Here is the list of tests I decided to execute :

Dijkstra tests

  • shortest_path function of dijkstra library return the good shortest path..
  • Exception thrown when there is an unreachable destination
  • Exception thrown if destination does not exists

File tests

  • Parsing a correct file return expected results.
  • Exception thrown if the file given doesn't have enough data (less than 3 lines)
  • Exception is thrown if the given file has an intermediate currency with a started or target devise same as the init started one (otherwise conversion will be impossible)
  • Same but with the init targeted devise
First line
  • Expected return when parsing the entries of first line is correct
  • Exception thrown when init currencies does not have 3 chars
  • Exception is thrown when the INIT started AND targeted devises are the same
  • Exception thrown when amount is not a number
Second line
  • Expected return when the entry of second line is correct
  • Exception thrown when the given data is not an integer
Intermediate currencies (3rd line and more)
  • 2nd line (intermediates currencies number expected) = number of "3rd line and more" (list of all intermediates currencies)
  • Exception thrown when the case above does not match
  • Expected result when parsing a correct file
  • Exception thrown when at least one intermediate currency as same started and targeted devise (probably a user error)

Graph tests

  • Expected graph object when building the graph with same weight (with correct data)
  • Expected graph object when building the graph with "exchange rate" weight
  • Expected shortest path when passing a same weight graph

Math tests

  • Expected return from preciseRound function (up: rounded above and down: rounded below)
  • Converted total is the expected rounded integer value when given test data

Dependencies

There is the list of the dependencies I used for this project :

  • Mocha : Library for testing
  • Dijkstrajs : Library for calculating shortest path thanks to Dijkstra algorithm (No need to reinvent the wheel)
  • Expectjs: For testing expected results