Vulcan/packages/nova-lib/lib/polyfills.js

39 lines
1,004 B
JavaScript
Raw Normal View History

import { getSetting } from './settings.js';
2016-11-26 11:17:01 +09:00
/*
Babel polyfill for SimpleSchema. See https://github.com/aldeed/node-simple-schema/issues/33
2016-11-26 11:17:01 +09:00
*/
Array.includes = function() {
let [first, ...rest] = arguments;
return Array.prototype.includes.apply(first, rest);
}
2016-11-26 11:17:01 +09:00
2016-08-08 11:18:21 +09:00
/*
intl polyfill. See https://github.com/andyearnshaw/Intl.js/
*/
const areIntlLocalesSupported = require('intl-locales-supported');
2016-06-09 17:42:20 +09:00
const localesMyAppSupports = [
2016-12-12 15:00:56 +09:00
getSetting("locale", "en")
2016-06-09 17:42:20 +09:00
];
if (global.Intl) {
// Determine if the built-in `Intl` has the locale data we need.
if (!areIntlLocalesSupported(localesMyAppSupports)) {
// `Intl` exists, but it doesn't have the data we need, so load the
// polyfill and replace the constructors with need with the polyfill's.
const IntlPolyfill = require('intl');
2016-06-09 17:42:20 +09:00
Intl.NumberFormat = IntlPolyfill.NumberFormat;
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
}
} else {
// No `Intl`, so use and load the polyfill.
global.Intl = require('intl');
}