Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Use messageFormatter.
like = Globalize.messageFormatter("like");
// Use formatMessage.
console.log(Globalize.formatMessage("task", {count: 1000, formattedCount: "1,000"}));
/**
* Relative Time
*/
// Use relativeTimeFormatter.
var relativeTimeFormatter = Globalize.relativeTimeFormatter("day");
console.log(relativeTimeFormatter(0));
// Use formatRelativeTime.
console.log(Globalize.formatRelativeTime(-35, "second"));
/**
* Unit
*/
// Use unitFormatter.
var unitFormatter = Globalize.unitFormatter("kilowatt");
console.log(unitFormatter(120));
// Use formatUnit.
console.log(Globalize.formatUnit(60, "mile/hour", {form: "short"}));
// 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" } ) );
// 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" } ) );
const options: RelativeTimeFormatterOptions = { form: 'short' };
assert.strictEqual(
globalizeDelegator('formatRelativeTime', {
unit,
value
}),
Globalize.formatRelativeTime(value, unit)
);
assert.strictEqual(
globalizeDelegator('formatRelativeTime', {
optionsOrLocale: options,
unit,
value
}),
Globalize.formatRelativeTime(value, unit, options)
);
assert.strictEqual(
globalizeDelegator('formatRelativeTime', {
locale,
optionsOrLocale: options,
unit,
value
}),
new Globalize('fr').formatRelativeTime(value, unit, options)
);
},
'assert method that takes a value and a unit'() {
const locale = 'fr';
const unit = 'week';
const value = 5;
const options: RelativeTimeFormatterOptions = { form: 'short' };
assert.strictEqual(
globalizeDelegator('formatRelativeTime', {
unit,
value
}),
Globalize.formatRelativeTime(value, unit)
);
assert.strictEqual(
globalizeDelegator('formatRelativeTime', {
optionsOrLocale: options,
unit,
value
}),
Globalize.formatRelativeTime(value, unit, options)
);
assert.strictEqual(
globalizeDelegator('formatRelativeTime', {
locale,
optionsOrLocale: options,
unit,
value
}),