Socket
Socket
Sign inDemoInstall

globalize

Package Overview
Dependencies
Maintainers
3
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data.


Version published
Weekly downloads
343K
decreased by-16.39%
Maintainers
3
Weekly downloads
 
Created

What is globalize?

Globalize is a JavaScript library for internationalization and localization. It provides tools for formatting and parsing dates, numbers, and currencies, as well as for handling pluralization and message translation.

What are globalize's main functionalities?

Date Formatting

This feature allows you to format dates according to different locales. The code sample demonstrates how to format a date in the 'en' locale.

const Globalize = require('globalize');
Globalize.load(require('cldr-data').entireSupplemental());
Globalize.load(require('cldr-data').entireMainFor('en', 'es'));
Globalize.locale('en');
const formattedDate = Globalize.formatDate(new Date(), { datetime: 'medium' });
console.log(formattedDate);

Number Formatting

This feature allows you to format numbers according to different locales. The code sample demonstrates how to format a number in the 'en' locale.

const Globalize = require('globalize');
Globalize.load(require('cldr-data').entireSupplemental());
Globalize.load(require('cldr-data').entireMainFor('en', 'es'));
Globalize.locale('en');
const formattedNumber = Globalize.formatNumber(12345.6789);
console.log(formattedNumber);

Currency Formatting

This feature allows you to format currencies according to different locales. The code sample demonstrates how to format a currency in the 'en' locale.

const Globalize = require('globalize');
Globalize.load(require('cldr-data').entireSupplemental());
Globalize.load(require('cldr-data').entireMainFor('en', 'es'));
Globalize.locale('en');
const formattedCurrency = Globalize.formatCurrency(12345.6789, 'USD');
console.log(formattedCurrency);

Message Translation

This feature allows you to translate messages according to different locales. The code sample demonstrates how to translate a message in the 'en' locale.

const Globalize = require('globalize');
Globalize.loadMessages({
  en: { hello: 'Hello, {name}!' },
  es: { hello: '¡Hola, {name}!' }
});
Globalize.locale('en');
const message = Globalize.messageFormatter('hello')({ name: 'John' });
console.log(message);

Pluralization

This feature allows you to handle pluralization according to different locales. The code sample demonstrates how to handle pluralization in the 'en' locale.

const Globalize = require('globalize');
Globalize.load(require('cldr-data').entireSupplemental());
Globalize.load(require('cldr-data').entireMainFor('en', 'es'));
Globalize.locale('en');
const pluralize = Globalize.pluralGenerator();
console.log(pluralize(0)); // 'other'
console.log(pluralize(1)); // 'one'
console.log(pluralize(2)); // 'other'

Other packages similar to globalize

Keywords

FAQs

Package last updated on 18 May 2017

Did you know?

Socket

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.

Install

Related posts

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