Enter an ISO-4217 currency code and return the symbol
npm install currency-code-to-symbolA React hook for mapping currency codes to their respective symbols and locales. This package provides an easy way to display currency symbols in your React applications based on currency codes.
To install the package, use npm or yarn:
``bash`
npm install currency-code-to-symbol
or
`bash`
yarn add currency-code-to-symbol
Import the useCurrencySymbol hook into your React component and use it to get the symbol for a given currency code.
`javascript
import React from "react";
import useCurrencySymbol from "./useCurrencySymbol";
const CurrencyInfo = ({ currencyCode }) => {
const { symbol, locale, error } = useCurrencySymbol(currencyCode);
if (error) {
return
return (
Currency Symbol: {symbol}
Locale: {locale}
export default CurrencyInfo;
`
`javascript
import React, { useState } from "react";
import useCurrencySymbol from "currency-code-to-symbol";
const App = () => {
const [currencyCode, setCurrencyCode] = useState("USD");
const { symbol, locale, error } = useCurrencySymbol(currencyCode);
return (
The symbol for {currencyCode} is {symbol}
The locale for {currencyCode} is {locale}
export default App;
`
The use-currency-symbol package supports a wide range of global currencies. Here are some examples:
| Currency Code | Symbol | Locale |
| ------------- | ------ | ------ |
| USD | $ | en-US |
| EUR | € | de-DE |
| JPY | ¥ | ja-JP |
| GBP | £ | en-GB |
| AUD | A$ | en-AU |
| CAD | C$ | en-CA |
| CHF | CHF | de-CH |
| CNY | ¥ | zh-CN |
| SEK | kr | sv-SE |
| ... | ... | ... |
Version 1.1.0
- Added Locale Support: Each currency now includes its respective locale, allowing for better internationalization and localization in applications.
- Updated Documentation: The README now includes detailed information on using the hook with the new locale support.
useCurrencySymbol(currencyCode)
currencyCode (string): The ISO 4217 currency code.
Returns: (string) The symbol corresponding to the currency code.
Contributions are welcome! Please feel free to submit a Pull Request.
1. Create your feature branch (git checkout -b feature/your-feature).git commit -m 'Add some feature'
2. Commit your changes ().git push origin feature/your-feature`).
3. Push to the branch (
Open a Pull Request.
This project is licensed under the ISC License - see the LICENSE file for details.