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

currency-to-locale

v1.1.4

Published

Converts currency codes to locale identifiers following format specified in IETF BCP 47 standard

Downloads

300

Readme

currency-to-locale

Author

This project was built and is maintained by Laura Gates, https://github.com/laurapg1214.

Feel free to reach out with any questions or contributions!

Description

Converts currency codes to locale identifiers following format specified in IETF BCP 47 standard, comprised of a two-letter ISO 639-1 language code and ISO 3166-1 alpha-2 country code.

For currency codes with multiple locales/language codes, defaults have been selected.

Currency codes initially compiled using Frankfurter's https://api.frankfurter.app/currencies.

Additional currency code and locale ID additions are welcome; please see "Contributing" section below.


Installation

Install via npm:

npm install currency-to-locale

This will add the package to your project's dependencies.


Usage

To use the currencyToLocale function in your project, import it as follows:

import currencyToLocale from 'currency-to-locale';

Function usage: currencyToLocale

currencyToLocale(currencyCode, languageCode)

The currencyToLocale function accepts two arguments:

  • currencyCode (required): The 3-letter currency code (e.g. "USD", "EUR").
  • languageCode (optional): The 2-letter language code (e.g. "en", "de").

It returns the corresponding locale identifier (e.g. "en-US", "de-DE").

Examples

// Example 1: Simple usage const locale = currencyToLocale('USD'); // returns 'en-US'

// Example 2: Currency code with multiple locales, returns locale based on language code provided const locale = currencyToLocale('EUR', 'fr'); // returns 'fr-FR'

// Example 3: Currency code with multiple locales, no language code provided (default locale returned) console.log("EUR with no language code:", currencyToLocale('EUR')); // returns 'de-DE'

// Example 4: Invalid or not-found currency code const locale = currencyToLocale('XYZ'); // returns 'Currency code not found.' const locale = currencyToLocale(1); // returns 'Please provide a valid currency code.'

Run examples

To see these and additional examples in action, run the following command:

node examples/examples.js

This will execute the example script provided in the examples folder and show the output.


Contributing

I welcome contributions! If you'd like to improve or add to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch (e.g., feature-xyz or bugfix-123).
  3. Make your changes, ensuring they align with the project’s goals and style.
  4. Test your changes to ensure they work correctly.
  5. Submit a pull request with a description of your changes.

Code of Conduct Please be respectful and follow the Contributor Covenant Code of Conduct.

I appreciate your contributions and look forward to collaborating with you!


License

This project is licensed under the MIT License - see the LICENSE file for details.