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.
// Standalone table.
var numberFormatter = Globalize.numberFormatter({ maximumFractionDigits: 2 });
document.getElementById( "number" ).textContent = numberFormatter( 12345.6789 );
var numberCompactFormatter = Globalize.numberFormatter({
compact: "short",
minimumSignificantDigits: 1,
maximumSignificantDigits: 3
});
document.getElementById( "number-compact" ).textContent = numberCompactFormatter( 12345.6789 );
var currencyFormatter = Globalize.currencyFormatter( "USD" );
document.getElementById( "currency" ).textContent = currencyFormatter( 69900 );
var dateFormatter = Globalize.dateFormatter({ datetime: "medium" });
document.getElementById( "date" ).textContent = dateFormatter( new Date() );
var dateWithTimeZoneFormatter = Globalize.dateFormatter({
datetime: "full",
timeZone: "America/Sao_Paulo"
});
document.getElementById( "date-time-zone" ).textContent = dateWithTimeZoneFormatter( new Date() );
var _dateToPartsFormatter = Globalize.dateToPartsFormatter({ datetime: "medium" });
var dateToPartsFormatter = function( value ) {
return _dateToPartsFormatter( value, {
datetime: "medium"
}).map(function( part ) {
switch(part.type) {
case "month": return "<strong>" + part.value + "</strong>";
default: return part.value;
'assert method returns a method'() {
const locale = 'fr';
const value = new Date();
const options: DateFormatterOptions = { datetime: 'full' };
let formatter = globalizeDelegator('dateFormatter', {});
assert.strictEqual(formatter(value), Globalize.dateFormatter()(value));
formatter = globalizeDelegator('dateFormatter', {
optionsOrLocale: options
});
assert.strictEqual(formatter(value), Globalize.dateFormatter(options)(value));
formatter = globalizeDelegator('dateFormatter', {
locale,
optionsOrLocale: options
});
assert.strictEqual(formatter(value), new Globalize('fr').dateFormatter(options)(value));
}
}
document.getElementById( "number" ).textContent = numberFormatter( 12345.6789 );
var numberCompactFormatter = Globalize.numberFormatter({
compact: "short",
minimumSignificantDigits: 1,
maximumSignificantDigits: 3
});
document.getElementById( "number-compact" ).textContent = numberCompactFormatter( 12345.6789 );
var currencyFormatter = Globalize.currencyFormatter( "USD" );
document.getElementById( "currency" ).textContent = currencyFormatter( 69900 );
var dateFormatter = Globalize.dateFormatter({ datetime: "medium" });
document.getElementById( "date" ).textContent = dateFormatter( new Date() );
var dateWithTimeZoneFormatter = Globalize.dateFormatter({
datetime: "full",
timeZone: "America/Sao_Paulo"
});
document.getElementById( "date-time-zone" ).textContent = dateWithTimeZoneFormatter( new Date() );
var _dateToPartsFormatter = Globalize.dateToPartsFormatter({ datetime: "medium" });
var dateToPartsFormatter = function( value ) {
return _dateToPartsFormatter( value, {
datetime: "medium"
}).map(function( part ) {
switch(part.type) {
case "month": return "<strong>" + part.value + "</strong>";
default: return part.value;
}
}).reduce(function( memo, value ) {
return memo + value;