Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

currency-to-locale

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

currency-to-locale - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

81

examples/examples.js

@@ -7,3 +7,3 @@ import currencyToLocale from '../index.js';

);
console.log("USD:", currencyToLocale('USD')); // 'en_US'
console.log("currencyCode: 'USD'\n RETURNS:", currencyToLocale('USD')); // prints 'en-US'

@@ -14,4 +14,10 @@ // Example 2: Currency code with multiple locale IDs

);
console.log("EUR with fr:", currencyToLocale('EUR', 'fr')); // 'fr_FR'
console.log("EUR with es:", currencyToLocale('EUR', 'es')); // 'es_ES'
console.log(
"currencyCode: 'EUR', languageCode: 'fr'\n RETURNS:",
currencyToLocale('EUR', 'fr')
); // prints 'fr-FR'
console.log(
"currencyCode: 'EUR', languageCode: 'es'\n RETURNS:",
currencyToLocale('EUR', 'es')
); // prints 'es-ES'

@@ -24,3 +30,6 @@ // Example 3: Currency code with multiple locale IDs, no language code provided

);
console.log("EUR with no language code:", currencyToLocale('EUR')); // 'de_DE'
console.log(
"currencyCode: 'EUR', no language code\n RETURNS:",
currencyToLocale('EUR')
); // prints 'de-DE'

@@ -34,13 +43,16 @@ // Example 4: Currency code with only one locale ID

console.log(
"HKD with de (incorrect language code for HKD, but ignored):",
currencyToLocale('HKD', 'de')
); // 'zh_HK'
"currencyCode: 'HKD', languageCode: 'de'\n RETURNS:",
currencyToLocale('HKD', 'de'),
"(incorrect language code for HKD, but ignored)"
); // prints 'zh-HK'
console.log(
"HKD with xyz (invalid language code, but ignored):",
currencyToLocale('HKD', 'xyz')
); // 'zh_HK'
"currencyCode: 'HKD', languageCode: 'xyz'\n RETURNS:",
currencyToLocale('HKD', 'xyz'),
"(invalid language code, but ignored)"
); // prints 'zh-HK'
console.log(
"HKD with 1 (invalid language code type, but ignored):",
currencyToLocale('HKD', 1)
); // 'zh_HK'
"currencyCode: 'HKD', languageCode: 1\n RETURNS:",
currencyToLocale('HKD', 1),
"(invalid language code type, but ignored)"
); // prints 'zh-HK'

@@ -52,9 +64,11 @@ // Example 5: Improperly formatted currency or language code (accepted)

console.log(
"Lowercase 'jpy' currency code:",
currencyToLocale('jpy')
); // 'ja_JP'
"currencyCode: 'jpy'\n RETURNS:",
currencyToLocale('jpy'),
"(handles improper formatting: lowercase currency code)"
); // prints 'ja-JP'
console.log(
"Uppercase 'IT' language code:",
currencyToLocale('CHF', 'IT')
); // 'it_CH'
"currencyCode: 'CHF', languageCode: 'IT'\n RETURNS:",
currencyToLocale('CHF', 'IT'),
"(handles improper formatting: uppercase language code)"
); // prints 'it-CH'

@@ -66,14 +80,14 @@ // Example 6: Invalid or not-found currency code

console.log(
"Currency code 1 (number):",
"currencyCode: 1\n RETURNS:",
currencyToLocale(1)
); // 'Please provide a valid currency code.'
); // prints 'Please provide a valid currency code.'
console.log(
"Currency code 'ABCD' (not 3-character):",
"currencyCode: 'ABCD' (not 3-character)\n RETURNS:",
currencyToLocale('ABCD')
); // 'Please provide a valide currency code.'
); // prints 'Please provide a valide currency code.'
console.log(
"Currency code 'XYZ':",
"currencyCode 'XYZ'\n RETURNS:",
currencyToLocale('XYZ'),
"(currency code might be valid, just missing from function's mapping)"
); // 'Currency code not found.'
); // prints 'Currency code not found.'

