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

global-currency-convert

v1.1.0

Published

A free and easy-to-use npm package for real-time currency conversion. free-global-currency-converter provides accurate exchange rates for multiple currencies worldwide, making it ideal for applications needing quick and reliable currency conversion

Downloads

118

Readme

Global Currency Convert

A free and easy-to-use npm package for real-time currency conversion. The global-currency-convert package provides accurate exchange rates for multiple currencies worldwide, making it ideal for applications needing quick and reliable currency conversion.

Table of Contents

Installation

You can install the package using npm:

npm install global-currency-convert

Usage

NodeJS Usage

  1. Import the package and load your environment variables:
import { currencyConverter } from 'global-currency-convert';
  1. Call the currencyConverter function with the required parameters:
const convertCurrency = async () => {
    try {
        const fromCurrency = 'USD'; // Currency to convert from
        const toCurrency = 'EUR';    // Currency to convert to
        const units = 100;           // Amount to convert

        const convertedAmount = await currencyConverter(fromCurrency, toCurrency, units);
        console.log(`Converted Amount: ${convertedAmount} ${toCurrency}`);
    } catch (error) {
        console.error(`Error: ${error.message}`);
    }
};

convertCurrency();

Usage in React.js

  1. Create a React component:
import React, { useState } from 'react';
import { currencyConverter } from 'global-currency-convert';
import dotenv from 'dotenv';

dotenv.config();

const CurrencyConverter = () => {
    const [fromCurrency, setFromCurrency] = useState('USD');
    const [toCurrency, setToCurrency] = useState('EUR');
    const [units, setUnits] = useState(100);
    const [convertedAmount, setConvertedAmount] = useState(null);
    const [error, setError] = useState(null);

    const handleConvert = async () => {
        try {
            const result = await currencyConverter(fromCurrency, toCurrency, units);
            setConvertedAmount(result);
            setError(null);
        } catch (err) {
            setError(err.message);
        }
    };

    return (
        <div>
            <h1>Currency Converter</h1>
            <input type="text" value={fromCurrency} onChange={(e) => setFromCurrency(e.target.value)} placeholder="From Currency" />
            <input type="text" value={toCurrency} onChange={(e) => setToCurrency(e.target.value)} placeholder="To Currency" />
            <input type="number" value={units} onChange={(e) => setUnits(e.target.value)} placeholder="Amount" />
            <button onClick={handleConvert}>Convert</button>
            {convertedAmount && <p>Converted Amount: {convertedAmount} {toCurrency}</p>}
            {error && <p style={{ color: 'red' }}>Error: {error}</p>}
        </div>
    );
};

export default CurrencyConverter;

Summary

This README provides all necessary information for users to install and use your currency converter package in different environments (Node.js, React.js, and Next.js). It also includes error handling guidelines to ensure users can manage any issues that arise. Adjust any specific sections or examples as needed for your package.