Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@razorpay/i18nify-js
Advanced tools
_A one-stop solution built in javascript to provide internationalization support._
A one-stop solution built in javascript to provide internationalization support.
Hey, dive into this JavaScript toolkitโit's like having a magic kit for your app! ๐ชโจ Picture this: modules for phoneNumber, currency, dateโthey're like enchanted tools that make your app talk fluently in any language, anywhere! It's your ticket to making your app a global citizen, no matter where it goes!
And hey, hang tightโI'll break down each of these enchanting modules in the sections coming up! ๐๐ฑ๐ธ๐๏ธ
yarn add @razorpay/i18nify-js
Here's your roadmap to getting this party started:
yarn install
yarn build
Go on, code conqueror, the adventure awaits!
Welcome to the command center for your i18n experience! This module serves as the control hub, housing the essential functions to manage your i18n settings seamlessly. This module offers a trio of functions to handle all your i18n needs. Whether it's checking the current state, customizing settings, or starting afresh, this module has got you covered in managing your i18n world! ๐
setState(newState: Partial <I18nState>
): Customize and update your i18n state with ease! Whether you're changing locales or tweaking directions, this function is your ticket to tailor your i18n experience precisely how you want it! ๐จ
import { setState } from "@razorpay/i18nify-js/core";
// Set a new locale
setState({ locale: 'en-US' });
getState(): Peek into the current i18n state - the active locale, direction, and country settings - at any time, giving you a snapshot of your i18n setup! ๐ธ
import { getState } from '@razorpay/i18nify-js/core';
// Get the current state
const currentState = getState();
console.log(currentState);
/*
{
locale: 'en-US',
direction: '',
country: '',
}
*/
resetState(): Made a mess? No worries! Hit the reset button with this function. It's the ultimate undo for your i18n adjustments, whisking your settings back to their pristine defaults. Fresh start, anyone? ๐
import { resetState } from "@razorpay/i18nify-js/core";
// Reset everything!
resetState();
This module's your go-to guru for everything currency/number-related. ๐ค It's all about formatting, validations, and handy tricks to make dealing with money/numbers a breeze. Here are the cool APIs and utilities this Currency Module gives you to play with! ๐๐ธ
๐ต๐ This function is your go-to tool for scaling currency values from lower to major units. Just input the amount in a minor unit (like cents or pence) along with the currency code, and voilร ! You get the amount in a major unit (like dollars or pounds). And if you stumble upon an unsupported currency code, it'll promptly let you know by throwing an error.
console.log(convertToMajorUnit(10000, { currency: 'USD' })); // Outputs the amount in dollars for 10000 cents (e.g., 100.00)
console.log(convertToMajorUnit(5000, { currency: 'GBP' })); // Converts 5000 pence to pounds (e.g., 50.00)
๐ต๐ This function is your go-to tool for scaling currency values from higher to minor units. Just input the amount in a major unit (like dollars or pounds) along with the currency code, and voilร ! You get the amount in a minor unit (like cents or pence). And if you stumble upon an unsupported currency code, it'll promptly let you know by throwing an error.
console.log(convertToMinorUnit(100, { currency: 'USD' })); // Outputs the amount in cents for 10000 dollars (e.g., 10000)
console.log(convertToMinorUnit(50, { currency: 'GBP' })); // Converts 50 pounds to pence (e.g., 5000)
๐ฉโจ This little wizard helps you jazz up numerical values in all sorts of fancy ways. And guess what? It uses the Internationalization API (Intl) to sprinkle that magic dust and give you snazzy, locale-specific number formatsโespecially for currencies! ๐๐ธ
console.log(formatNumber('1000.5', { currency: 'USD' })); // $1,000.50
console.log(
formatNumber('1500', {
currency: 'EUR',
locale: 'fr-FR',
intlOptions: {
currencyDisplay: 'code',
},
}),
); // 1 500,00 EUR
console.log(
formatNumber('5000', {
currency: 'JPY',
intlOptions: {
currencyDisplay: 'narrowSymbol',
},
}),
); // ยฅ5,000
๐๐ฐ It's your easy-peasy way to snag a whole list of currencies with their symbols and names. Simple, straightforward, and totally handy!
console.log(getCurrencyList()); /* {
AED: {
symbol: 'ุฏ.ุฅ',
name: 'United Arab Emirates Dirham',
lowerUnitName: 'Fils',
},
ALL: {
symbol: 'Lek',
name: 'Albanian Lek',
lowerUnitName: 'Qindarka',
},
AMD: {
symbol: 'ึ',
name: 'Armenian Dram',
lowerUnitName: 'Luma',
},
ARS: {
symbol: 'ARS',
name: 'Argentine Peso',
lowerUnitName: 'Centavo',
},
AUD: {
symbol: 'A$',
name: 'Australian Dollar',
lowerUnitName: 'Cent',
},
... rest of the country
} */
Picture this: it's like having a cool decoder ring for currency codes! ๐๐ฐ This little guy, grabs the symbol for a currency code from its secret stash.
console.log(getCurrencySymbol('USD')); // $
console.log(getCurrencySymbol('UZS')); // so'm
console.log(getCurrencySymbol('OMR')); // ุฑ.ุน.
This slick function breaks down numbers into separate pieces using Intl.NumberFormat. It's like taking apart a puzzle ๐งฉ โ currency symbol here, integers there, decimals in their placeโwith a fail-proof system to handle any formatting hiccups ๐ฅด along the way. Smooth operator, right?
console.log(
formatNumberByParts(12345.67, {
currency: 'USD',
locale: 'en-US',
}),
); /* {
"currency": "$",
"integer": "12,345",
"decimal": ".",
"fraction": "67",
"isPrefixSymbol": true,
"rawParts": [
{
"type": "currency",
"value": "$"
},
{
"type": "integer",
"value": "12"
},
{
"type": "group",
"value": ","
},
{
"type": "integer",
"value": "345"
},
{
"type": "decimal",
"value": "."
},
{
"type": "fraction",
"value": "67"
}
]
} */
console.log(
formatNumberByParts(12345.67, {
currency: 'XYZ',
locale: 'en-US',
}),
); /* {
"currency": "XYZ",
"integer": "12,345",
"decimal": ".",
"fraction": "67",
"isPrefixSymbol": true,
"rawParts": [
{
"type": "currency",
"value": "XYZ"
},
{
"type": "literal",
"value": "ย "
},
{
"type": "integer",
"value": "12"
},
{
"type": "group",
"value": ","
},
{
"type": "integer",
"value": "345"
},
{
"type": "decimal",
"value": "."
},
{
"type": "fraction",
"value": "67"
}
]
} */
console.log(
formatNumberByParts(12345.67, {
currency: 'EUR',
locale: 'fr-FR',
}),
); /* {
"integer": "12โฏ345",
"decimal": ",",
"fraction": "67",
"currency": "โฌ",
"isPrefixSymbol": false,
"rawParts": [
{
"type": "integer",
"value": "12"
},
{
"type": "group",
"value": "โฏ"
},
{
"type": "integer",
"value": "345"
},
{
"type": "decimal",
"value": ","
},
{
"type": "fraction",
"value": "67"
},
{
"type": "literal",
"value": "ย "
},
{
"type": "currency",
"value": "โฌ"
}
]
} */
console.log(
formatNumberByParts(12345.67, {
currency: 'JPY',
locale: 'ja-JP',
}),
); /* {
"currency": "๏ฟฅ",
"integer": "12,346",
"isPrefixSymbol": true,
"rawParts": [
{
"type": "currency",
"value": "๏ฟฅ"
},
{
"type": "integer",
"value": "12"
},
{
"type": "group",
"value": ","
},
{
"type": "integer",
"value": "346"
}
]
} */
console.log(
formatNumberByParts(12345.67, {
currency: 'OMR',
locale: 'ar-OM',
}),
); /* {
"integer": "ูกูขูฌูฃูคูฅ",
"decimal": "ูซ",
"fraction": "ูฆูงู ",
"currency": "ุฑ.ุน.",
"isPrefixSymbol": false,
"rawParts": [
{
"type": "literal",
"value": " "
},
{
"type": "integer",
"value": "ูกูข"
},
{
"type": "group",
"value": "ูฌ"
},
{
"type": "integer",
"value": "ูฃูคูฅ"
},
{
"type": "decimal",
"value": "ูซ"
},
{
"type": "fraction",
"value": "ูฆูงู "
},
{
"type": "literal",
"value": "ย "
},
{
"type": "currency",
"value": "ุฑ.ุน."
},
{
"type": "literal",
"value": " "
}
]
} */
This module's your phone's best friend, handling all things phone number-related. ๐ฑ It's the go-to for formatting, checking if those digits are legit, and all those handy phone-related tricks. And guess what? It's got a bunch of cool stuffโAPIs and utilitiesโjust waiting for you to dive in and make your phone game strong! ๐๐ข
๐ It's like the phone number detective, using fancy patterns to check if a number is the real deal for a specific country code. So, it's pretty simple: if it says true, your number's good to go for that country; if it's false, time to double-check those digits! ๐ต๏ธโโ๏ธ๐
// Basic Validation
console.log(isValidPhoneNumber('+14155552671')); // true
// Specifying Country Code for Validation
console.log(isValidPhoneNumber('0501234567', 'AE')); // true
// Auto-Detecting Country Code
console.log(isValidPhoneNumber('+447700900123')); // true
// Handling Invalid Numbers
console.log(isValidPhoneNumber('123456789', 'US')); // false
// Invalid Country Code
console.log(isValidPhoneNumber('+123456789')); // false
// Empty Phone Number
console.log(isValidPhoneNumber('')); // false
// Non-Standard Formatting
console.log(isValidPhoneNumber('(555) 555-5555')); // true
๐ It's like your personal phone number stylist, working its magic to make those digits look all snazzy. You can tell it the country code, or it'll figure it out itselfโthen presto! It hands you back a phone number looking sharp and dapper in that country's typical style. โจ๐
// Basic Formatting
console.log(formatPhoneNumber('+14155552671')); // '+1 415-555-2671'
// Specifying Country Code for Formatting
console.log(formatPhoneNumber('0501234567', 'AE')); // '050 123 4567'
// Auto-Detecting Country Code for Formatting
console.log(formatPhoneNumber('+447700900123')); // '+44 7700 900123'
// Handling Invalid Numbers for Formatting
console.log(formatPhoneNumber('123456789', 'US')); // '123456789'
// Invalid Country Code for Formatting
console.log(formatPhoneNumber('+123456789')); // '+123456789'
// Empty Phone Number
console.log(formatPhoneNumber('')); // Throws an Error: 'Parameter `phoneNumber` is invalid!'
// Non-Standard Formatting
console.log(formatPhoneNumber('(555) 555-5555')); // '555 555 5555'
๐ต๏ธโโ๏ธ๐ This clever function digs deep into a phone number, pulling out all the juicy details: country code, dial code, the number all dolled up, and even the format it follows. What's cool? It hands you back an object filled with all these deets, making it a breeze to access everything about that phone number. It's like having the ultimate phone number cheat sheet! ๐
// Formatting a Phone Number
const phoneNumber = '+1 (555) 123-4567';
const parsedInfo = parsePhoneNumber(phoneNumber);
console.log('Country Code:', parsedInfo.countryCode); // 'US'
console.log('Formatted Number:', parsedInfo.formattedPhoneNumber); // '555-123-4567'
console.log('Dial Code:', parsedInfo.dialCode); // '+1'
console.log('Format Template:', parsedInfo.formatTemplate); // 'xxx-xxx-xxxx'
// Parsing a Phone Number with Specified Country Code
const phoneNumber = '987654321'; // Phone number without country code
const countryCode = 'IN'; // Specifying the country code (India)
const parsedInfo = parsePhoneNumber(phoneNumber, countryCode);
console.log('Country Code:', parsedInfo.countryCode); // 'IN'
console.log('Formatted Number:', parsedInfo.formattedPhoneNumber); // '98-765-4321'
console.log('Dial Code:', parsedInfo.dialCode);
('');
console.log('Format Template:', parsedInfo.formatTemplate);
('xxxx xxxxxx');
// Handling Invalid Phone Numbers
try {
const invalidPhoneNumber = ''; // Empty phone number
// This will throw an error since the phone number is empty
const parsedInfo = parsePhoneNumber(invalidPhoneNumber);
// If the parsePhoneNumber function succeeds, log the parsed information
console.log('Country Code:', parsedInfo.countryCode);
console.log('Formatted Number:', parsedInfo.formattedPhoneNumber);
} catch (error) {
console.error('Error:', error.message); // 'Parameter `phoneNumber` is invalid!'
}
// Obtaining Format Information for a Country Code
const countryCode = 'JP'; // Country code for Japan
// Get the format information without providing a phone number
const parsedInfo = parsePhoneNumber('', countryCode);
console.log('Country Code:', parsedInfo.countryCode); // 'JP'
console.log('Format Template:', parsedInfo.formatTemplate); // 'xxx-xxxx-xxxx'
๐๐ข This function is a comprehensive directory of international dial codes, mapped to their respective country codes. Whether you're coding a global application or just need to reference international dialing formats, this function provides a quick and accurate reference, organizing the world's dial codes in a clean, easy-to-use format.
console.log(getDialCodes()); /*
{
US: '+1',
RU: '+7',
KZ: '+7',
EG: '+20',
ZA: '+27',
GR: '+30',
NL: '+31',
BE: '+32',
FR: '+33',
ES: '+34',
HU: '+36',
IT: '+39',
VA: '+39',
RO: '+40',
CH: '+41',
AT: '+43',
GB: '+44',
MM: '+95',
IR: '+98',
SS: '+211',
MA: '+212',
EH: '+212',
DZ: '+213',
TN: '+216',
LY: '+218',
GM: '+220',
SN: '+221',
// ... rest of the country
}
*/
๐๐บ๏ธ This function is your quick access to finding the dial code for any specific country, utilizing the country's ISO code. Perfect for applications that require validating user input for phone numbers or enhancing UIs with country-specific details. It ensures you get the exact dial code you need, and if the country code doesn't match, it alerts you right away with an error.
console.log(getDialCodeByCountryCode('BR')); // Outputs the dial code for Brazil (+55)
console.log(getDialCodeByCountryCode('DE')); // Outputs the dial code for Germany (+49)
๐๐ The getMaskedPhoneNumber function is a versatile tool designed to handle phone number formatting and masking based on the specific requirements of different countries. This function is ideal for applications that require the display of partially hidden phone numbers for security purposes or privacy concerns. It supports a wide range of configurations, including options to mask portions of the phone number, specify the number of digits to mask, and choose whether to mask digits from the beginning or end of the number.
// Masking a U.S. phone number completely
console.log(
getMaskedPhoneNumber({
countryCode: 'US',
phoneNumber: '2025550125',
withDialCode: true,
}),
);
// Output: +1 xxx-xxx-xxxx
// Partially masking an Indian phone number, hiding the last 6 digits with maskingStyle: suffix
console.log(
getMaskedPhoneNumber({
countryCode: 'IN',
phoneNumber: '9876543210',
maskingOptions: {
maskingStyle: 'suffix',
maskedDigitsCount: 6,
maskingChar: '*',
},
withDialCode: true,
}),
);
// Output: +91 9876 ******
// Partially masking an Indian phone number, hiding the first 6 digits with maskingStyle: prefix
console.log(
getMaskedPhoneNumber({
countryCode: 'IN',
phoneNumber: '9876543210',
maskingOptions: {
maskingStyle: 'prefix',
maskedDigitsCount: 6,
maskingChar: '*',
},
withDialCode: true,
}),
);
// Output: +91 **** 543210
// Partially masking an Indian phone number, hiding the first 6 digits with maskingStyle: full
console.log(
getMaskedPhoneNumber({
countryCode: 'IN',
phoneNumber: '9876543210',
maskingOptions: {
maskingStyle: 'full',
maskingChar: '*',
},
withDialCode: true,
}),
);
// Output: +91 **** ******
// Partially masking an Indian phone number, hiding the first 6 digits with maskingStyle: alternate
console.log(
getMaskedPhoneNumber({
countryCode: 'IN',
phoneNumber: '9876543210',
maskingOptions: {
maskingStyle: 'alternate',
maskingChar: '*',
},
withDialCode: true,
}),
);
// Output: +91 9*7* 5*3*1*
// Formatting and completely masking a phone number for Brazil without specifying a phone number
console.log(
getMaskedPhoneNumber({
countryCode: 'BR',
}),
);
// Output: xx xxxx-xxxx
Dive into the digital atlas with the Geo Module ๐, your ultimate toolkit for accessing geo contextual data from around the globe ๐. Whether you're infusing your projects with national pride ๐ or exploring different countries ๐ค, this module is like a magic carpet ride ๐งโโ๏ธ. With a range of functions at your disposal โจ, incorporating global data ๐ฉ into your app has never been easier. Let's explore these global gems ๐:
The Geo Module is designed to enrich your applications by providing easy access to high-quality flag images and emojis, country information, states, cities, and zip codes for every country.
Note: Below APIs in the Geo module currently support a limited set of countries.
- getStates
- getCities
- getZipcodes
These countries are 'IN', 'MY', 'SG' and 'US'.
Looking for a global adventure? The getAllCountries API is your passport to a world of fun facts! Get ready to explore every country on the map, complete with cool details like names, languages, currencies, dial codes, and even their snazzy flags.
// Fetching the list of all countries
const res = await getAllCountries();
console.log(res);
/*
"AF": {
"country_name": "Afghanistan",
"continent_code": "AS",
"continent_name": "Asia",
"alpha_3": "AFG",
"numeric_code": "004",
"flag": "https://flagcdn.com/af.svg",
"sovereignty": "UN member state",
"dial_code": "+93",
"supported_currency": [
"AFN"
],
"timezones": {
"Asia/Kabul": {
"utc_offset": "UTC +04:30"
}
},
"timezone_of_capital": "Asia/Kabul",
"locales": {
"fa_AF": {
"name": "Persian (Afghanistan)"
},
"ps": {
"name": "Pashto"
},
"uz_AF": {
"name": "Uzbek"
},
"tk": {
"name": "Turkmen"
}
},
"default_locale": "fa_AF",
"default_currency": "AFN"
},
// more_countries
*/
Embark on a state-by-state discovery with the getStates API! Get access to a treasure trove of state information, including names, time zones, and even a list of vibrant cities within each state.
// Getting list of all states
const res = await getStates('IN');
console.log(res);
/*
{"NL": {"name": "Nagaland",
"cities": [{"name": "Wokha",
"timezone": "Asia/Kolkata",
"zipcodes": ["797111"],
"region_name": "nan"},
{"name": "Mokokchลซng",
"timezone": "Asia/Kolkata",
"zipcodes": ["798601",
"798601",
"798604",
"798607",
"798614",
"798615",
"798618"],
"region_name": "nan"},
{"name": "Kohima",
"timezone": "Asia/Kolkata",
"zipcodes": ["797001",
"797002",
"797003",
"797006",
"797105",
"797109",
"797120"],
"region_name": "nan"},
{"name": "Dimฤpur",
"timezone": "Asia/Kolkata",
"zipcodes": ["797103",
"797103",
"797106",
"797112",
"797115",
"797116",
"797118"],
"region_name": "nan"}]}
// ...more_states
}
*/
// Passing invalid country code
getStates('XYZ').catch((err) => {
console.log(err);
}); // Outputs Invalid country code: XYZ
Uncover the charm of cities worldwide with the getCities API! This dynamic tool fetches an array of cities complete with their names, time zones, and region names, providing a detailed glimpse into urban life across the globe.
// Getting list of all cities for a country
const res = await getCities('IN');
console.log(res);
/*
[{
name: 'Tughlakฤbฤd',
timezone: 'Asia/Kolkata',
zipcodes: [],
region_name: 'nan',
},
{
name: 'Sabzi Mandi',
timezone: 'Asia/Kolkata',
zipcodes: [],
region_name: 'nan',
},
{
name: 'Pฤlam',
timezone: 'Asia/Kolkata',
zipcodes: ['517401', '517401'],
region_name: 'nan',
},
{
name: 'New Delhi',
timezone: 'Asia/Kolkata',
zipcodes: ['110001', '110020', '110029', '110084'],
region_name: 'nan',
},
// ...more_cities
]
*/
// Getting list of all cities within a state
const res = await getCities('IN', 'DL');
console.log(res);
/*
[{
name: 'Tughlakฤbฤd',
timezone: 'Asia/Kolkata',
zipcodes: [],
region_name: 'nan',
},
{
name: 'Sabzi Mandi',
timezone: 'Asia/Kolkata',
zipcodes: [],
region_name: 'nan',
},
{
name: 'Pฤlam',
timezone: 'Asia/Kolkata',
zipcodes: ['517401', '517401'],
region_name: 'nan',
},
{
name: 'New Delhi',
timezone: 'Asia/Kolkata',
zipcodes: ['110001', '110020', '110029', '110084'],
region_name: 'nan',
},
// ...more_cities_in_DL
]
*/
// Passing invalid country code
getCities('XYZ').catch((err) => {
console.log(err);
}); // Outputs Invalid country code: XYZ
// Passing invalid state code
getCities('IN', 'XYZ').catch((err) => {
console.log(err);
}); // Outputs State code XYZ missing in IN
Explore postal codes with the getZipcodes API! Discover a list of unique zip codes organized by country and state, making it easy to navigate geographic areas and streamline address-based operations.
// Getting list of all cities for a country
const res = await getZipcodes('IN');
console.log(res);
/*
['517401', '517401','110001', '110020', '110029', '110084', ...more_zipcodes]
*/
// Getting list of all cities within a state
const res = await getZipcodes('IN', 'DL');
console.log(res);
/*
['517401', '517401','110001', '110020', '110029', '110084', ...more_zipcodes_in_DL]
*/
// Passing invalid country code
getZipcodes('XYZ').catch((err) => {
console.log(err);
}); // Outputs Invalid country code: XYZ
// Passing invalid state code
getZipcodes('IN', 'XYZ').catch((err) => {
console.log(err);
}); // Outputs State code XYZ missing in IN
Source for flag images: FlagCDN.
Retrieve flag images for any ISO country code ๐โ๏ธ with a simple API call, bolstering your application's global engagement ๐ and honoring worldwide diversity ๐ณ๏ธ. This method efficiently integrates international flags into your digital projects, leveraging high-resolution SVG formats from a reliable source.
// Fetching the flag of the United States ๐บ๐ธ
console.log(getFlagOfCountry('US'));
/*
{
"original": "https://flagcdn.com/US.svg",
"4X3": "https://unpkg.com/@razorpay/i18nify-js/lib/assets/flags/us.svg"
}
*/
// Fetching the flag of India ๐ฎ๐ณ
console.log(getFlagOfCountry('IN'));
/*
{
"original": "https://flagcdn.com/IN.svg",
"4X3": "https://unpkg.com/@razorpay/i18nify-js/lib/assets/flags/in.svg"
}
*/
// When you wander off the map with an invalid country code
try {
console.log(getFlagOfCountry('XX')); // Oops, this will throw an error
} catch (error) {
console.error(error.message); // Politely informs 'Invalid country code: XX'
}
Source for flag images: FlagCDN.
Access a comprehensive collection of global flags with an ISO country code ๐โ๏ธโserving as your digital passport ๐ to a visually unified world. This feature amplifies your app's international flair ๐ and celebrates cultural diversity ๐ณ๏ธ๐ by embedding flags from every recognized nation.
// Embracing the flags of all nations
const allFlags = getFlagsForAllCountries();
console.log(allFlags);
/*
Behold, an object where each key is a country code linked to its flag's URL, such as:
{
US: {
"original": "https://flagcdn.com/US.svg",
"4X3": "https://unpkg.com/@razorpay/i18nify-js/lib/assets/flags/us.svg"
},
IN: {
"original": "https://flagcdn.com/IN.svg",
"4X3": "https://unpkg.com/@razorpay/i18nify-js/lib/assets/flags/in.svg"
},
...
}
*/
This module provides functions for formatting and manipulating dates and times in a locale-sensitive manner using the JavaScript Intl API & Date object.
๐ ๏ธ Dive into the sophistication of formatDateTime, a highly configurable function designed for developers seeking to master the intricacies of international date and time formatting. Leveraging the robust capabilities of the Intl.DateTimeFormat API, this utility offers unparalleled precision and adaptability in crafting date-time strings. Whether your application caters to a global audience or requires meticulous timestamping, formatDateTime delivers the versatility and accuracy essential for modern software development. ๐๐ง
// Comprehensive date-time formatting with custom options
console.log(
formatDateTime('2024-12-31 23:59', {
locale: 'en-US',
dateTimeMode: 'dateTime',
intlOptions: {
weekday: 'long',
year: 'numeric',
month: 'short',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
},
}),
); // Outputs 'Tuesday, Dec 31, 2024, 23:59:00'
// Locale-specific date-only formatting
console.log(
formatDateTime('2024-05-20', {
locale: 'ja-JP',
dateTimeMode: 'dateOnly',
}),
); // Outputs '2024/05/20', adhering to the Japanese date format
// Time-only formatting with emphasis on precision
console.log(
formatDateTime('2024-05-20 15:45:30', {
locale: 'fr-FR',
dateTimeMode: 'timeOnly',
intlOptions: {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: true,
},
}),
); // Outputs '03:45:30 PM', catering to the French preference for 24-hour time with high precision
Utilize formatDateTime
to ensure your application's date and time outputs are not only accurate ๐ฏ but also culturally and contextually appropriate ๐. From backend logging systems ๐ฅ๏ธ to user-facing interfaces ๐ฑ, this function stands as a testament to your commitment to internationalization ๐ and user experience excellence โจ. With its straightforward implementation ๐ ๏ธ and extensive configuration options โ๏ธ, formatDateTime
empowers you to meet the diverse needs of your audience ๐ฅ, promoting clarity ๐ and understanding ๐ค across different cultures and languages ๐ฃ๏ธ.
โณ๐ This time-traveling virtuoso effortlessly bridges the gap between dates, offering a glimpse into the past or a peek into the future. With the help of the Internationalization API (Intl), getRelativeTime
transforms absolute dates into relatable, human-friendly phrases like '3 hours ago' or 'in 2 days'. Whether you're reminiscing the past or anticipating the future, this function keeps you connected to time in the most intuitive way! ๐๐ฐ๏ธ
// How long ago was a past date?
console.log(getRelativeTime('2024-01-20')); // Outputs something like '3 days ago'
// How much time until a future date?
console.log(getRelativeTime('2024-01-26')); // Outputs 'in 3 days'
// Customizing output for different locales
console.log(
getRelativeTime('2024-01-26', { locale: 'fr-FR', baseDate: '2024-01-23' }),
); // Outputs 'dans 3 jours' (in 3 days in French)
๐ก Pro Tip: getRelativeTime
is not just a way to express time differences; it's a bridge that connects your users to the temporal context in a way that's both meaningful and culturally aware. Time is more than seconds and minutes; it's a story, and this function helps you tell it! ๐โ
๐
๐ This global day-namer is your trusty guide through the week, no matter where you are in the world. Using the power of the Internationalization API (Intl), getWeekdays
serves up the names of all seven days tailored to your chosen locale. From planning international meetings to creating a multilingual planner, this function provides the perfect blend of cultural awareness and practical utility, keeping you in sync with the local rhythm of life, one day at a time! ๐๐๏ธ
// Getting weekdays in English
console.log(getWeekdays({ locale: 'en-US' })); // Outputs ['Sunday', 'Monday', ..., 'Saturday']
// Discovering weekdays in French
console.log(getWeekdays({ locale: 'fr-FR' })); // Outputs ['dimanche', 'lundi', ..., 'samedi']
// Exploring weekdays in Japanese
console.log(getWeekdays({ locale: 'ja-JP' })); // Outputs ['ๆฅๆๆฅ', 'ๆๆๆฅ', ..., 'ๅๆๆฅ']
๐ก Did You Know? The order and names of weekdays vary across cultures and languages. With getWeekdays
, you can easily cater to a global audience, ensuring that your application speaks their language, quite literally! ๐๐ฃ๏ธ
๐๐๏ธ The parseDateTime
function is like a time-traveler's best friend, expertly navigating the complex world of dates and times. Whether it's a string or a Date object you're dealing with, this function seamlessly transforms it into a comprehensive, easy-to-digest package of date information, tailored to any locale you desire. ๐โฒ๏ธ
// Parsing a date string with default locale and options
const parsed1 = parseDateTime('18/01/2024');
console.log(parsed1); // Outputs object with detailed date components
/*
{
"day": "18",
"month": "01",
"year": "2024",
"rawParts": [
{
"type": "day",
"value": "18"
},
{
"type": "literal",
"value": "/"
},
{
"type": "month",
"value": "01"
},
{
"type": "literal",
"value": "/"
},
{
"type": "year",
"value": "2024"
}
],
"formattedDate": "18/01/2024",
"date": "2024-01-17T18:30:00.000Z"
}
*/
// Parsing with specific locale and formatting options
const parsed2 = parseDateTime('2024-01-23', {
intlOptions: {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
},
locale: 'fr-FR',
});
console.log(parsed2); // Outputs object with formatted date in French
/*
{
"weekday": "mardi",
"day": "23",
"month": "janvier",
"year": "2024",
"rawParts": [
{
"type": "weekday",
"value": "mardi"
},
{
"type": "literal",
"value": " "
},
{
"type": "day",
"value": "23"
},
{
"type": "literal",
"value": " "
},
{
"type": "month",
"value": "janvier"
},
{
"type": "literal",
"value": " "
},
{
"type": "year",
"value": "2024"
}
],
"formattedDate": "mardi 23 janvier 2024",
"date": "2024-01-22T18:30:00.000Z"
}
*/
// Parsing a Date object
const parsed3 = parseDateTime(new Date(2024, 0, 23));
console.log(parsed3); // Outputs object with date components for January 23, 2024
/*
{
"day": "23",
"month": "01",
"year": "2024",
"rawParts": [
{
"type": "day",
"value": "23"
},
{
"type": "literal",
"value": "/"
},
{
"type": "month",
"value": "01"
},
{
"type": "literal",
"value": "/"
},
{
"type": "year",
"value": "2024"
}
],
"formattedDate": "23/01/2024",
"date": "2024-01-22T18:30:00.000Z"
}
*/
๐ก Pro Tip: Leverage parseDateTime
in applications where detailed date analysis and manipulation are key, such as in calendar apps, scheduling tools, or date-sensitive data processing. It's like having a Swiss Army knife for all things related to dates and times! ๐
๐ ๏ธ
Leverage the power of Adobe's @internationalized/date with our module, designed to offer a sophisticated, locale-sensitive approach to managing dates and times. Utilize these advanced tools to create applications that are both intuitive and efficient, ensuring they connect with users worldwide.
Discover more about integrating these powerful components into your software at Adobe's Internationalized Date Documentation.
Tailor your app with comprehensive calendar interfaces, ensuring global locale compatibility.
Focus on date-specific functionalities, perfect for event planning and deadlines without the time zone hassle.
Merge dates and times seamlessly for scheduling and reminders, with smart time zone handling.
Simplify time tracking and events in your app, concentrating solely on time without the date aspect.
Master global time zones for scheduling and planning across borders, ensuring accuracy and user relevance.
FAQs
_A one-stop solution built in javascript to provide internationalization support._
We found that @razorpay/i18nify-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.