UNPKG

ilib

Version:

iLib is a cross-engine library of internationalization (i18n) classes written in pure JS

3 lines 1.7 kB
var ilib=require("../index.js"),Locale=require("./Locale.js"),LocaleInfo=require("./LocaleInfo.js"),Calendar=require("./Calendar.js"),CalendarFactory=function(options){var locale,type,instance,sync=!0;return options&&(options.locale&&(locale="string"==typeof options.locale?new Locale(options.locale):options.locale),type=options.type||options.calendar,"boolean"==typeof options.sync)&&(sync=options.sync),locale=locale||new Locale(),type?instance=CalendarFactory._init(type,options):new LocaleInfo(locale,{sync:sync,loadParams:options&&options.loadParams,onLoad:function(info){type=info.getCalendar(),instance=CalendarFactory._init(type,options)}}),instance};function circumventWebPack(x){return"./"+x+"Cal.js"}CalendarFactory._dynMap={coptic:"Coptic",ethiopic:"Ethiopic",gregorian:"Gregorian",han:"Han",hebrew:"Hebrew",islamic:"Islamic",julian:"Julian",persian:"Persian","persian-algo":"PersianAlgo",thaisolar:"ThaiSolar"},CalendarFactory._dynLoadCalendar=function(name,fnc){var entry;return Calendar._constructors[name]||(entry=CalendarFactory._dynMap[name])&&( // eslint-disable-next-line Calendar._constructors[name]=require(fnc(entry))),Calendar._constructors[name]},CalendarFactory._init=function(type,options){return ilib.isDynCode()&&CalendarFactory._dynLoadCalendar(type,circumventWebPack),(type=Calendar._constructors[type])||"function"!=typeof options.onLoad||options.onLoad(void 0),type&&new type(options)},CalendarFactory.getCalendars=function(){var c,arr=[];if(ilib.isDynCode())for(c in CalendarFactory._dynMap)CalendarFactory._dynLoadCalendar(c,circumventWebPack);for(c in Calendar._constructors)c&&Calendar._constructors[c]&&arr.push(c);return arr},module.exports=CalendarFactory;