@@ -85,14 +99,14 @@ // Example 7: Invalid or not-found language code with valid currency code

console.log(
"Language code 1 (number) with currency code 'EUR':",
"currencyCode: 'EUR', languageCode: 1\n RETURNS:",
currencyToLocale('EUR', 1)
); // 'Please provide a valid language code.'
); // prints 'Please provide a valid language code.'
console.log(
"Language code 'xyz' (not 2-character) with currency code 'EUR':",
"currencyCode: 'EUR', languageCode: 'xyz' (not 2-character)\n RETURNS:",
currencyToLocale('EUR', 'xyz')
); // 'Please provide a valid language code.'
); // prints 'Please provide a valid language code.'
console.log(
"Language code 'zh' with currency code 'EUR':",
"currencyCode: 'EUR', languageCode 'zh'\n RETURNS:",
currencyToLocale('EUR', 'zh'),
"(language code might be valid, just missing from function's mapping)"
); // 'Language code not found for EUR.'
); // prints 'Language code not found for EUR.'

@@ -103,2 +117,5 @@ // Example 8: No input

);
console.log(currencyToLocale()); // 'Please provide a currency code.'
console.log(
"No input\n RETURNS:",
currencyToLocale()
); // prints 'Please provide a currency code.'

@@ -17,33 +17,33 @@ // function to map currency codes to locale identifiers

const currencyLocales = {
"AUD": "en_AU",
"BGN": "bg_BG",
"BRL": "pt_BR",
"CAD": "en_CA",
"CHF": ["de_CH", "fr_CH", "it_CH"], // multiple locales array
"CNY": "zh_CN",
"CZK": "cs_CZ",
"DKK": "da_DK",
"EUR": ["de_DE", "fr_FR", "es_ES", "it_IT"], // multiple locales array
"GBP": "en_GB",
"HKD": "zh_HK",
"HUF": "hu_HU",
"IDR": "id_ID",
"ILS": "he_IL",
"INR": "en_IN",
"ISK": "is_IS",
"JPY": "ja_JP",
"KRW": "ko_KR",
"MXN": "es_MX",
"MYR": "ms_MY",
"NOK": "no_NO",
"NZD": "en_NZ",
"PHP": "en_PH",
"PLN": "pl_PL",
"RON": "ro_RO",
"SEK": "sv_SE",
"SGD": "en_SG",
"THB": "th_TH",
"TRY": "tr_TR",
"USD": "en_US",
"ZAR": "en_ZA"
"AUD": "en-AU",
"BGN": "bg-BG",
"BRL": "pt-BR",
"CAD": "en-CA",
"CHF": ["de-CH", "fr-CH", "it-CH"], // multiple locales array
"CNY": "zh-CN",
"CZK": "cs-CZ",
"DKK": "da-DK",
"EUR": ["de-DE", "fr-FR", "es-ES", "it-IT"], // multiple locales array
"GBP": "en-GB",
"HKD": "zh-HK",
"HUF": "hu-HU",
"IDR": "id-ID",
"ILS": "he-IL",
"INR": "en-IN",
"ISK": "is-IS",
"JPY": "ja-JP",
"KRW": "ko-KR",
"MXN": "es-MX",
"MYR": "ms-MY",
"NOK": "no-NO",
"NZD": "en-NZ",
"PHP": "en-PH",
"PLN": "pl-PL",
"RON": "ro-RO",
"SEK": "sv-SE",
"SGD": "en-SG",
"THB": "th-TH",
"TRY": "tr-TR",
"USD": "en-US",
"ZAR": "en-ZA"
};

@@ -71,3 +71,3 @@

