ColonesExchangeRate 2.1.0

dotnet add package ColonesExchangeRate --version 2.1.0
                    
NuGet\Install-Package ColonesExchangeRate -Version 2.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ColonesExchangeRate" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ColonesExchangeRate" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="ColonesExchangeRate" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ColonesExchangeRate --version 2.1.0
                    
#r "nuget: ColonesExchangeRate, 2.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ColonesExchangeRate@2.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ColonesExchangeRate&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=ColonesExchangeRate&version=2.1.0
                    
Install as a Cake Tool

Colones Exchange Rate NuGet & npm Packages

This repository contains a NuGet & npm packages to provide currency conversion from Colones (Costa Rica - CRC ₡) to Dollars (United States - USD $) and Euros (European Union - EUR €). It consumes the API from Ministerio de Hacienda de Costa Rica (The API is in Spanish).

Note: The API usually changes the response for the Euro exchange rate, during business hours, the response contains the exchange rate in dollars and colones, but after business hours, the response only contains the exchange rate in dollars. The ColonesExchangeRate packages handles this situation and returns the correct values.

ColonesExchangeRate - CI/CD NuGet npm License: MIT

alternate text is missing from this package README image

Prerequisites

  • NuGet: .NET Standard 2.1 compatible runtime (e.g. .NET Core 3.0+, .NET 5+)
  • npm: Node.js 18.0.0 or later

Installation

You can install the ColonesExchangeRate package from NuGet.org, npmjs.com or GitHub Packages.

NuGet Package

To install ColonesExchangeRate using NuGet, run the following command in the Package Manager Console:

Install-Package ColonesExchangeRate

Usage

To use ColonesExchangeRate, first create an instance of the class:

var converter = new ColonesExchangeRate();
var amount = 1000;

decimal dollarsToColones = await converter.DollarsToColones(amount);
decimal colonesToDollars = await converter.ColonesToDollars(amount);
decimal dollarsToEuros = await converter.DollarsToEuros(amount);
decimal eurosToDollars = await converter.EurosToDollars(amount);
decimal colonesToEuros = await converter.ColonesToEuros(amount);
decimal eurosToColones = await converter.EurosToColones(amount);
var dollarExchangeRate = await converter.GetDollarExchangeRate();
var euroExchangeRate = await converter.GetEuroExchangeRate();

Console.WriteLine($"{amount} Dollars = {dollarsToColones} Colones");
Console.WriteLine($"{amount} Colones = {colonesToDollars} Dollars");
Console.WriteLine($"{amount} Dollars = {dollarsToEuros} Euros");
Console.WriteLine($"{amount} Euros = {eurosToDollars} Dollars");
Console.WriteLine($"{amount} Colones = {colonesToEuros} Euros");
Console.WriteLine($"{amount} Euros = {eurosToColones} Colones");
    
Console.WriteLine($"Dollar exchange rate: {dollarExchangeRate.date} - Sale: {dollarExchangeRate.sale} - Purchase: {dollarExchangeRate.purchase}");
if (euroExchangeRate.colones != null)
    Console.WriteLine($"Euro exchange rate: {euroExchangeRate.date} - Dollars: {euroExchangeRate.dollars} - Colones: {euroExchangeRate.colones}");
else
    Console.WriteLine($"Euro exchange rate: {euroExchangeRate.date} - Dollars: {euroExchangeRate.dollars}");
Caching (Optional)

To avoid redundant API calls when performing multiple conversions, enable caching:

// Cache exchange rates for 5 minutes
var converter = new ColonesExchangeRate(TimeSpan.FromMinutes(5));
CancellationToken Support

All methods accept an optional CancellationToken:

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
var result = await converter.DollarsToColones(100, cts.Token);
Custom HttpClient

You can inject your own HttpClient (e.g. for use with IHttpClientFactory):

var converter = new ColonesExchangeRate(httpClient, TimeSpan.FromMinutes(5));

The result will look similar to this: Console Result

Note: Replace amount with the amount of currency you want to convert.

npm Package

To install ColonesExchangeRate using npm, run the following command in the command line of your project's root directory:

npm i @dsanchezcr/colonesexchangerate

Usage

To use ColonesExchangeRate, import the module:

import ColonesExchangeRate from '@dsanchezcr/colonesexchangerate';

const converter = new ColonesExchangeRate();
const amount = 1000;

const amountInColones = await converter.dollarsToColones(amount);
console.log(`$${amount} is ₡${amountInColones}`);

const amountInDollars = await converter.colonesToDollars(amount);
console.log(`₡${amount} is $${amountInDollars}`);

const amountInEuros = await converter.dollarsToEuros(amount);
console.log(`$${amount} is €${amountInEuros}`);

const amountFromEuros = await converter.eurosToDollars(amount);
console.log(`€${amount} is $${amountFromEuros}`);

const colonesToEuros = await converter.colonesToEuros(amount);
console.log(`₡${amount} is €${colonesToEuros}`);

const eurosToColones = await converter.eurosToColones(amount);
console.log(`€${amount} is ₡${eurosToColones}`);

const dollarRate = await converter.getDollarExchangeRate();
console.log(`Dollar exchange rate: ${JSON.stringify(dollarRate)}`);

const euroRate = await converter.getEuroExchangeRate();
console.log(`Euro exchange rate: ${JSON.stringify(euroRate)}`);
Caching (Optional)

To avoid redundant API calls when performing multiple conversions, enable caching:

// Cache exchange rates for 5 minutes
const converter = new ColonesExchangeRate({ cacheTtlMs: 300000 });
TypeScript

The package includes TypeScript type definitions out of the box — no @types package needed. The result will look similar to this: npm console result

Note: Replace amount with the amount of currency you want to convert.

The following methods return an object/tuple with exchange rate details:

  • getDollarExchangeRate / GetDollarExchangeRate: the date of the exchange rate, the sale rate, and the purchase rate.
  • getEuroExchangeRate / GetEuroExchangeRate: the date of the exchange rate, the dollars rate, and the colones rate.

API Reference

Method Parameters Returns Description
DollarsToColones / dollarsToColones amount decimal / number Converts USD to CRC
ColonesToDollars / colonesToDollars amount decimal / number Converts CRC to USD
DollarsToEuros / dollarsToEuros amount decimal / number Converts USD to EUR
EurosToDollars / eurosToDollars amount decimal / number Converts EUR to USD
ColonesToEuros / colonesToEuros amount decimal / number Converts CRC to EUR
EurosToColones / eurosToColones amount decimal / number Converts EUR to CRC
GetDollarExchangeRate / getDollarExchangeRate (date, sale, purchase) / {date, sale, purchase} Gets current USD/CRC rate
GetEuroExchangeRate / getEuroExchangeRate (date, dollars, colones) / {date, dollars, colones} Gets current EUR rate

All NuGet methods also accept an optional CancellationToken parameter.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for development setup, testing instructions, and guidelines.

License

ColonesExchangeRate is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.0 44 2/20/2026
2.0.2 617 11/24/2023
2.0.1 213 11/20/2023
2.0.0 206 11/19/2023
1.0.2 223 11/18/2023
1.0.1 291 11/12/2023
1.0.0 234 11/6/2023