Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var like;
var Globalize = require("globalize");
/**
* Date
*/
// Use dateFormatter.
var dateFormatter = Globalize.dateFormatter({time: "medium"});
console.log(dateFormatter(new Date()));
// Use formatDate.
console.log(Globalize.formatDate(new Date(), {date: "medium"}));
// Use formatDate in specific time zones.
console.log(Globalize.formatDate(new Date(), {
datetime: "full",
timeZone: "America/Sao_Paulo"
}));
// Use dateToPartsFormatter.
var dateToPartsFormatter = Globalize.dateToPartsFormatter({time: "long"});
console.log(dateToPartsFormatter(new Date()));
// Use formatDateToParts.
console.log(Globalize.formatDateToParts(new Date(), {date: "long"}));
// Use dateParser in specific time zones.
var dateParser = Globalize.dateParser({skeleton: "MMMd", timeZone: "America/New_York"});
require( "cldr-data/main/en/dateFields" ),
require( "cldr-data/main/en/numbers" ),
require( "cldr-data/main/en/units" ),
require( "cldr-data/supplemental/currencyData" ),
require( "cldr-data/supplemental/likelySubtags" ),
require( "cldr-data/supplemental/plurals" ),
require( "cldr-data/supplemental/timeData" ),
require( "cldr-data/supplemental/weekData" )
);
Globalize.loadMessages( require( "./messages/en" ) );
// Set "en" as our default locale.
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 ) );
require( "cldr-data/supplemental/plurals" ),
require( "cldr-data/supplemental/timeData" ),
require( "cldr-data/supplemental/weekData" )
);
Globalize.loadMessages( require( "./messages/en" ) );
Globalize.loadTimeZone( require( "iana-tz-data" ) );
// Set "en" as our default locale.
Globalize.locale( "en" );
// Use Globalize to format dates.
console.log( Globalize.formatDate( new Date(), { datetime: "medium" } ) );
// Use Globalize to format dates in specific time zones.
console.log( Globalize.formatDate( new Date(), {
datetime: "full",
timeZone: "America/Sao_Paulo"
}));
// Use Globalize to format dates to parts.
console.log( Globalize.formatDateToParts( new Date(), { datetime: "medium" } ) );
// Use Globalize to format numbers.
console.log( Globalize.formatNumber( 12345.6789 ) );
// Use Globalize to format numbers (compact form).
console.log( Globalize.formatNumber( 12345.6789, {
compact: "short",
minimumSignificantDigits: 1,
maximumSignificantDigits: 3
}));
'assert method that takes a value'() {
const locale = 'fr';
const value = new Date();
const options: DateFormatterOptions = { datetime: 'full' };
assert.strictEqual(globalizeDelegator('formatDate', { value }), Globalize.formatDate(value));
assert.strictEqual(
globalizeDelegator('formatDate', {
optionsOrLocale: options,
value
}),
Globalize.formatDate(value, options)
);
assert.strictEqual(
globalizeDelegator('formatDate', {
locale,
optionsOrLocale: options,
value
}),
new Globalize('fr').formatDate(value, options)
);
},
'assert method that takes a value'() {
const locale = 'fr';
const value = new Date();
const options: DateFormatterOptions = { datetime: 'full' };
assert.strictEqual(globalizeDelegator('formatDate', { value }), Globalize.formatDate(value));
assert.strictEqual(
globalizeDelegator('formatDate', {
optionsOrLocale: options,
value
}),
Globalize.formatDate(value, options)
);
assert.strictEqual(
globalizeDelegator('formatDate', {
locale,
optionsOrLocale: options,
value
}),
new Globalize('fr').formatDate(value, options)
);
},