Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Use formatCurrency.
console.log(Globalize.formatCurrency(69900, "USD"));
/**
* Message
*/
// Use pluralGenerator.
var pluralGenerator = Globalize.pluralGenerator({type: "ordinal"});
console.log(pluralGenerator(2));
// Use plural.
console.log(Globalize.plural(12345.6789));
// Use messageFormatter.
like = Globalize.messageFormatter("like");
console.log(like(0));
console.log(like(1));
console.log(like(2));
console.log(like(3));
// Use messageFormatter.
like = Globalize.messageFormatter("like");
// Use formatMessage.
console.log(Globalize.formatMessage("task", {count: 1000, formattedCount: "1,000"}));
/**
* Relative Time
*/
// Use relativeTimeFormatter.
// Use Globalize to format numbers (compact form).
console.log( Globalize.formatNumber( 12345.6789, {
compact: "short",
minimumSignificantDigits: 1,
maximumSignificantDigits: 3
}));
// Use Globalize to format currencies.
console.log( Globalize.formatCurrency( 69900, "USD" ) );
// Use Globalize to get the plural form of a numeric value.
console.log( Globalize.plural( 12345.6789 ) );
// Use Globalize to format a message with plural inflection.
like = Globalize.messageFormatter( "like" );
console.log( like( 0 ) );
console.log( like( 1 ) );
console.log( like( 2 ) );
console.log( like( 3 ) );
// Use Globalize to format relative time.
console.log( Globalize.formatRelativeTime( -35, "second" ) );
// Use Globalize to format unit.
console.log( Globalize.formatUnit( 60, "mile/hour", { form: "short" } ) );
Globalize.locale( "en" );
// Use Globalize to format dates.
console.log( Globalize.formatDate( new Date(), { datetime: "medium" } ) );
// Use Globalize to format numbers.
console.log( Globalize.formatNumber( 12345.6789 ) );
// Use Globalize to format currencies.
console.log( Globalize.formatCurrency( 69900, "USD" ) );
// Use Globalize to get the plural form of a numeric value.
console.log( Globalize.plural( 12345.6789 ) );
// Use Globalize to format a message with plural inflection.
like = Globalize.messageFormatter( "like" );
console.log( like( 0 ) );
console.log( like( 1 ) );
console.log( like( 2 ) );
console.log( like( 3 ) );
// Use Globalize to format relative time.
console.log( Globalize.formatRelativeTime( -35, "second" ) );
// Use Globalize to format unit.
console.log( Globalize.formatUnit( 60, "mile/hour", { form: "short" } ) );
// Elements replacement.
if (elements) {
formatted = _replaceElements(formatted, elements);
}
return formatted;
}
function sanitizePath(pathString) {
return pathString.trim().replace(/\{/g, "(").replace(/\}/g, ")").replace(/\//g, "|").replace(/\n/g, " ").replace(/ +/g, " ").replace(/"/g, "'");
}
// Overload Globalize's `.formatMessage` to allow default message.
var globalizeMessageFormatter = Globalize.messageFormatter;
Globalize.messageFormatter = Globalize.prototype.messageFormatter = function(pathOrMessage) {
var aux = {};
var sanitizedPath = sanitizePath(pathOrMessage);
// Globalize runtime
if (!this.cldr) {
// On runtime, the only way for deciding between using sanitizedPath or
// pathOrMessage as path is by checking which formatter exists.
arguments[0] = sanitizedPath;
aux = globalizeMessageFormatter.apply(this, arguments);
arguments[0] = pathOrMessage;
return aux || globalizeMessageFormatter.apply(this, arguments);
}
var sanitizedPathExists = this.cldr.get(["globalize-messages/{bundle}", sanitizedPath]) !== undefined;
var pathExists = this.cldr.get(["globalize-messages/{bundle}", pathOrMessage]) !== undefined;
// Elements replacement.
if (elements) {
formatted = _replaceElements(formatted, elements);
}
return formatted;
}
function sanitizePath(pathString) {
return pathString.trim().replace(/\{/g, "(").replace(/\}/g, ")").replace(/\//g, "|").replace(/\n/g, " ").replace(/ +/g, " ").replace(/"/g, "'");
}
// Overload Globalize's `.formatMessage` to allow default message.
var globalizeMessageFormatter = Globalize.messageFormatter;
Globalize.messageFormatter = Globalize.prototype.messageFormatter = function(pathOrMessage) {
var aux = {};
var sanitizedPath = sanitizePath(pathOrMessage);
// Globalize runtime
if (!this.cldr) {
// On runtime, the only way for deciding between using sanitizedPath or
// pathOrMessage as path is by checking which formatter exists.
arguments[0] = sanitizedPath;
aux = globalizeMessageFormatter.apply(this, arguments);
arguments[0] = pathOrMessage;
return aux || globalizeMessageFormatter.apply(this, arguments);
}
var sanitizedPathExists = this.cldr.get(["globalize-messages/{bundle}", sanitizedPath]) !== undefined;
var pathExists = this.cldr.get(["globalize-messages/{bundle}", pathOrMessage]) !== undefined;