for (const [k, localeID] of Object.entries(currencyLocales[key])) {
let localeLang = localeID.split('_')[0];
let localeLang = localeID.split('-')[0];
// match beginning of locale ID

@@ -74,0 +74,0 @@ if (languageCode === localeLang) {

{
"name": "currency-to-locale",
"version": "1.1.1",
"version": "1.1.2",
"description": "Converts currency codes to locale identifiers following format specified in IETF BCP 47 standard",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -53,13 +53,13 @@ # currency-to-locale

// Example 1: Simple usage
const locale = currencyToLocale('USD'); // 'en_US'
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'); // 'fr_FR'
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')); // 'de_DE'
console.log("EUR with no language code:", currencyToLocale('EUR')); // returns 'de-DE'
// Example 4: Invalid or not-found currency code
const locale = currencyToLocale('XYZ'); // 'Currency code not found.'
const locale = currencyToLocale(1); // 'Please provide a valid currency code.'
const locale = currencyToLocale('XYZ'); // returns 'Currency code not found.'
const locale = currencyToLocale(1); // returns 'Please provide a valid currency code.'

@@ -66,0 +66,0 @@

@@ -5,4 +5,4 @@ import currencyToLocale from '../index.js';

console.assert(
currencyToLocale('USD') === 'en_US',
"Expected 'en_US' for USD"
currencyToLocale('USD') === 'en-US',
"Expected 'en-US' for USD"
);

@@ -12,8 +12,8 @@

console.assert(
currencyToLocale('CHF', 'fr') === 'fr_CH',
"Expected 'fr_CH for CHF, fr"
currencyToLocale('CHF', 'fr') === 'fr-CH',
"Expected 'fr-CH for CHF, fr"
);
console.assert(
currencyToLocale('EUR', 'es') === 'es_ES',
"Expected 'es_ES' for EUR, es"
currencyToLocale('EUR', 'es') === 'es-ES',
"Expected 'es-ES' for EUR, es"
);

@@ -23,4 +23,4 @@

console.assert(
currencyToLocale('EUR') === 'de_DE',
"Expected 'de_DE' for EUR"
currencyToLocale('EUR') === 'de-DE',
"Expected 'de-DE' for EUR"
)

@@ -30,4 +30,4 @@

console.assert(
currencyToLocale('AUD', 'en') === 'en_AU',
"Expected 'en_AU' for AUD, en"
currencyToLocale('AUD', 'en') === 'en-AU',
"Expected 'en-AU' for AUD, en"
);

@@ -38,14 +38,14 @@

// language code not found in function's mapping
currencyToLocale('USD', 'xy') === 'en_US',
"Expected 'en_US' for USD, xy"
currencyToLocale('USD', 'xy') === 'en-US',
"Expected 'en-US' for USD, xy"
);
console.assert(
// invalid language code length
currencyToLocale('USD', 'xyz') === 'en_US',
"Expected 'en_US' for USD, xyz"
currencyToLocale('USD', 'xyz') === 'en-US',
"Expected 'en-US' for USD, xyz"
)
console.assert(
// invalid language code type
currencyToLocale('USD', 1) === 'en_US',
"Expected 'en_US' for USD, 1"
currencyToLocale('USD', 1) === 'en-US',
"Expected 'en-US' for USD, 1"
)

@@ -95,4 +95,4 @@

console.assert(
currencyToLocale('usd') === 'en_US',
"Expected 'en_US' for usd"
currencyToLocale('usd') === 'en-US',
"Expected 'en-US' for usd"
);

@@ -102,4 +102,4 @@

console.assert(
currencyToLocale('EUR', 'FR') === 'fr_FR',
"Expected 'fr_FR' for EUR, FR"
currencyToLocale('EUR', 'FR') === 'fr-FR',
"Expected 'fr-FR' for EUR, FR"
);

@@ -109,4 +109,4 @@

console.assert(
currencyToLocale('chf', 'IT') === 'it_CH',
"Expected 'it_CH' for chf, IT"
currencyToLocale('chf', 'IT') === 'it-CH',
"Expected 'it-CH' for chf, IT"
);

@@ -113,0 +113,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc