Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nunjucks-slim.js 104KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263
  1. /*! Browser bundle of nunjucks 3.2.3 (slim, only works with precompiled templates) */
  2. (function webpackUniversalModuleDefinition(root, factory) {
  3. if(typeof exports === 'object' && typeof module === 'object')
  4. module.exports = factory();
  5. else if(typeof define === 'function' && define.amd)
  6. define([], factory);
  7. else if(typeof exports === 'object')
  8. exports["nunjucks"] = factory();
  9. else
  10. root["nunjucks"] = factory();
  11. })(typeof self !== 'undefined' ? self : this, function() {
  12. return /******/ (function(modules) { // webpackBootstrap
  13. /******/ // The module cache
  14. /******/ var installedModules = {};
  15. /******/
  16. /******/ // The require function
  17. /******/ function __webpack_require__(moduleId) {
  18. /******/
  19. /******/ // Check if module is in cache
  20. /******/ if(installedModules[moduleId]) {
  21. /******/ return installedModules[moduleId].exports;
  22. /******/ }
  23. /******/ // Create a new module (and put it into the cache)
  24. /******/ var module = installedModules[moduleId] = {
  25. /******/ i: moduleId,
  26. /******/ l: false,
  27. /******/ exports: {}
  28. /******/ };
  29. /******/
  30. /******/ // Execute the module function
  31. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  32. /******/
  33. /******/ // Flag the module as loaded
  34. /******/ module.l = true;
  35. /******/
  36. /******/ // Return the exports of the module
  37. /******/ return module.exports;
  38. /******/ }
  39. /******/
  40. /******/
  41. /******/ // expose the modules object (__webpack_modules__)
  42. /******/ __webpack_require__.m = modules;
  43. /******/
  44. /******/ // expose the module cache
  45. /******/ __webpack_require__.c = installedModules;
  46. /******/
  47. /******/ // define getter function for harmony exports
  48. /******/ __webpack_require__.d = function(exports, name, getter) {
  49. /******/ if(!__webpack_require__.o(exports, name)) {
  50. /******/ Object.defineProperty(exports, name, {
  51. /******/ configurable: false,
  52. /******/ enumerable: true,
  53. /******/ get: getter
  54. /******/ });
  55. /******/ }
  56. /******/ };
  57. /******/
  58. /******/ // getDefaultExport function for compatibility with non-harmony modules
  59. /******/ __webpack_require__.n = function(module) {
  60. /******/ var getter = module && module.__esModule ?
  61. /******/ function getDefault() { return module['default']; } :
  62. /******/ function getModuleExports() { return module; };
  63. /******/ __webpack_require__.d(getter, 'a', getter);
  64. /******/ return getter;
  65. /******/ };
  66. /******/
  67. /******/ // Object.prototype.hasOwnProperty.call
  68. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  69. /******/
  70. /******/ // __webpack_public_path__
  71. /******/ __webpack_require__.p = "";
  72. /******/
  73. /******/ // Load entry module and return exports
  74. /******/ return __webpack_require__(__webpack_require__.s = 6);
  75. /******/ })
  76. /************************************************************************/
  77. /******/ ([
  78. /* 0 */
  79. /***/ (function(module, exports) {
  80. /***/ }),
  81. /* 1 */
  82. /***/ (function(module, exports, __webpack_require__) {
  83. "use strict";
  84. var ArrayProto = Array.prototype;
  85. var ObjProto = Object.prototype;
  86. var escapeMap = {
  87. '&': '&',
  88. '"': '"',
  89. '\'': ''',
  90. '<': '&lt;',
  91. '>': '&gt;'
  92. };
  93. var escapeRegex = /[&"'<>]/g;
  94. var exports = module.exports = {};
  95. function hasOwnProp(obj, k) {
  96. return ObjProto.hasOwnProperty.call(obj, k);
  97. }
  98. exports.hasOwnProp = hasOwnProp;
  99. function lookupEscape(ch) {
  100. return escapeMap[ch];
  101. }
  102. function _prettifyError(path, withInternals, err) {
  103. if (!err.Update) {
  104. // not one of ours, cast it
  105. err = new exports.TemplateError(err);
  106. }
  107. err.Update(path); // Unless they marked the dev flag, show them a trace from here
  108. if (!withInternals) {
  109. var old = err;
  110. err = new Error(old.message);
  111. err.name = old.name;
  112. }
  113. return err;
  114. }
  115. exports._prettifyError = _prettifyError;
  116. function TemplateError(message, lineno, colno) {
  117. var err;
  118. var cause;
  119. if (message instanceof Error) {
  120. cause = message;
  121. message = cause.name + ": " + cause.message;
  122. }
  123. if (Object.setPrototypeOf) {
  124. err = new Error(message);
  125. Object.setPrototypeOf(err, TemplateError.prototype);
  126. } else {
  127. err = this;
  128. Object.defineProperty(err, 'message', {
  129. enumerable: false,
  130. writable: true,
  131. value: message
  132. });
  133. }
  134. Object.defineProperty(err, 'name', {
  135. value: 'Template render error'
  136. });
  137. if (Error.captureStackTrace) {
  138. Error.captureStackTrace(err, this.constructor);
  139. }
  140. var getStack;
  141. if (cause) {
  142. var stackDescriptor = Object.getOwnPropertyDescriptor(cause, 'stack');
  143. getStack = stackDescriptor && (stackDescriptor.get || function () {
  144. return stackDescriptor.value;
  145. });
  146. if (!getStack) {
  147. getStack = function getStack() {
  148. return cause.stack;
  149. };
  150. }
  151. } else {
  152. var stack = new Error(message).stack;
  153. getStack = function getStack() {
  154. return stack;
  155. };
  156. }
  157. Object.defineProperty(err, 'stack', {
  158. get: function get() {
  159. return getStack.call(err);
  160. }
  161. });
  162. Object.defineProperty(err, 'cause', {
  163. value: cause
  164. });
  165. err.lineno = lineno;
  166. err.colno = colno;
  167. err.firstUpdate = true;
  168. err.Update = function Update(path) {
  169. var msg = '(' + (path || 'unknown path') + ')'; // only show lineno + colno next to path of template
  170. // where error occurred
  171. if (this.firstUpdate) {
  172. if (this.lineno && this.colno) {
  173. msg += " [Line " + this.lineno + ", Column " + this.colno + "]";
  174. } else if (this.lineno) {
  175. msg += " [Line " + this.lineno + "]";
  176. }
  177. }
  178. msg += '\n ';
  179. if (this.firstUpdate) {
  180. msg += ' ';
  181. }
  182. this.message = msg + (this.message || '');
  183. this.firstUpdate = false;
  184. return this;
  185. };
  186. return err;
  187. }
  188. if (Object.setPrototypeOf) {
  189. Object.setPrototypeOf(TemplateError.prototype, Error.prototype);
  190. } else {
  191. TemplateError.prototype = Object.create(Error.prototype, {
  192. constructor: {
  193. value: TemplateError
  194. }
  195. });
  196. }
  197. exports.TemplateError = TemplateError;
  198. function escape(val) {
  199. return val.replace(escapeRegex, lookupEscape);
  200. }
  201. exports.escape = escape;
  202. function isFunction(obj) {
  203. return ObjProto.toString.call(obj) === '[object Function]';
  204. }
  205. exports.isFunction = isFunction;
  206. function isArray(obj) {
  207. return ObjProto.toString.call(obj) === '[object Array]';
  208. }
  209. exports.isArray = isArray;
  210. function isString(obj) {
  211. return ObjProto.toString.call(obj) === '[object String]';
  212. }
  213. exports.isString = isString;
  214. function isObject(obj) {
  215. return ObjProto.toString.call(obj) === '[object Object]';
  216. }
  217. exports.isObject = isObject;
  218. /**
  219. * @param {string|number} attr
  220. * @returns {(string|number)[]}
  221. * @private
  222. */
  223. function _prepareAttributeParts(attr) {
  224. if (!attr) {
  225. return [];
  226. }
  227. if (typeof attr === 'string') {
  228. return attr.split('.');
  229. }
  230. return [attr];
  231. }
  232. /**
  233. * @param {string} attribute Attribute value. Dots allowed.
  234. * @returns {function(Object): *}
  235. */
  236. function getAttrGetter(attribute) {
  237. var parts = _prepareAttributeParts(attribute);
  238. return function attrGetter(item) {
  239. var _item = item;
  240. for (var i = 0; i < parts.length; i++) {
  241. var part = parts[i]; // If item is not an object, and we still got parts to handle, it means
  242. // that something goes wrong. Just roll out to undefined in that case.
  243. if (hasOwnProp(_item, part)) {
  244. _item = _item[part];
  245. } else {
  246. return undefined;
  247. }
  248. }
  249. return _item;
  250. };
  251. }
  252. exports.getAttrGetter = getAttrGetter;
  253. function groupBy(obj, val, throwOnUndefined) {
  254. var result = {};
  255. var iterator = isFunction(val) ? val : getAttrGetter(val);
  256. for (var i = 0; i < obj.length; i++) {
  257. var value = obj[i];
  258. var key = iterator(value, i);
  259. if (key === undefined && throwOnUndefined === true) {
  260. throw new TypeError("groupby: attribute \"" + val + "\" resolved to undefined");
  261. }
  262. (result[key] || (result[key] = [])).push(value);
  263. }
  264. return result;
  265. }
  266. exports.groupBy = groupBy;
  267. function toArray(obj) {
  268. return Array.prototype.slice.call(obj);
  269. }
  270. exports.toArray = toArray;
  271. function without(array) {
  272. var result = [];
  273. if (!array) {
  274. return result;
  275. }
  276. var length = array.length;
  277. var contains = toArray(arguments).slice(1);
  278. var index = -1;
  279. while (++index < length) {
  280. if (indexOf(contains, array[index]) === -1) {
  281. result.push(array[index]);
  282. }
  283. }
  284. return result;
  285. }
  286. exports.without = without;
  287. function repeat(char_, n) {
  288. var str = '';
  289. for (var i = 0; i < n; i++) {
  290. str += char_;
  291. }
  292. return str;
  293. }
  294. exports.repeat = repeat;
  295. function each(obj, func, context) {
  296. if (obj == null) {
  297. return;
  298. }
  299. if (ArrayProto.forEach && obj.forEach === ArrayProto.forEach) {
  300. obj.forEach(func, context);
  301. } else if (obj.length === +obj.length) {
  302. for (var i = 0, l = obj.length; i < l; i++) {
  303. func.call(context, obj[i], i, obj);
  304. }
  305. }
  306. }
  307. exports.each = each;
  308. function map(obj, func) {
  309. var results = [];
  310. if (obj == null) {
  311. return results;
  312. }
  313. if (ArrayProto.map && obj.map === ArrayProto.map) {
  314. return obj.map(func);
  315. }
  316. for (var i = 0; i < obj.length; i++) {
  317. results[results.length] = func(obj[i], i);
  318. }
  319. if (obj.length === +obj.length) {
  320. results.length = obj.length;
  321. }
  322. return results;
  323. }
  324. exports.map = map;
  325. function asyncIter(arr, iter, cb) {
  326. var i = -1;
  327. function next() {
  328. i++;
  329. if (i < arr.length) {
  330. iter(arr[i], i, next, cb);
  331. } else {
  332. cb();
  333. }
  334. }
  335. next();
  336. }
  337. exports.asyncIter = asyncIter;
  338. function asyncFor(obj, iter, cb) {
  339. var keys = keys_(obj || {});
  340. var len = keys.length;
  341. var i = -1;
  342. function next() {
  343. i++;
  344. var k = keys[i];
  345. if (i < len) {
  346. iter(k, obj[k], i, len, next);
  347. } else {
  348. cb();
  349. }
  350. }
  351. next();
  352. }
  353. exports.asyncFor = asyncFor;
  354. function indexOf(arr, searchElement, fromIndex) {
  355. return Array.prototype.indexOf.call(arr || [], searchElement, fromIndex);
  356. }
  357. exports.indexOf = indexOf;
  358. function keys_(obj) {
  359. /* eslint-disable no-restricted-syntax */
  360. var arr = [];
  361. for (var k in obj) {
  362. if (hasOwnProp(obj, k)) {
  363. arr.push(k);
  364. }
  365. }
  366. return arr;
  367. }
  368. exports.keys = keys_;
  369. function _entries(obj) {
  370. return keys_(obj).map(function (k) {
  371. return [k, obj[k]];
  372. });
  373. }
  374. exports._entries = _entries;
  375. function _values(obj) {
  376. return keys_(obj).map(function (k) {
  377. return obj[k];
  378. });
  379. }
  380. exports._values = _values;
  381. function extend(obj1, obj2) {
  382. obj1 = obj1 || {};
  383. keys_(obj2).forEach(function (k) {
  384. obj1[k] = obj2[k];
  385. });
  386. return obj1;
  387. }
  388. exports._assign = exports.extend = extend;
  389. function inOperator(key, val) {
  390. if (isArray(val) || isString(val)) {
  391. return val.indexOf(key) !== -1;
  392. } else if (isObject(val)) {
  393. return key in val;
  394. }
  395. throw new Error('Cannot use "in" operator to search for "' + key + '" in unexpected types.');
  396. }
  397. exports.inOperator = inOperator;
  398. /***/ }),
  399. /* 2 */
  400. /***/ (function(module, exports, __webpack_require__) {
  401. "use strict";
  402. var lib = __webpack_require__(1);
  403. var arrayFrom = Array.from;
  404. var supportsIterators = typeof Symbol === 'function' && Symbol.iterator && typeof arrayFrom === 'function'; // Frames keep track of scoping both at compile-time and run-time so
  405. // we know how to access variables. Block tags can introduce special
  406. // variables, for example.
  407. var Frame = /*#__PURE__*/function () {
  408. function Frame(parent, isolateWrites) {
  409. this.variables = Object.create(null);
  410. this.parent = parent;
  411. this.topLevel = false; // if this is true, writes (set) should never propagate upwards past
  412. // this frame to its parent (though reads may).
  413. this.isolateWrites = isolateWrites;
  414. }
  415. var _proto = Frame.prototype;
  416. _proto.set = function set(name, val, resolveUp) {
  417. // Allow variables with dots by automatically creating the
  418. // nested structure
  419. var parts = name.split('.');
  420. var obj = this.variables;
  421. var frame = this;
  422. if (resolveUp) {
  423. if (frame = this.resolve(parts[0], true)) {
  424. frame.set(name, val);
  425. return;
  426. }
  427. }
  428. for (var i = 0; i < parts.length - 1; i++) {
  429. var id = parts[i];
  430. if (!obj[id]) {
  431. obj[id] = {};
  432. }
  433. obj = obj[id];
  434. }
  435. obj[parts[parts.length - 1]] = val;
  436. };
  437. _proto.get = function get(name) {
  438. var val = this.variables[name];
  439. if (val !== undefined) {
  440. return val;
  441. }
  442. return null;
  443. };
  444. _proto.lookup = function lookup(name) {
  445. var p = this.parent;
  446. var val = this.variables[name];
  447. if (val !== undefined) {
  448. return val;
  449. }
  450. return p && p.lookup(name);
  451. };
  452. _proto.resolve = function resolve(name, forWrite) {
  453. var p = forWrite && this.isolateWrites ? undefined : this.parent;
  454. var val = this.variables[name];
  455. if (val !== undefined) {
  456. return this;
  457. }
  458. return p && p.resolve(name);
  459. };
  460. _proto.push = function push(isolateWrites) {
  461. return new Frame(this, isolateWrites);
  462. };
  463. _proto.pop = function pop() {
  464. return this.parent;
  465. };
  466. return Frame;
  467. }();
  468. function makeMacro(argNames, kwargNames, func) {
  469. return function macro() {
  470. for (var _len = arguments.length, macroArgs = new Array(_len), _key = 0; _key < _len; _key++) {
  471. macroArgs[_key] = arguments[_key];
  472. }
  473. var argCount = numArgs(macroArgs);
  474. var args;
  475. var kwargs = getKeywordArgs(macroArgs);
  476. if (argCount > argNames.length) {
  477. args = macroArgs.slice(0, argNames.length); // Positional arguments that should be passed in as
  478. // keyword arguments (essentially default values)
  479. macroArgs.slice(args.length, argCount).forEach(function (val, i) {
  480. if (i < kwargNames.length) {
  481. kwargs[kwargNames[i]] = val;
  482. }
  483. });
  484. args.push(kwargs);
  485. } else if (argCount < argNames.length) {
  486. args = macroArgs.slice(0, argCount);
  487. for (var i = argCount; i < argNames.length; i++) {
  488. var arg = argNames[i]; // Keyword arguments that should be passed as
  489. // positional arguments, i.e. the caller explicitly
  490. // used the name of a positional arg
  491. args.push(kwargs[arg]);
  492. delete kwargs[arg];
  493. }
  494. args.push(kwargs);
  495. } else {
  496. args = macroArgs;
  497. }
  498. return func.apply(this, args);
  499. };
  500. }
  501. function makeKeywordArgs(obj) {
  502. obj.__keywords = true;
  503. return obj;
  504. }
  505. function isKeywordArgs(obj) {
  506. return obj && Object.prototype.hasOwnProperty.call(obj, '__keywords');
  507. }
  508. function getKeywordArgs(args) {
  509. var len = args.length;
  510. if (len) {
  511. var lastArg = args[len - 1];
  512. if (isKeywordArgs(lastArg)) {
  513. return lastArg;
  514. }
  515. }
  516. return {};
  517. }
  518. function numArgs(args) {
  519. var len = args.length;
  520. if (len === 0) {
  521. return 0;
  522. }
  523. var lastArg = args[len - 1];
  524. if (isKeywordArgs(lastArg)) {
  525. return len - 1;
  526. } else {
  527. return len;
  528. }
  529. } // A SafeString object indicates that the string should not be
  530. // autoescaped. This happens magically because autoescaping only
  531. // occurs on primitive string objects.
  532. function SafeString(val) {
  533. if (typeof val !== 'string') {
  534. return val;
  535. }
  536. this.val = val;
  537. this.length = val.length;
  538. }
  539. SafeString.prototype = Object.create(String.prototype, {
  540. length: {
  541. writable: true,
  542. configurable: true,
  543. value: 0
  544. }
  545. });
  546. SafeString.prototype.valueOf = function valueOf() {
  547. return this.val;
  548. };
  549. SafeString.prototype.toString = function toString() {
  550. return this.val;
  551. };
  552. function copySafeness(dest, target) {
  553. if (dest instanceof SafeString) {
  554. return new SafeString(target);
  555. }
  556. return target.toString();
  557. }
  558. function markSafe(val) {
  559. var type = typeof val;
  560. if (type === 'string') {
  561. return new SafeString(val);
  562. } else if (type !== 'function') {
  563. return val;
  564. } else {
  565. return function wrapSafe(args) {
  566. var ret = val.apply(this, arguments);
  567. if (typeof ret === 'string') {
  568. return new SafeString(ret);
  569. }
  570. return ret;
  571. };
  572. }
  573. }
  574. function suppressValue(val, autoescape) {
  575. val = val !== undefined && val !== null ? val : '';
  576. if (autoescape && !(val instanceof SafeString)) {
  577. val = lib.escape(val.toString());
  578. }
  579. return val;
  580. }
  581. function ensureDefined(val, lineno, colno) {
  582. if (val === null || val === undefined) {
  583. throw new lib.TemplateError('attempted to output null or undefined value', lineno + 1, colno + 1);
  584. }
  585. return val;
  586. }
  587. function memberLookup(obj, val) {
  588. if (obj === undefined || obj === null) {
  589. return undefined;
  590. }
  591. if (typeof obj[val] === 'function') {
  592. return function () {
  593. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  594. args[_key2] = arguments[_key2];
  595. }
  596. return obj[val].apply(obj, args);
  597. };
  598. }
  599. return obj[val];
  600. }
  601. function callWrap(obj, name, context, args) {
  602. if (!obj) {
  603. throw new Error('Unable to call `' + name + '`, which is undefined or falsey');
  604. } else if (typeof obj !== 'function') {
  605. throw new Error('Unable to call `' + name + '`, which is not a function');
  606. }
  607. return obj.apply(context, args);
  608. }
  609. function contextOrFrameLookup(context, frame, name) {
  610. var val = frame.lookup(name);
  611. return val !== undefined ? val : context.lookup(name);
  612. }
  613. function handleError(error, lineno, colno) {
  614. if (error.lineno) {
  615. return error;
  616. } else {
  617. return new lib.TemplateError(error, lineno, colno);
  618. }
  619. }
  620. function asyncEach(arr, dimen, iter, cb) {
  621. if (lib.isArray(arr)) {
  622. var len = arr.length;
  623. lib.asyncIter(arr, function iterCallback(item, i, next) {
  624. switch (dimen) {
  625. case 1:
  626. iter(item, i, len, next);
  627. break;
  628. case 2:
  629. iter(item[0], item[1], i, len, next);
  630. break;
  631. case 3:
  632. iter(item[0], item[1], item[2], i, len, next);
  633. break;
  634. default:
  635. item.push(i, len, next);
  636. iter.apply(this, item);
  637. }
  638. }, cb);
  639. } else {
  640. lib.asyncFor(arr, function iterCallback(key, val, i, len, next) {
  641. iter(key, val, i, len, next);
  642. }, cb);
  643. }
  644. }
  645. function asyncAll(arr, dimen, func, cb) {
  646. var finished = 0;
  647. var len;
  648. var outputArr;
  649. function done(i, output) {
  650. finished++;
  651. outputArr[i] = output;
  652. if (finished === len) {
  653. cb(null, outputArr.join(''));
  654. }
  655. }
  656. if (lib.isArray(arr)) {
  657. len = arr.length;
  658. outputArr = new Array(len);
  659. if (len === 0) {
  660. cb(null, '');
  661. } else {
  662. for (var i = 0; i < arr.length; i++) {
  663. var item = arr[i];
  664. switch (dimen) {
  665. case 1:
  666. func(item, i, len, done);
  667. break;
  668. case 2:
  669. func(item[0], item[1], i, len, done);
  670. break;
  671. case 3:
  672. func(item[0], item[1], item[2], i, len, done);
  673. break;
  674. default:
  675. item.push(i, len, done);
  676. func.apply(this, item);
  677. }
  678. }
  679. }
  680. } else {
  681. var keys = lib.keys(arr || {});
  682. len = keys.length;
  683. outputArr = new Array(len);
  684. if (len === 0) {
  685. cb(null, '');
  686. } else {
  687. for (var _i = 0; _i < keys.length; _i++) {
  688. var k = keys[_i];
  689. func(k, arr[k], _i, len, done);
  690. }
  691. }
  692. }
  693. }
  694. function fromIterator(arr) {
  695. if (typeof arr !== 'object' || arr === null || lib.isArray(arr)) {
  696. return arr;
  697. } else if (supportsIterators && Symbol.iterator in arr) {
  698. return arrayFrom(arr);
  699. } else {
  700. return arr;
  701. }
  702. }
  703. module.exports = {
  704. Frame: Frame,
  705. makeMacro: makeMacro,
  706. makeKeywordArgs: makeKeywordArgs,
  707. numArgs: numArgs,
  708. suppressValue: suppressValue,
  709. ensureDefined: ensureDefined,
  710. memberLookup: memberLookup,
  711. contextOrFrameLookup: contextOrFrameLookup,
  712. callWrap: callWrap,
  713. handleError: handleError,
  714. isArray: lib.isArray,
  715. keys: lib.keys,
  716. SafeString: SafeString,
  717. copySafeness: copySafeness,
  718. markSafe: markSafe,
  719. asyncEach: asyncEach,
  720. asyncAll: asyncAll,
  721. inOperator: lib.inOperator,
  722. fromIterator: fromIterator
  723. };
  724. /***/ }),
  725. /* 3 */
  726. /***/ (function(module, exports, __webpack_require__) {
  727. "use strict";
  728. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  729. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  730. var Loader = __webpack_require__(4);
  731. var PrecompiledLoader = /*#__PURE__*/function (_Loader) {
  732. _inheritsLoose(PrecompiledLoader, _Loader);
  733. function PrecompiledLoader(compiledTemplates) {
  734. var _this;
  735. _this = _Loader.call(this) || this;
  736. _this.precompiled = compiledTemplates || {};
  737. return _this;
  738. }
  739. var _proto = PrecompiledLoader.prototype;
  740. _proto.getSource = function getSource(name) {
  741. if (this.precompiled[name]) {
  742. return {
  743. src: {
  744. type: 'code',
  745. obj: this.precompiled[name]
  746. },
  747. path: name
  748. };
  749. }
  750. return null;
  751. };
  752. return PrecompiledLoader;
  753. }(Loader);
  754. module.exports = {
  755. PrecompiledLoader: PrecompiledLoader
  756. };
  757. /***/ }),
  758. /* 4 */
  759. /***/ (function(module, exports, __webpack_require__) {
  760. "use strict";
  761. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  762. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  763. var path = __webpack_require__(0);
  764. var _require = __webpack_require__(5),
  765. EmitterObj = _require.EmitterObj;
  766. module.exports = /*#__PURE__*/function (_EmitterObj) {
  767. _inheritsLoose(Loader, _EmitterObj);
  768. function Loader() {
  769. return _EmitterObj.apply(this, arguments) || this;
  770. }
  771. var _proto = Loader.prototype;
  772. _proto.resolve = function resolve(from, to) {
  773. return path.resolve(path.dirname(from), to);
  774. };
  775. _proto.isRelative = function isRelative(filename) {
  776. return filename.indexOf('./') === 0 || filename.indexOf('../') === 0;
  777. };
  778. return Loader;
  779. }(EmitterObj);
  780. /***/ }),
  781. /* 5 */
  782. /***/ (function(module, exports, __webpack_require__) {
  783. "use strict";
  784. // A simple class system, more documentation to come
  785. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  786. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  787. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  788. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  789. var EventEmitter = __webpack_require__(13);
  790. var lib = __webpack_require__(1);
  791. function parentWrap(parent, prop) {
  792. if (typeof parent !== 'function' || typeof prop !== 'function') {
  793. return prop;
  794. }
  795. return function wrap() {
  796. // Save the current parent method
  797. var tmp = this.parent; // Set parent to the previous method, call, and restore
  798. this.parent = parent;
  799. var res = prop.apply(this, arguments);
  800. this.parent = tmp;
  801. return res;
  802. };
  803. }
  804. function extendClass(cls, name, props) {
  805. props = props || {};
  806. lib.keys(props).forEach(function (k) {
  807. props[k] = parentWrap(cls.prototype[k], props[k]);
  808. });
  809. var subclass = /*#__PURE__*/function (_cls) {
  810. _inheritsLoose(subclass, _cls);
  811. function subclass() {
  812. return _cls.apply(this, arguments) || this;
  813. }
  814. _createClass(subclass, [{
  815. key: "typename",
  816. get: function get() {
  817. return name;
  818. }
  819. }]);
  820. return subclass;
  821. }(cls);
  822. lib._assign(subclass.prototype, props);
  823. return subclass;
  824. }
  825. var Obj = /*#__PURE__*/function () {
  826. function Obj() {
  827. // Unfortunately necessary for backwards compatibility
  828. this.init.apply(this, arguments);
  829. }
  830. var _proto = Obj.prototype;
  831. _proto.init = function init() {};
  832. Obj.extend = function extend(name, props) {
  833. if (typeof name === 'object') {
  834. props = name;
  835. name = 'anonymous';
  836. }
  837. return extendClass(this, name, props);
  838. };
  839. _createClass(Obj, [{
  840. key: "typename",
  841. get: function get() {
  842. return this.constructor.name;
  843. }
  844. }]);
  845. return Obj;
  846. }();
  847. var EmitterObj = /*#__PURE__*/function (_EventEmitter) {
  848. _inheritsLoose(EmitterObj, _EventEmitter);
  849. function EmitterObj() {
  850. var _this2;
  851. var _this;
  852. _this = _EventEmitter.call(this) || this; // Unfortunately necessary for backwards compatibility
  853. (_this2 = _this).init.apply(_this2, arguments);
  854. return _this;
  855. }
  856. var _proto2 = EmitterObj.prototype;
  857. _proto2.init = function init() {};
  858. EmitterObj.extend = function extend(name, props) {
  859. if (typeof name === 'object') {
  860. props = name;
  861. name = 'anonymous';
  862. }
  863. return extendClass(this, name, props);
  864. };
  865. _createClass(EmitterObj, [{
  866. key: "typename",
  867. get: function get() {
  868. return this.constructor.name;
  869. }
  870. }]);
  871. return EmitterObj;
  872. }(EventEmitter);
  873. module.exports = {
  874. Obj: Obj,
  875. EmitterObj: EmitterObj
  876. };
  877. /***/ }),
  878. /* 6 */
  879. /***/ (function(module, exports, __webpack_require__) {
  880. "use strict";
  881. var lib = __webpack_require__(1);
  882. var _require = __webpack_require__(7),
  883. Environment = _require.Environment,
  884. Template = _require.Template;
  885. var Loader = __webpack_require__(4);
  886. var loaders = __webpack_require__(3);
  887. var precompile = __webpack_require__(0);
  888. var compiler = __webpack_require__(0);
  889. var parser = __webpack_require__(0);
  890. var lexer = __webpack_require__(0);
  891. var runtime = __webpack_require__(2);
  892. var nodes = __webpack_require__(0);
  893. var installJinjaCompat = __webpack_require__(17); // A single instance of an environment, since this is so commonly used
  894. var e;
  895. function configure(templatesPath, opts) {
  896. opts = opts || {};
  897. if (lib.isObject(templatesPath)) {
  898. opts = templatesPath;
  899. templatesPath = null;
  900. }
  901. var TemplateLoader;
  902. if (loaders.FileSystemLoader) {
  903. TemplateLoader = new loaders.FileSystemLoader(templatesPath, {
  904. watch: opts.watch,
  905. noCache: opts.noCache
  906. });
  907. } else if (loaders.WebLoader) {
  908. TemplateLoader = new loaders.WebLoader(templatesPath, {
  909. useCache: opts.web && opts.web.useCache,
  910. async: opts.web && opts.web.async
  911. });
  912. }
  913. e = new Environment(TemplateLoader, opts);
  914. if (opts && opts.express) {
  915. e.express(opts.express);
  916. }
  917. return e;
  918. }
  919. module.exports = {
  920. Environment: Environment,
  921. Template: Template,
  922. Loader: Loader,
  923. FileSystemLoader: loaders.FileSystemLoader,
  924. NodeResolveLoader: loaders.NodeResolveLoader,
  925. PrecompiledLoader: loaders.PrecompiledLoader,
  926. WebLoader: loaders.WebLoader,
  927. compiler: compiler,
  928. parser: parser,
  929. lexer: lexer,
  930. runtime: runtime,
  931. lib: lib,
  932. nodes: nodes,
  933. installJinjaCompat: installJinjaCompat,
  934. configure: configure,
  935. reset: function reset() {
  936. e = undefined;
  937. },
  938. compile: function compile(src, env, path, eagerCompile) {
  939. if (!e) {
  940. configure();
  941. }
  942. return new Template(src, env, path, eagerCompile);
  943. },
  944. render: function render(name, ctx, cb) {
  945. if (!e) {
  946. configure();
  947. }
  948. return e.render(name, ctx, cb);
  949. },
  950. renderString: function renderString(src, ctx, cb) {
  951. if (!e) {
  952. configure();
  953. }
  954. return e.renderString(src, ctx, cb);
  955. },
  956. precompile: precompile ? precompile.precompile : undefined,
  957. precompileString: precompile ? precompile.precompileString : undefined
  958. };
  959. /***/ }),
  960. /* 7 */
  961. /***/ (function(module, exports, __webpack_require__) {
  962. "use strict";
  963. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  964. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  965. var asap = __webpack_require__(8);
  966. var _waterfall = __webpack_require__(11);
  967. var lib = __webpack_require__(1);
  968. var compiler = __webpack_require__(0);
  969. var filters = __webpack_require__(12);
  970. var _require = __webpack_require__(3),
  971. FileSystemLoader = _require.FileSystemLoader,
  972. WebLoader = _require.WebLoader,
  973. PrecompiledLoader = _require.PrecompiledLoader;
  974. var tests = __webpack_require__(14);
  975. var globals = __webpack_require__(15);
  976. var _require2 = __webpack_require__(5),
  977. Obj = _require2.Obj,
  978. EmitterObj = _require2.EmitterObj;
  979. var globalRuntime = __webpack_require__(2);
  980. var handleError = globalRuntime.handleError,
  981. Frame = globalRuntime.Frame;
  982. var expressApp = __webpack_require__(16); // If the user is using the async API, *always* call it
  983. // asynchronously even if the template was synchronous.
  984. function callbackAsap(cb, err, res) {
  985. asap(function () {
  986. cb(err, res);
  987. });
  988. }
  989. /**
  990. * A no-op template, for use with {% include ignore missing %}
  991. */
  992. var noopTmplSrc = {
  993. type: 'code',
  994. obj: {
  995. root: function root(env, context, frame, runtime, cb) {
  996. try {
  997. cb(null, '');
  998. } catch (e) {
  999. cb(handleError(e, null, null));
  1000. }
  1001. }
  1002. }
  1003. };
  1004. var Environment = /*#__PURE__*/function (_EmitterObj) {
  1005. _inheritsLoose(Environment, _EmitterObj);
  1006. function Environment() {
  1007. return _EmitterObj.apply(this, arguments) || this;
  1008. }
  1009. var _proto = Environment.prototype;
  1010. _proto.init = function init(loaders, opts) {
  1011. var _this = this;
  1012. // The dev flag determines the trace that'll be shown on errors.
  1013. // If set to true, returns the full trace from the error point,
  1014. // otherwise will return trace starting from Template.render
  1015. // (the full trace from within nunjucks may confuse developers using
  1016. // the library)
  1017. // defaults to false
  1018. opts = this.opts = opts || {};
  1019. this.opts.dev = !!opts.dev; // The autoescape flag sets global autoescaping. If true,
  1020. // every string variable will be escaped by default.
  1021. // If false, strings can be manually escaped using the `escape` filter.
  1022. // defaults to true
  1023. this.opts.autoescape = opts.autoescape != null ? opts.autoescape : true; // If true, this will make the system throw errors if trying
  1024. // to output a null or undefined value
  1025. this.opts.throwOnUndefined = !!opts.throwOnUndefined;
  1026. this.opts.trimBlocks = !!opts.trimBlocks;
  1027. this.opts.lstripBlocks = !!opts.lstripBlocks;
  1028. this.loaders = [];
  1029. if (!loaders) {
  1030. // The filesystem loader is only available server-side
  1031. if (FileSystemLoader) {
  1032. this.loaders = [new FileSystemLoader('views')];
  1033. } else if (WebLoader) {
  1034. this.loaders = [new WebLoader('/views')];
  1035. }
  1036. } else {
  1037. this.loaders = lib.isArray(loaders) ? loaders : [loaders];
  1038. } // It's easy to use precompiled templates: just include them
  1039. // before you configure nunjucks and this will automatically
  1040. // pick it up and use it
  1041. if (typeof window !== 'undefined' && window.nunjucksPrecompiled) {
  1042. this.loaders.unshift(new PrecompiledLoader(window.nunjucksPrecompiled));
  1043. }
  1044. this._initLoaders();
  1045. this.globals = globals();
  1046. this.filters = {};
  1047. this.tests = {};
  1048. this.asyncFilters = [];
  1049. this.extensions = {};
  1050. this.extensionsList = [];
  1051. lib._entries(filters).forEach(function (_ref) {
  1052. var name = _ref[0],
  1053. filter = _ref[1];
  1054. return _this.addFilter(name, filter);
  1055. });
  1056. lib._entries(tests).forEach(function (_ref2) {
  1057. var name = _ref2[0],
  1058. test = _ref2[1];
  1059. return _this.addTest(name, test);
  1060. });
  1061. };
  1062. _proto._initLoaders = function _initLoaders() {
  1063. var _this2 = this;
  1064. this.loaders.forEach(function (loader) {
  1065. // Caching and cache busting
  1066. loader.cache = {};
  1067. if (typeof loader.on === 'function') {
  1068. loader.on('update', function (name, fullname) {
  1069. loader.cache[name] = null;
  1070. _this2.emit('update', name, fullname, loader);
  1071. });
  1072. loader.on('load', function (name, source) {
  1073. _this2.emit('load', name, source, loader);
  1074. });
  1075. }
  1076. });
  1077. };
  1078. _proto.invalidateCache = function invalidateCache() {
  1079. this.loaders.forEach(function (loader) {
  1080. loader.cache = {};
  1081. });
  1082. };
  1083. _proto.addExtension = function addExtension(name, extension) {
  1084. extension.__name = name;
  1085. this.extensions[name] = extension;
  1086. this.extensionsList.push(extension);
  1087. return this;
  1088. };
  1089. _proto.removeExtension = function removeExtension(name) {
  1090. var extension = this.getExtension(name);
  1091. if (!extension) {
  1092. return;
  1093. }
  1094. this.extensionsList = lib.without(this.extensionsList, extension);
  1095. delete this.extensions[name];
  1096. };
  1097. _proto.getExtension = function getExtension(name) {
  1098. return this.extensions[name];
  1099. };
  1100. _proto.hasExtension = function hasExtension(name) {
  1101. return !!this.extensions[name];
  1102. };
  1103. _proto.addGlobal = function addGlobal(name, value) {
  1104. this.globals[name] = value;
  1105. return this;
  1106. };
  1107. _proto.getGlobal = function getGlobal(name) {
  1108. if (typeof this.globals[name] === 'undefined') {
  1109. throw new Error('global not found: ' + name);
  1110. }
  1111. return this.globals[name];
  1112. };
  1113. _proto.addFilter = function addFilter(name, func, async) {
  1114. var wrapped = func;
  1115. if (async) {
  1116. this.asyncFilters.push(name);
  1117. }
  1118. this.filters[name] = wrapped;
  1119. return this;
  1120. };
  1121. _proto.getFilter = function getFilter(name) {
  1122. if (!this.filters[name]) {
  1123. throw new Error('filter not found: ' + name);
  1124. }
  1125. return this.filters[name];
  1126. };
  1127. _proto.addTest = function addTest(name, func) {
  1128. this.tests[name] = func;
  1129. return this;
  1130. };
  1131. _proto.getTest = function getTest(name) {
  1132. if (!this.tests[name]) {
  1133. throw new Error('test not found: ' + name);
  1134. }
  1135. return this.tests[name];
  1136. };
  1137. _proto.resolveTemplate = function resolveTemplate(loader, parentName, filename) {
  1138. var isRelative = loader.isRelative && parentName ? loader.isRelative(filename) : false;
  1139. return isRelative && loader.resolve ? loader.resolve(parentName, filename) : filename;
  1140. };
  1141. _proto.getTemplate = function getTemplate(name, eagerCompile, parentName, ignoreMissing, cb) {
  1142. var _this3 = this;
  1143. var that = this;
  1144. var tmpl = null;
  1145. if (name && name.raw) {
  1146. // this fixes autoescape for templates referenced in symbols
  1147. name = name.raw;
  1148. }
  1149. if (lib.isFunction(parentName)) {
  1150. cb = parentName;
  1151. parentName = null;
  1152. eagerCompile = eagerCompile || false;
  1153. }
  1154. if (lib.isFunction(eagerCompile)) {
  1155. cb = eagerCompile;
  1156. eagerCompile = false;
  1157. }
  1158. if (name instanceof Template) {
  1159. tmpl = name;
  1160. } else if (typeof name !== 'string') {
  1161. throw new Error('template names must be a string: ' + name);
  1162. } else {
  1163. for (var i = 0; i < this.loaders.length; i++) {
  1164. var loader = this.loaders[i];
  1165. tmpl = loader.cache[this.resolveTemplate(loader, parentName, name)];
  1166. if (tmpl) {
  1167. break;
  1168. }
  1169. }
  1170. }
  1171. if (tmpl) {
  1172. if (eagerCompile) {
  1173. tmpl.compile();
  1174. }
  1175. if (cb) {
  1176. cb(null, tmpl);
  1177. return undefined;
  1178. } else {
  1179. return tmpl;
  1180. }
  1181. }
  1182. var syncResult;
  1183. var createTemplate = function createTemplate(err, info) {
  1184. if (!info && !err && !ignoreMissing) {
  1185. err = new Error('template not found: ' + name);
  1186. }
  1187. if (err) {
  1188. if (cb) {
  1189. cb(err);
  1190. return;
  1191. } else {
  1192. throw err;
  1193. }
  1194. }
  1195. var newTmpl;
  1196. if (!info) {
  1197. newTmpl = new Template(noopTmplSrc, _this3, '', eagerCompile);
  1198. } else {
  1199. newTmpl = new Template(info.src, _this3, info.path, eagerCompile);
  1200. if (!info.noCache) {
  1201. info.loader.cache[name] = newTmpl;
  1202. }
  1203. }
  1204. if (cb) {
  1205. cb(null, newTmpl);
  1206. } else {
  1207. syncResult = newTmpl;
  1208. }
  1209. };
  1210. lib.asyncIter(this.loaders, function (loader, i, next, done) {
  1211. function handle(err, src) {
  1212. if (err) {
  1213. done(err);
  1214. } else if (src) {
  1215. src.loader = loader;
  1216. done(null, src);
  1217. } else {
  1218. next();
  1219. }
  1220. } // Resolve name relative to parentName
  1221. name = that.resolveTemplate(loader, parentName, name);
  1222. if (loader.async) {
  1223. loader.getSource(name, handle);
  1224. } else {
  1225. handle(null, loader.getSource(name));
  1226. }
  1227. }, createTemplate);
  1228. return syncResult;
  1229. };
  1230. _proto.express = function express(app) {
  1231. return expressApp(this, app);
  1232. };
  1233. _proto.render = function render(name, ctx, cb) {
  1234. if (lib.isFunction(ctx)) {
  1235. cb = ctx;
  1236. ctx = null;
  1237. } // We support a synchronous API to make it easier to migrate
  1238. // existing code to async. This works because if you don't do
  1239. // anything async work, the whole thing is actually run
  1240. // synchronously.
  1241. var syncResult = null;
  1242. this.getTemplate(name, function (err, tmpl) {
  1243. if (err && cb) {
  1244. callbackAsap(cb, err);
  1245. } else if (err) {
  1246. throw err;
  1247. } else {
  1248. syncResult = tmpl.render(ctx, cb);
  1249. }
  1250. });
  1251. return syncResult;
  1252. };
  1253. _proto.renderString = function renderString(src, ctx, opts, cb) {
  1254. if (lib.isFunction(opts)) {
  1255. cb = opts;
  1256. opts = {};
  1257. }
  1258. opts = opts || {};
  1259. var tmpl = new Template(src, this, opts.path);
  1260. return tmpl.render(ctx, cb);
  1261. };
  1262. _proto.waterfall = function waterfall(tasks, callback, forceAsync) {
  1263. return _waterfall(tasks, callback, forceAsync);
  1264. };
  1265. return Environment;
  1266. }(EmitterObj);
  1267. var Context = /*#__PURE__*/function (_Obj) {
  1268. _inheritsLoose(Context, _Obj);
  1269. function Context() {
  1270. return _Obj.apply(this, arguments) || this;
  1271. }
  1272. var _proto2 = Context.prototype;
  1273. _proto2.init = function init(ctx, blocks, env) {
  1274. var _this4 = this;
  1275. // Has to be tied to an environment so we can tap into its globals.
  1276. this.env = env || new Environment(); // Make a duplicate of ctx
  1277. this.ctx = lib.extend({}, ctx);
  1278. this.blocks = {};
  1279. this.exported = [];
  1280. lib.keys(blocks).forEach(function (name) {
  1281. _this4.addBlock(name, blocks[name]);
  1282. });
  1283. };
  1284. _proto2.lookup = function lookup(name) {
  1285. // This is one of the most called functions, so optimize for
  1286. // the typical case where the name isn't in the globals
  1287. if (name in this.env.globals && !(name in this.ctx)) {
  1288. return this.env.globals[name];
  1289. } else {
  1290. return this.ctx[name];
  1291. }
  1292. };
  1293. _proto2.setVariable = function setVariable(name, val) {
  1294. this.ctx[name] = val;
  1295. };
  1296. _proto2.getVariables = function getVariables() {
  1297. return this.ctx;
  1298. };
  1299. _proto2.addBlock = function addBlock(name, block) {
  1300. this.blocks[name] = this.blocks[name] || [];
  1301. this.blocks[name].push(block);
  1302. return this;
  1303. };
  1304. _proto2.getBlock = function getBlock(name) {
  1305. if (!this.blocks[name]) {
  1306. throw new Error('unknown block "' + name + '"');
  1307. }
  1308. return this.blocks[name][0];
  1309. };
  1310. _proto2.getSuper = function getSuper(env, name, block, frame, runtime, cb) {
  1311. var idx = lib.indexOf(this.blocks[name] || [], block);
  1312. var blk = this.blocks[name][idx + 1];
  1313. var context = this;
  1314. if (idx === -1 || !blk) {
  1315. throw new Error('no super block available for "' + name + '"');
  1316. }
  1317. blk(env, context, frame, runtime, cb);
  1318. };
  1319. _proto2.addExport = function addExport(name) {
  1320. this.exported.push(name);
  1321. };
  1322. _proto2.getExported = function getExported() {
  1323. var _this5 = this;
  1324. var exported = {};
  1325. this.exported.forEach(function (name) {
  1326. exported[name] = _this5.ctx[name];
  1327. });
  1328. return exported;
  1329. };
  1330. return Context;
  1331. }(Obj);
  1332. var Template = /*#__PURE__*/function (_Obj2) {
  1333. _inheritsLoose(Template, _Obj2);
  1334. function Template() {
  1335. return _Obj2.apply(this, arguments) || this;
  1336. }
  1337. var _proto3 = Template.prototype;
  1338. _proto3.init = function init(src, env, path, eagerCompile) {
  1339. this.env = env || new Environment();
  1340. if (lib.isObject(src)) {
  1341. switch (src.type) {
  1342. case 'code':
  1343. this.tmplProps = src.obj;
  1344. break;
  1345. case 'string':
  1346. this.tmplStr = src.obj;
  1347. break;
  1348. default:
  1349. throw new Error("Unexpected template object type " + src.type + "; expected 'code', or 'string'");
  1350. }
  1351. } else if (lib.isString(src)) {
  1352. this.tmplStr = src;
  1353. } else {
  1354. throw new Error('src must be a string or an object describing the source');
  1355. }
  1356. this.path = path;
  1357. if (eagerCompile) {
  1358. try {
  1359. this._compile();
  1360. } catch (err) {
  1361. throw lib._prettifyError(this.path, this.env.opts.dev, err);
  1362. }
  1363. } else {
  1364. this.compiled = false;
  1365. }
  1366. };
  1367. _proto3.render = function render(ctx, parentFrame, cb) {
  1368. var _this6 = this;
  1369. if (typeof ctx === 'function') {
  1370. cb = ctx;
  1371. ctx = {};
  1372. } else if (typeof parentFrame === 'function') {
  1373. cb = parentFrame;
  1374. parentFrame = null;
  1375. } // If there is a parent frame, we are being called from internal
  1376. // code of another template, and the internal system
  1377. // depends on the sync/async nature of the parent template
  1378. // to be inherited, so force an async callback
  1379. var forceAsync = !parentFrame; // Catch compile errors for async rendering
  1380. try {
  1381. this.compile();
  1382. } catch (e) {
  1383. var err = lib._prettifyError(this.path, this.env.opts.dev, e);
  1384. if (cb) {
  1385. return callbackAsap(cb, err);
  1386. } else {
  1387. throw err;
  1388. }
  1389. }
  1390. var context = new Context(ctx || {}, this.blocks, this.env);
  1391. var frame = parentFrame ? parentFrame.push(true) : new Frame();
  1392. frame.topLevel = true;
  1393. var syncResult = null;
  1394. var didError = false;
  1395. this.rootRenderFunc(this.env, context, frame, globalRuntime, function (err, res) {
  1396. // TODO: this is actually a bug in the compiled template (because waterfall
  1397. // tasks are both not passing errors up the chain of callbacks AND are not
  1398. // causing a return from the top-most render function). But fixing that
  1399. // will require a more substantial change to the compiler.
  1400. if (didError && cb && typeof res !== 'undefined') {
  1401. // prevent multiple calls to cb
  1402. return;
  1403. }
  1404. if (err) {
  1405. err = lib._prettifyError(_this6.path, _this6.env.opts.dev, err);
  1406. didError = true;
  1407. }
  1408. if (cb) {
  1409. if (forceAsync) {
  1410. callbackAsap(cb, err, res);
  1411. } else {
  1412. cb(err, res);
  1413. }
  1414. } else {
  1415. if (err) {
  1416. throw err;
  1417. }
  1418. syncResult = res;
  1419. }
  1420. });
  1421. return syncResult;
  1422. };
  1423. _proto3.getExported = function getExported(ctx, parentFrame, cb) {
  1424. // eslint-disable-line consistent-return
  1425. if (typeof ctx === 'function') {
  1426. cb = ctx;
  1427. ctx = {};
  1428. }
  1429. if (typeof parentFrame === 'function') {
  1430. cb = parentFrame;
  1431. parentFrame = null;
  1432. } // Catch compile errors for async rendering
  1433. try {
  1434. this.compile();
  1435. } catch (e) {
  1436. if (cb) {
  1437. return cb(e);
  1438. } else {
  1439. throw e;
  1440. }
  1441. }
  1442. var frame = parentFrame ? parentFrame.push() : new Frame();
  1443. frame.topLevel = true; // Run the rootRenderFunc to populate the context with exported vars
  1444. var context = new Context(ctx || {}, this.blocks, this.env);
  1445. this.rootRenderFunc(this.env, context, frame, globalRuntime, function (err) {
  1446. if (err) {
  1447. cb(err, null);
  1448. } else {
  1449. cb(null, context.getExported());
  1450. }
  1451. });
  1452. };
  1453. _proto3.compile = function compile() {
  1454. if (!this.compiled) {
  1455. this._compile();
  1456. }
  1457. };
  1458. _proto3._compile = function _compile() {
  1459. var props;
  1460. if (this.tmplProps) {
  1461. props = this.tmplProps;
  1462. } else {
  1463. var source = compiler.compile(this.tmplStr, this.env.asyncFilters, this.env.extensionsList, this.path, this.env.opts);
  1464. var func = new Function(source); // eslint-disable-line no-new-func
  1465. props = func();
  1466. }
  1467. this.blocks = this._getBlocks(props);
  1468. this.rootRenderFunc = props.root;
  1469. this.compiled = true;
  1470. };
  1471. _proto3._getBlocks = function _getBlocks(props) {
  1472. var blocks = {};
  1473. lib.keys(props).forEach(function (k) {
  1474. if (k.slice(0, 2) === 'b_') {
  1475. blocks[k.slice(2)] = props[k];
  1476. }
  1477. });
  1478. return blocks;
  1479. };
  1480. return Template;
  1481. }(Obj);
  1482. module.exports = {
  1483. Environment: Environment,
  1484. Template: Template
  1485. };
  1486. /***/ }),
  1487. /* 8 */
  1488. /***/ (function(module, exports, __webpack_require__) {
  1489. "use strict";
  1490. // rawAsap provides everything we need except exception management.
  1491. var rawAsap = __webpack_require__(9);
  1492. // RawTasks are recycled to reduce GC churn.
  1493. var freeTasks = [];
  1494. // We queue errors to ensure they are thrown in right order (FIFO).
  1495. // Array-as-queue is good enough here, since we are just dealing with exceptions.
  1496. var pendingErrors = [];
  1497. var requestErrorThrow = rawAsap.makeRequestCallFromTimer(throwFirstError);
  1498. function throwFirstError() {
  1499. if (pendingErrors.length) {
  1500. throw pendingErrors.shift();
  1501. }
  1502. }
  1503. /**
  1504. * Calls a task as soon as possible after returning, in its own event, with priority
  1505. * over other events like animation, reflow, and repaint. An error thrown from an
  1506. * event will not interrupt, nor even substantially slow down the processing of
  1507. * other events, but will be rather postponed to a lower priority event.
  1508. * @param {{call}} task A callable object, typically a function that takes no
  1509. * arguments.
  1510. */
  1511. module.exports = asap;
  1512. function asap(task) {
  1513. var rawTask;
  1514. if (freeTasks.length) {
  1515. rawTask = freeTasks.pop();
  1516. } else {
  1517. rawTask = new RawTask();
  1518. }
  1519. rawTask.task = task;
  1520. rawAsap(rawTask);
  1521. }
  1522. // We wrap tasks with recyclable task objects. A task object implements
  1523. // `call`, just like a function.
  1524. function RawTask() {
  1525. this.task = null;
  1526. }
  1527. // The sole purpose of wrapping the task is to catch the exception and recycle
  1528. // the task object after its single use.
  1529. RawTask.prototype.call = function () {
  1530. try {
  1531. this.task.call();
  1532. } catch (error) {
  1533. if (asap.onerror) {
  1534. // This hook exists purely for testing purposes.
  1535. // Its name will be periodically randomized to break any code that
  1536. // depends on its existence.
  1537. asap.onerror(error);
  1538. } else {
  1539. // In a web browser, exceptions are not fatal. However, to avoid
  1540. // slowing down the queue of pending tasks, we rethrow the error in a
  1541. // lower priority turn.
  1542. pendingErrors.push(error);
  1543. requestErrorThrow();
  1544. }
  1545. } finally {
  1546. this.task = null;
  1547. freeTasks[freeTasks.length] = this;
  1548. }
  1549. };
  1550. /***/ }),
  1551. /* 9 */
  1552. /***/ (function(module, exports, __webpack_require__) {
  1553. "use strict";
  1554. /* WEBPACK VAR INJECTION */(function(global) {
  1555. // Use the fastest means possible to execute a task in its own turn, with
  1556. // priority over other events including IO, animation, reflow, and redraw
  1557. // events in browsers.
  1558. //
  1559. // An exception thrown by a task will permanently interrupt the processing of
  1560. // subsequent tasks. The higher level `asap` function ensures that if an
  1561. // exception is thrown by a task, that the task queue will continue flushing as
  1562. // soon as possible, but if you use `rawAsap` directly, you are responsible to
  1563. // either ensure that no exceptions are thrown from your task, or to manually
  1564. // call `rawAsap.requestFlush` if an exception is thrown.
  1565. module.exports = rawAsap;
  1566. function rawAsap(task) {
  1567. if (!queue.length) {
  1568. requestFlush();
  1569. flushing = true;
  1570. }
  1571. // Equivalent to push, but avoids a function call.
  1572. queue[queue.length] = task;
  1573. }
  1574. var queue = [];
  1575. // Once a flush has been requested, no further calls to `requestFlush` are
  1576. // necessary until the next `flush` completes.
  1577. var flushing = false;
  1578. // `requestFlush` is an implementation-specific method that attempts to kick
  1579. // off a `flush` event as quickly as possible. `flush` will attempt to exhaust
  1580. // the event queue before yielding to the browser's own event loop.
  1581. var requestFlush;
  1582. // The position of the next task to execute in the task queue. This is
  1583. // preserved between calls to `flush` so that it can be resumed if
  1584. // a task throws an exception.
  1585. var index = 0;
  1586. // If a task schedules additional tasks recursively, the task queue can grow
  1587. // unbounded. To prevent memory exhaustion, the task queue will periodically
  1588. // truncate already-completed tasks.
  1589. var capacity = 1024;
  1590. // The flush function processes all tasks that have been scheduled with
  1591. // `rawAsap` unless and until one of those tasks throws an exception.
  1592. // If a task throws an exception, `flush` ensures that its state will remain
  1593. // consistent and will resume where it left off when called again.
  1594. // However, `flush` does not make any arrangements to be called again if an
  1595. // exception is thrown.
  1596. function flush() {
  1597. while (index < queue.length) {
  1598. var currentIndex = index;
  1599. // Advance the index before calling the task. This ensures that we will
  1600. // begin flushing on the next task the task throws an error.
  1601. index = index + 1;
  1602. queue[currentIndex].call();
  1603. // Prevent leaking memory for long chains of recursive calls to `asap`.
  1604. // If we call `asap` within tasks scheduled by `asap`, the queue will
  1605. // grow, but to avoid an O(n) walk for every task we execute, we don't
  1606. // shift tasks off the queue after they have been executed.
  1607. // Instead, we periodically shift 1024 tasks off the queue.
  1608. if (index > capacity) {
  1609. // Manually shift all values starting at the index back to the
  1610. // beginning of the queue.
  1611. for (var scan = 0, newLength = queue.length - index; scan < newLength; scan++) {
  1612. queue[scan] = queue[scan + index];
  1613. }
  1614. queue.length -= index;
  1615. index = 0;
  1616. }
  1617. }
  1618. queue.length = 0;
  1619. index = 0;
  1620. flushing = false;
  1621. }
  1622. // `requestFlush` is implemented using a strategy based on data collected from
  1623. // every available SauceLabs Selenium web driver worker at time of writing.
  1624. // https://docs.google.com/spreadsheets/d/1mG-5UYGup5qxGdEMWkhP6BWCz053NUb2E1QoUTU16uA/edit#gid=783724593
  1625. // Safari 6 and 6.1 for desktop, iPad, and iPhone are the only browsers that
  1626. // have WebKitMutationObserver but not un-prefixed MutationObserver.
  1627. // Must use `global` or `self` instead of `window` to work in both frames and web
  1628. // workers. `global` is a provision of Browserify, Mr, Mrs, or Mop.
  1629. /* globals self */
  1630. var scope = typeof global !== "undefined" ? global : self;
  1631. var BrowserMutationObserver = scope.MutationObserver || scope.WebKitMutationObserver;
  1632. // MutationObservers are desirable because they have high priority and work
  1633. // reliably everywhere they are implemented.
  1634. // They are implemented in all modern browsers.
  1635. //
  1636. // - Android 4-4.3
  1637. // - Chrome 26-34
  1638. // - Firefox 14-29
  1639. // - Internet Explorer 11
  1640. // - iPad Safari 6-7.1
  1641. // - iPhone Safari 7-7.1
  1642. // - Safari 6-7
  1643. if (typeof BrowserMutationObserver === "function") {
  1644. requestFlush = makeRequestCallFromMutationObserver(flush);
  1645. // MessageChannels are desirable because they give direct access to the HTML
  1646. // task queue, are implemented in Internet Explorer 10, Safari 5.0-1, and Opera
  1647. // 11-12, and in web workers in many engines.
  1648. // Although message channels yield to any queued rendering and IO tasks, they
  1649. // would be better than imposing the 4ms delay of timers.
  1650. // However, they do not work reliably in Internet Explorer or Safari.
  1651. // Internet Explorer 10 is the only browser that has setImmediate but does
  1652. // not have MutationObservers.
  1653. // Although setImmediate yields to the browser's renderer, it would be
  1654. // preferrable to falling back to setTimeout since it does not have
  1655. // the minimum 4ms penalty.
  1656. // Unfortunately there appears to be a bug in Internet Explorer 10 Mobile (and
  1657. // Desktop to a lesser extent) that renders both setImmediate and
  1658. // MessageChannel useless for the purposes of ASAP.
  1659. // https://github.com/kriskowal/q/issues/396
  1660. // Timers are implemented universally.
  1661. // We fall back to timers in workers in most engines, and in foreground
  1662. // contexts in the following browsers.
  1663. // However, note that even this simple case requires nuances to operate in a
  1664. // broad spectrum of browsers.
  1665. //
  1666. // - Firefox 3-13
  1667. // - Internet Explorer 6-9
  1668. // - iPad Safari 4.3
  1669. // - Lynx 2.8.7
  1670. } else {
  1671. requestFlush = makeRequestCallFromTimer(flush);
  1672. }
  1673. // `requestFlush` requests that the high priority event queue be flushed as
  1674. // soon as possible.
  1675. // This is useful to prevent an error thrown in a task from stalling the event
  1676. // queue if the exception handled by Node.js’s
  1677. // `process.on("uncaughtException")` or by a domain.
  1678. rawAsap.requestFlush = requestFlush;
  1679. // To request a high priority event, we induce a mutation observer by toggling
  1680. // the text of a text node between "1" and "-1".
  1681. function makeRequestCallFromMutationObserver(callback) {
  1682. var toggle = 1;
  1683. var observer = new BrowserMutationObserver(callback);
  1684. var node = document.createTextNode("");
  1685. observer.observe(node, {characterData: true});
  1686. return function requestCall() {
  1687. toggle = -toggle;
  1688. node.data = toggle;
  1689. };
  1690. }
  1691. // The message channel technique was discovered by Malte Ubl and was the
  1692. // original foundation for this library.
  1693. // http://www.nonblocking.io/2011/06/windownexttick.html
  1694. // Safari 6.0.5 (at least) intermittently fails to create message ports on a
  1695. // page's first load. Thankfully, this version of Safari supports
  1696. // MutationObservers, so we don't need to fall back in that case.
  1697. // function makeRequestCallFromMessageChannel(callback) {
  1698. // var channel = new MessageChannel();
  1699. // channel.port1.onmessage = callback;
  1700. // return function requestCall() {
  1701. // channel.port2.postMessage(0);
  1702. // };
  1703. // }
  1704. // For reasons explained above, we are also unable to use `setImmediate`
  1705. // under any circumstances.
  1706. // Even if we were, there is another bug in Internet Explorer 10.
  1707. // It is not sufficient to assign `setImmediate` to `requestFlush` because
  1708. // `setImmediate` must be called *by name* and therefore must be wrapped in a
  1709. // closure.
  1710. // Never forget.
  1711. // function makeRequestCallFromSetImmediate(callback) {
  1712. // return function requestCall() {
  1713. // setImmediate(callback);
  1714. // };
  1715. // }
  1716. // Safari 6.0 has a problem where timers will get lost while the user is
  1717. // scrolling. This problem does not impact ASAP because Safari 6.0 supports
  1718. // mutation observers, so that implementation is used instead.
  1719. // However, if we ever elect to use timers in Safari, the prevalent work-around
  1720. // is to add a scroll event listener that calls for a flush.
  1721. // `setTimeout` does not call the passed callback if the delay is less than
  1722. // approximately 7 in web workers in Firefox 8 through 18, and sometimes not
  1723. // even then.
  1724. function makeRequestCallFromTimer(callback) {
  1725. return function requestCall() {
  1726. // We dispatch a timeout with a specified delay of 0 for engines that
  1727. // can reliably accommodate that request. This will usually be snapped
  1728. // to a 4 milisecond delay, but once we're flushing, there's no delay
  1729. // between events.
  1730. var timeoutHandle = setTimeout(handleTimer, 0);
  1731. // However, since this timer gets frequently dropped in Firefox
  1732. // workers, we enlist an interval handle that will try to fire
  1733. // an event 20 times per second until it succeeds.
  1734. var intervalHandle = setInterval(handleTimer, 50);
  1735. function handleTimer() {
  1736. // Whichever timer succeeds will cancel both timers and
  1737. // execute the callback.
  1738. clearTimeout(timeoutHandle);
  1739. clearInterval(intervalHandle);
  1740. callback();
  1741. }
  1742. };
  1743. }
  1744. // This is for `asap.js` only.
  1745. // Its name will be periodically randomized to break any code that depends on
  1746. // its existence.
  1747. rawAsap.makeRequestCallFromTimer = makeRequestCallFromTimer;
  1748. // ASAP was originally a nextTick shim included in Q. This was factored out
  1749. // into this ASAP package. It was later adapted to RSVP which made further
  1750. // amendments. These decisions, particularly to marginalize MessageChannel and
  1751. // to capture the MutationObserver implementation in a closure, were integrated
  1752. // back into ASAP proper.
  1753. // https://github.com/tildeio/rsvp.js/blob/cddf7232546a9cf858524b75cde6f9edf72620a7/lib/rsvp/asap.js
  1754. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(10)))
  1755. /***/ }),
  1756. /* 10 */
  1757. /***/ (function(module, exports) {
  1758. var g;
  1759. // This works in non-strict mode
  1760. g = (function() {
  1761. return this;
  1762. })();
  1763. try {
  1764. // This works if eval is allowed (see CSP)
  1765. g = g || Function("return this")() || (1,eval)("this");
  1766. } catch(e) {
  1767. // This works if the window reference is available
  1768. if(typeof window === "object")
  1769. g = window;
  1770. }
  1771. // g can still be undefined, but nothing to do about it...
  1772. // We return undefined, instead of nothing here, so it's
  1773. // easier to handle this case. if(!global) { ...}
  1774. module.exports = g;
  1775. /***/ }),
  1776. /* 11 */
  1777. /***/ (function(module, exports, __webpack_require__) {
  1778. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// MIT license (by Elan Shanker).
  1779. (function(globals) {
  1780. 'use strict';
  1781. var executeSync = function(){
  1782. var args = Array.prototype.slice.call(arguments);
  1783. if (typeof args[0] === 'function'){
  1784. args[0].apply(null, args.splice(1));
  1785. }
  1786. };
  1787. var executeAsync = function(fn){
  1788. if (typeof setImmediate === 'function') {
  1789. setImmediate(fn);
  1790. } else if (typeof process !== 'undefined' && process.nextTick) {
  1791. process.nextTick(fn);
  1792. } else {
  1793. setTimeout(fn, 0);
  1794. }
  1795. };
  1796. var makeIterator = function (tasks) {
  1797. var makeCallback = function (index) {
  1798. var fn = function () {
  1799. if (tasks.length) {
  1800. tasks[index].apply(null, arguments);
  1801. }
  1802. return fn.next();
  1803. };
  1804. fn.next = function () {
  1805. return (index < tasks.length - 1) ? makeCallback(index + 1): null;
  1806. };
  1807. return fn;
  1808. };
  1809. return makeCallback(0);
  1810. };
  1811. var _isArray = Array.isArray || function(maybeArray){
  1812. return Object.prototype.toString.call(maybeArray) === '[object Array]';
  1813. };
  1814. var waterfall = function (tasks, callback, forceAsync) {
  1815. var nextTick = forceAsync ? executeAsync : executeSync;
  1816. callback = callback || function () {};
  1817. if (!_isArray(tasks)) {
  1818. var err = new Error('First argument to waterfall must be an array of functions');
  1819. return callback(err);
  1820. }
  1821. if (!tasks.length) {
  1822. return callback();
  1823. }
  1824. var wrapIterator = function (iterator) {
  1825. return function (err) {
  1826. if (err) {
  1827. callback.apply(null, arguments);
  1828. callback = function () {};
  1829. } else {
  1830. var args = Array.prototype.slice.call(arguments, 1);
  1831. var next = iterator.next();
  1832. if (next) {
  1833. args.push(wrapIterator(next));
  1834. } else {
  1835. args.push(callback);
  1836. }
  1837. nextTick(function () {
  1838. iterator.apply(null, args);
  1839. });
  1840. }
  1841. };
  1842. };
  1843. wrapIterator(makeIterator(tasks))();
  1844. };
  1845. if (true) {
  1846. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () {
  1847. return waterfall;
  1848. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  1849. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); // RequireJS
  1850. } else if (typeof module !== 'undefined' && module.exports) {
  1851. module.exports = waterfall; // CommonJS
  1852. } else {
  1853. globals.waterfall = waterfall; // <script>
  1854. }
  1855. })(this);
  1856. /***/ }),
  1857. /* 12 */
  1858. /***/ (function(module, exports, __webpack_require__) {
  1859. "use strict";
  1860. var lib = __webpack_require__(1);
  1861. var r = __webpack_require__(2);
  1862. var exports = module.exports = {};
  1863. function normalize(value, defaultValue) {
  1864. if (value === null || value === undefined || value === false) {
  1865. return defaultValue;
  1866. }
  1867. return value;
  1868. }
  1869. exports.abs = Math.abs;
  1870. function isNaN(num) {
  1871. return num !== num; // eslint-disable-line no-self-compare
  1872. }
  1873. function batch(arr, linecount, fillWith) {
  1874. var i;
  1875. var res = [];
  1876. var tmp = [];
  1877. for (i = 0; i < arr.length; i++) {
  1878. if (i % linecount === 0 && tmp.length) {
  1879. res.push(tmp);
  1880. tmp = [];
  1881. }
  1882. tmp.push(arr[i]);
  1883. }
  1884. if (tmp.length) {
  1885. if (fillWith) {
  1886. for (i = tmp.length; i < linecount; i++) {
  1887. tmp.push(fillWith);
  1888. }
  1889. }
  1890. res.push(tmp);
  1891. }
  1892. return res;
  1893. }
  1894. exports.batch = batch;
  1895. function capitalize(str) {
  1896. str = normalize(str, '');
  1897. var ret = str.toLowerCase();
  1898. return r.copySafeness(str, ret.charAt(0).toUpperCase() + ret.slice(1));
  1899. }
  1900. exports.capitalize = capitalize;
  1901. function center(str, width) {
  1902. str = normalize(str, '');
  1903. width = width || 80;
  1904. if (str.length >= width) {
  1905. return str;
  1906. }
  1907. var spaces = width - str.length;
  1908. var pre = lib.repeat(' ', spaces / 2 - spaces % 2);
  1909. var post = lib.repeat(' ', spaces / 2);
  1910. return r.copySafeness(str, pre + str + post);
  1911. }
  1912. exports.center = center;
  1913. function default_(val, def, bool) {
  1914. if (bool) {
  1915. return val || def;
  1916. } else {
  1917. return val !== undefined ? val : def;
  1918. }
  1919. } // TODO: it is confusing to export something called 'default'
  1920. exports['default'] = default_; // eslint-disable-line dot-notation
  1921. function dictsort(val, caseSensitive, by) {
  1922. if (!lib.isObject(val)) {
  1923. throw new lib.TemplateError('dictsort filter: val must be an object');
  1924. }
  1925. var array = []; // deliberately include properties from the object's prototype
  1926. for (var k in val) {
  1927. // eslint-disable-line guard-for-in, no-restricted-syntax
  1928. array.push([k, val[k]]);
  1929. }
  1930. var si;
  1931. if (by === undefined || by === 'key') {
  1932. si = 0;
  1933. } else if (by === 'value') {
  1934. si = 1;
  1935. } else {
  1936. throw new lib.TemplateError('dictsort filter: You can only sort by either key or value');
  1937. }
  1938. array.sort(function (t1, t2) {
  1939. var a = t1[si];
  1940. var b = t2[si];
  1941. if (!caseSensitive) {
  1942. if (lib.isString(a)) {
  1943. a = a.toUpperCase();
  1944. }
  1945. if (lib.isString(b)) {
  1946. b = b.toUpperCase();
  1947. }
  1948. }
  1949. return a > b ? 1 : a === b ? 0 : -1; // eslint-disable-line no-nested-ternary
  1950. });
  1951. return array;
  1952. }
  1953. exports.dictsort = dictsort;
  1954. function dump(obj, spaces) {
  1955. return JSON.stringify(obj, null, spaces);
  1956. }
  1957. exports.dump = dump;
  1958. function escape(str) {
  1959. if (str instanceof r.SafeString) {
  1960. return str;
  1961. }
  1962. str = str === null || str === undefined ? '' : str;
  1963. return r.markSafe(lib.escape(str.toString()));
  1964. }
  1965. exports.escape = escape;
  1966. function safe(str) {
  1967. if (str instanceof r.SafeString) {
  1968. return str;
  1969. }
  1970. str = str === null || str === undefined ? '' : str;
  1971. return r.markSafe(str.toString());
  1972. }
  1973. exports.safe = safe;
  1974. function first(arr) {
  1975. return arr[0];
  1976. }
  1977. exports.first = first;
  1978. function forceescape(str) {
  1979. str = str === null || str === undefined ? '' : str;
  1980. return r.markSafe(lib.escape(str.toString()));
  1981. }
  1982. exports.forceescape = forceescape;
  1983. function groupby(arr, attr) {
  1984. return lib.groupBy(arr, attr, this.env.opts.throwOnUndefined);
  1985. }
  1986. exports.groupby = groupby;
  1987. function indent(str, width, indentfirst) {
  1988. str = normalize(str, '');
  1989. if (str === '') {
  1990. return '';
  1991. }
  1992. width = width || 4; // let res = '';
  1993. var lines = str.split('\n');
  1994. var sp = lib.repeat(' ', width);
  1995. var res = lines.map(function (l, i) {
  1996. return i === 0 && !indentfirst ? l : "" + sp + l;
  1997. }).join('\n');
  1998. return r.copySafeness(str, res);
  1999. }
  2000. exports.indent = indent;
  2001. function join(arr, del, attr) {
  2002. del = del || '';
  2003. if (attr) {
  2004. arr = lib.map(arr, function (v) {
  2005. return v[attr];
  2006. });
  2007. }
  2008. return arr.join(del);
  2009. }
  2010. exports.join = join;
  2011. function last(arr) {
  2012. return arr[arr.length - 1];
  2013. }
  2014. exports.last = last;
  2015. function lengthFilter(val) {
  2016. var value = normalize(val, '');
  2017. if (value !== undefined) {
  2018. if (typeof Map === 'function' && value instanceof Map || typeof Set === 'function' && value instanceof Set) {
  2019. // ECMAScript 2015 Maps and Sets
  2020. return value.size;
  2021. }
  2022. if (lib.isObject(value) && !(value instanceof r.SafeString)) {
  2023. // Objects (besides SafeStrings), non-primative Arrays
  2024. return lib.keys(value).length;
  2025. }
  2026. return value.length;
  2027. }
  2028. return 0;
  2029. }
  2030. exports.length = lengthFilter;
  2031. function list(val) {
  2032. if (lib.isString(val)) {
  2033. return val.split('');
  2034. } else if (lib.isObject(val)) {
  2035. return lib._entries(val || {}).map(function (_ref) {
  2036. var key = _ref[0],
  2037. value = _ref[1];
  2038. return {
  2039. key: key,
  2040. value: value
  2041. };
  2042. });
  2043. } else if (lib.isArray(val)) {
  2044. return val;
  2045. } else {
  2046. throw new lib.TemplateError('list filter: type not iterable');
  2047. }
  2048. }
  2049. exports.list = list;
  2050. function lower(str) {
  2051. str = normalize(str, '');
  2052. return str.toLowerCase();
  2053. }
  2054. exports.lower = lower;
  2055. function nl2br(str) {
  2056. if (str === null || str === undefined) {
  2057. return '';
  2058. }
  2059. return r.copySafeness(str, str.replace(/\r\n|\n/g, '<br />\n'));
  2060. }
  2061. exports.nl2br = nl2br;
  2062. function random(arr) {
  2063. return arr[Math.floor(Math.random() * arr.length)];
  2064. }
  2065. exports.random = random;
  2066. /**
  2067. * Construct select or reject filter
  2068. *
  2069. * @param {boolean} expectedTestResult
  2070. * @returns {function(array, string, *): array}
  2071. */
  2072. function getSelectOrReject(expectedTestResult) {
  2073. function filter(arr, testName, secondArg) {
  2074. if (testName === void 0) {
  2075. testName = 'truthy';
  2076. }
  2077. var context = this;
  2078. var test = context.env.getTest(testName);
  2079. return lib.toArray(arr).filter(function examineTestResult(item) {
  2080. return test.call(context, item, secondArg) === expectedTestResult;
  2081. });
  2082. }
  2083. return filter;
  2084. }
  2085. exports.reject = getSelectOrReject(false);
  2086. function rejectattr(arr, attr) {
  2087. return arr.filter(function (item) {
  2088. return !item[attr];
  2089. });
  2090. }
  2091. exports.rejectattr = rejectattr;
  2092. exports.select = getSelectOrReject(true);
  2093. function selectattr(arr, attr) {
  2094. return arr.filter(function (item) {
  2095. return !!item[attr];
  2096. });
  2097. }
  2098. exports.selectattr = selectattr;
  2099. function replace(str, old, new_, maxCount) {
  2100. var originalStr = str;
  2101. if (old instanceof RegExp) {
  2102. return str.replace(old, new_);
  2103. }
  2104. if (typeof maxCount === 'undefined') {
  2105. maxCount = -1;
  2106. }
  2107. var res = ''; // Output
  2108. // Cast Numbers in the search term to string
  2109. if (typeof old === 'number') {
  2110. old = '' + old;
  2111. } else if (typeof old !== 'string') {
  2112. // If it is something other than number or string,
  2113. // return the original string
  2114. return str;
  2115. } // Cast numbers in the replacement to string
  2116. if (typeof str === 'number') {
  2117. str = '' + str;
  2118. } // If by now, we don't have a string, throw it back
  2119. if (typeof str !== 'string' && !(str instanceof r.SafeString)) {
  2120. return str;
  2121. } // ShortCircuits
  2122. if (old === '') {
  2123. // Mimic the python behaviour: empty string is replaced
  2124. // by replacement e.g. "abc"|replace("", ".") -> .a.b.c.
  2125. res = new_ + str.split('').join(new_) + new_;
  2126. return r.copySafeness(str, res);
  2127. }
  2128. var nextIndex = str.indexOf(old); // if # of replacements to perform is 0, or the string to does
  2129. // not contain the old value, return the string
  2130. if (maxCount === 0 || nextIndex === -1) {
  2131. return str;
  2132. }
  2133. var pos = 0;
  2134. var count = 0; // # of replacements made
  2135. while (nextIndex > -1 && (maxCount === -1 || count < maxCount)) {
  2136. // Grab the next chunk of src string and add it with the
  2137. // replacement, to the result
  2138. res += str.substring(pos, nextIndex) + new_; // Increment our pointer in the src string
  2139. pos = nextIndex + old.length;
  2140. count++; // See if there are any more replacements to be made
  2141. nextIndex = str.indexOf(old, pos);
  2142. } // We've either reached the end, or done the max # of
  2143. // replacements, tack on any remaining string
  2144. if (pos < str.length) {
  2145. res += str.substring(pos);
  2146. }
  2147. return r.copySafeness(originalStr, res);
  2148. }
  2149. exports.replace = replace;
  2150. function reverse(val) {
  2151. var arr;
  2152. if (lib.isString(val)) {
  2153. arr = list(val);
  2154. } else {
  2155. // Copy it
  2156. arr = lib.map(val, function (v) {
  2157. return v;
  2158. });
  2159. }
  2160. arr.reverse();
  2161. if (lib.isString(val)) {
  2162. return r.copySafeness(val, arr.join(''));
  2163. }
  2164. return arr;
  2165. }
  2166. exports.reverse = reverse;
  2167. function round(val, precision, method) {
  2168. precision = precision || 0;
  2169. var factor = Math.pow(10, precision);
  2170. var rounder;
  2171. if (method === 'ceil') {
  2172. rounder = Math.ceil;
  2173. } else if (method === 'floor') {
  2174. rounder = Math.floor;
  2175. } else {
  2176. rounder = Math.round;
  2177. }
  2178. return rounder(val * factor) / factor;
  2179. }
  2180. exports.round = round;
  2181. function slice(arr, slices, fillWith) {
  2182. var sliceLength = Math.floor(arr.length / slices);
  2183. var extra = arr.length % slices;
  2184. var res = [];
  2185. var offset = 0;
  2186. for (var i = 0; i < slices; i++) {
  2187. var start = offset + i * sliceLength;
  2188. if (i < extra) {
  2189. offset++;
  2190. }
  2191. var end = offset + (i + 1) * sliceLength;
  2192. var currSlice = arr.slice(start, end);
  2193. if (fillWith && i >= extra) {
  2194. currSlice.push(fillWith);
  2195. }
  2196. res.push(currSlice);
  2197. }
  2198. return res;
  2199. }
  2200. exports.slice = slice;
  2201. function sum(arr, attr, start) {
  2202. if (start === void 0) {
  2203. start = 0;
  2204. }
  2205. if (attr) {
  2206. arr = lib.map(arr, function (v) {
  2207. return v[attr];
  2208. });
  2209. }
  2210. return start + arr.reduce(function (a, b) {
  2211. return a + b;
  2212. }, 0);
  2213. }
  2214. exports.sum = sum;
  2215. exports.sort = r.makeMacro(['value', 'reverse', 'case_sensitive', 'attribute'], [], function sortFilter(arr, reversed, caseSens, attr) {
  2216. var _this = this;
  2217. // Copy it
  2218. var array = lib.map(arr, function (v) {
  2219. return v;
  2220. });
  2221. var getAttribute = lib.getAttrGetter(attr);
  2222. array.sort(function (a, b) {
  2223. var x = attr ? getAttribute(a) : a;
  2224. var y = attr ? getAttribute(b) : b;
  2225. if (_this.env.opts.throwOnUndefined && attr && (x === undefined || y === undefined)) {
  2226. throw new TypeError("sort: attribute \"" + attr + "\" resolved to undefined");
  2227. }
  2228. if (!caseSens && lib.isString(x) && lib.isString(y)) {
  2229. x = x.toLowerCase();
  2230. y = y.toLowerCase();
  2231. }
  2232. if (x < y) {
  2233. return reversed ? 1 : -1;
  2234. } else if (x > y) {
  2235. return reversed ? -1 : 1;
  2236. } else {
  2237. return 0;
  2238. }
  2239. });
  2240. return array;
  2241. });
  2242. function string(obj) {
  2243. return r.copySafeness(obj, obj);
  2244. }
  2245. exports.string = string;
  2246. function striptags(input, preserveLinebreaks) {
  2247. input = normalize(input, '');
  2248. var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>|<!--[\s\S]*?-->/gi;
  2249. var trimmedInput = trim(input.replace(tags, ''));
  2250. var res = '';
  2251. if (preserveLinebreaks) {
  2252. res = trimmedInput.replace(/^ +| +$/gm, '') // remove leading and trailing spaces
  2253. .replace(/ +/g, ' ') // squash adjacent spaces
  2254. .replace(/(\r\n)/g, '\n') // normalize linebreaks (CRLF -> LF)
  2255. .replace(/\n\n\n+/g, '\n\n'); // squash abnormal adjacent linebreaks
  2256. } else {
  2257. res = trimmedInput.replace(/\s+/gi, ' ');
  2258. }
  2259. return r.copySafeness(input, res);
  2260. }
  2261. exports.striptags = striptags;
  2262. function title(str) {
  2263. str = normalize(str, '');
  2264. var words = str.split(' ').map(function (word) {
  2265. return capitalize(word);
  2266. });
  2267. return r.copySafeness(str, words.join(' '));
  2268. }
  2269. exports.title = title;
  2270. function trim(str) {
  2271. return r.copySafeness(str, str.replace(/^\s*|\s*$/g, ''));
  2272. }
  2273. exports.trim = trim;
  2274. function truncate(input, length, killwords, end) {
  2275. var orig = input;
  2276. input = normalize(input, '');
  2277. length = length || 255;
  2278. if (input.length <= length) {
  2279. return input;
  2280. }
  2281. if (killwords) {
  2282. input = input.substring(0, length);
  2283. } else {
  2284. var idx = input.lastIndexOf(' ', length);
  2285. if (idx === -1) {
  2286. idx = length;
  2287. }
  2288. input = input.substring(0, idx);
  2289. }
  2290. input += end !== undefined && end !== null ? end : '...';
  2291. return r.copySafeness(orig, input);
  2292. }
  2293. exports.truncate = truncate;
  2294. function upper(str) {
  2295. str = normalize(str, '');
  2296. return str.toUpperCase();
  2297. }
  2298. exports.upper = upper;
  2299. function urlencode(obj) {
  2300. var enc = encodeURIComponent;
  2301. if (lib.isString(obj)) {
  2302. return enc(obj);
  2303. } else {
  2304. var keyvals = lib.isArray(obj) ? obj : lib._entries(obj);
  2305. return keyvals.map(function (_ref2) {
  2306. var k = _ref2[0],
  2307. v = _ref2[1];
  2308. return enc(k) + "=" + enc(v);
  2309. }).join('&');
  2310. }
  2311. }
  2312. exports.urlencode = urlencode; // For the jinja regexp, see
  2313. // https://github.com/mitsuhiko/jinja2/blob/f15b814dcba6aa12bc74d1f7d0c881d55f7126be/jinja2/utils.py#L20-L23
  2314. var puncRe = /^(?:\(|<|&lt;)?(.*?)(?:\.|,|\)|\n|&gt;)?$/; // from http://blog.gerv.net/2011/05/html5_email_address_regexp/
  2315. var emailRe = /^[\w.!#$%&'*+\-\/=?\^`{|}~]+@[a-z\d\-]+(\.[a-z\d\-]+)+$/i;
  2316. var httpHttpsRe = /^https?:\/\/.*$/;
  2317. var wwwRe = /^www\./;
  2318. var tldRe = /\.(?:org|net|com)(?:\:|\/|$)/;
  2319. function urlize(str, length, nofollow) {
  2320. if (isNaN(length)) {
  2321. length = Infinity;
  2322. }
  2323. var noFollowAttr = nofollow === true ? ' rel="nofollow"' : '';
  2324. var words = str.split(/(\s+)/).filter(function (word) {
  2325. // If the word has no length, bail. This can happen for str with
  2326. // trailing whitespace.
  2327. return word && word.length;
  2328. }).map(function (word) {
  2329. var matches = word.match(puncRe);
  2330. var possibleUrl = matches ? matches[1] : word;
  2331. var shortUrl = possibleUrl.substr(0, length); // url that starts with http or https
  2332. if (httpHttpsRe.test(possibleUrl)) {
  2333. return "<a href=\"" + possibleUrl + "\"" + noFollowAttr + ">" + shortUrl + "</a>";
  2334. } // url that starts with www.
  2335. if (wwwRe.test(possibleUrl)) {
  2336. return "<a href=\"http://" + possibleUrl + "\"" + noFollowAttr + ">" + shortUrl + "</a>";
  2337. } // an email address of the form username@domain.tld
  2338. if (emailRe.test(possibleUrl)) {
  2339. return "<a href=\"mailto:" + possibleUrl + "\">" + possibleUrl + "</a>";
  2340. } // url that ends in .com, .org or .net that is not an email address
  2341. if (tldRe.test(possibleUrl)) {
  2342. return "<a href=\"http://" + possibleUrl + "\"" + noFollowAttr + ">" + shortUrl + "</a>";
  2343. }
  2344. return word;
  2345. });
  2346. return words.join('');
  2347. }
  2348. exports.urlize = urlize;
  2349. function wordcount(str) {
  2350. str = normalize(str, '');
  2351. var words = str ? str.match(/\w+/g) : null;
  2352. return words ? words.length : null;
  2353. }
  2354. exports.wordcount = wordcount;
  2355. function float(val, def) {
  2356. var res = parseFloat(val);
  2357. return isNaN(res) ? def : res;
  2358. }
  2359. exports.float = float;
  2360. var intFilter = r.makeMacro(['value', 'default', 'base'], [], function doInt(value, defaultValue, base) {
  2361. if (base === void 0) {
  2362. base = 10;
  2363. }
  2364. var res = parseInt(value, base);
  2365. return isNaN(res) ? defaultValue : res;
  2366. });
  2367. exports.int = intFilter; // Aliases
  2368. exports.d = exports.default;
  2369. exports.e = exports.escape;
  2370. /***/ }),
  2371. /* 13 */
  2372. /***/ (function(module, exports, __webpack_require__) {
  2373. "use strict";
  2374. // Copyright Joyent, Inc. and other Node contributors.
  2375. //
  2376. // Permission is hereby granted, free of charge, to any person obtaining a
  2377. // copy of this software and associated documentation files (the
  2378. // "Software"), to deal in the Software without restriction, including
  2379. // without limitation the rights to use, copy, modify, merge, publish,
  2380. // distribute, sublicense, and/or sell copies of the Software, and to permit
  2381. // persons to whom the Software is furnished to do so, subject to the
  2382. // following conditions:
  2383. //
  2384. // The above copyright notice and this permission notice shall be included
  2385. // in all copies or substantial portions of the Software.
  2386. //
  2387. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2388. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2389. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2390. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2391. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2392. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2393. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  2394. var R = typeof Reflect === 'object' ? Reflect : null
  2395. var ReflectApply = R && typeof R.apply === 'function'
  2396. ? R.apply
  2397. : function ReflectApply(target, receiver, args) {
  2398. return Function.prototype.apply.call(target, receiver, args);
  2399. }
  2400. var ReflectOwnKeys
  2401. if (R && typeof R.ownKeys === 'function') {
  2402. ReflectOwnKeys = R.ownKeys
  2403. } else if (Object.getOwnPropertySymbols) {
  2404. ReflectOwnKeys = function ReflectOwnKeys(target) {
  2405. return Object.getOwnPropertyNames(target)
  2406. .concat(Object.getOwnPropertySymbols(target));
  2407. };
  2408. } else {
  2409. ReflectOwnKeys = function ReflectOwnKeys(target) {
  2410. return Object.getOwnPropertyNames(target);
  2411. };
  2412. }
  2413. function ProcessEmitWarning(warning) {
  2414. if (console && console.warn) console.warn(warning);
  2415. }
  2416. var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
  2417. return value !== value;
  2418. }
  2419. function EventEmitter() {
  2420. EventEmitter.init.call(this);
  2421. }
  2422. module.exports = EventEmitter;
  2423. module.exports.once = once;
  2424. // Backwards-compat with node 0.10.x
  2425. EventEmitter.EventEmitter = EventEmitter;
  2426. EventEmitter.prototype._events = undefined;
  2427. EventEmitter.prototype._eventsCount = 0;
  2428. EventEmitter.prototype._maxListeners = undefined;
  2429. // By default EventEmitters will print a warning if more than 10 listeners are
  2430. // added to it. This is a useful default which helps finding memory leaks.
  2431. var defaultMaxListeners = 10;
  2432. function checkListener(listener) {
  2433. if (typeof listener !== 'function') {
  2434. throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
  2435. }
  2436. }
  2437. Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
  2438. enumerable: true,
  2439. get: function() {
  2440. return defaultMaxListeners;
  2441. },
  2442. set: function(arg) {
  2443. if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
  2444. throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
  2445. }
  2446. defaultMaxListeners = arg;
  2447. }
  2448. });
  2449. EventEmitter.init = function() {
  2450. if (this._events === undefined ||
  2451. this._events === Object.getPrototypeOf(this)._events) {
  2452. this._events = Object.create(null);
  2453. this._eventsCount = 0;
  2454. }
  2455. this._maxListeners = this._maxListeners || undefined;
  2456. };
  2457. // Obviously not all Emitters should be limited to 10. This function allows
  2458. // that to be increased. Set to zero for unlimited.
  2459. EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
  2460. if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
  2461. throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
  2462. }
  2463. this._maxListeners = n;
  2464. return this;
  2465. };
  2466. function _getMaxListeners(that) {
  2467. if (that._maxListeners === undefined)
  2468. return EventEmitter.defaultMaxListeners;
  2469. return that._maxListeners;
  2470. }
  2471. EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
  2472. return _getMaxListeners(this);
  2473. };
  2474. EventEmitter.prototype.emit = function emit(type) {
  2475. var args = [];
  2476. for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
  2477. var doError = (type === 'error');
  2478. var events = this._events;
  2479. if (events !== undefined)
  2480. doError = (doError && events.error === undefined);
  2481. else if (!doError)
  2482. return false;
  2483. // If there is no 'error' event listener then throw.
  2484. if (doError) {
  2485. var er;
  2486. if (args.length > 0)
  2487. er = args[0];
  2488. if (er instanceof Error) {
  2489. // Note: The comments on the `throw` lines are intentional, they show
  2490. // up in Node's output if this results in an unhandled exception.
  2491. throw er; // Unhandled 'error' event
  2492. }
  2493. // At least give some kind of context to the user
  2494. var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
  2495. err.context = er;
  2496. throw err; // Unhandled 'error' event
  2497. }
  2498. var handler = events[type];
  2499. if (handler === undefined)
  2500. return false;
  2501. if (typeof handler === 'function') {
  2502. ReflectApply(handler, this, args);
  2503. } else {
  2504. var len = handler.length;
  2505. var listeners = arrayClone(handler, len);
  2506. for (var i = 0; i < len; ++i)
  2507. ReflectApply(listeners[i], this, args);
  2508. }
  2509. return true;
  2510. };
  2511. function _addListener(target, type, listener, prepend) {
  2512. var m;
  2513. var events;
  2514. var existing;
  2515. checkListener(listener);
  2516. events = target._events;
  2517. if (events === undefined) {
  2518. events = target._events = Object.create(null);
  2519. target._eventsCount = 0;
  2520. } else {
  2521. // To avoid recursion in the case that type === "newListener"! Before
  2522. // adding it to the listeners, first emit "newListener".
  2523. if (events.newListener !== undefined) {
  2524. target.emit('newListener', type,
  2525. listener.listener ? listener.listener : listener);
  2526. // Re-assign `events` because a newListener handler could have caused the
  2527. // this._events to be assigned to a new object
  2528. events = target._events;
  2529. }
  2530. existing = events[type];
  2531. }
  2532. if (existing === undefined) {
  2533. // Optimize the case of one listener. Don't need the extra array object.
  2534. existing = events[type] = listener;
  2535. ++target._eventsCount;
  2536. } else {
  2537. if (typeof existing === 'function') {
  2538. // Adding the second element, need to change to array.
  2539. existing = events[type] =
  2540. prepend ? [listener, existing] : [existing, listener];
  2541. // If we've already got an array, just append.
  2542. } else if (prepend) {
  2543. existing.unshift(listener);
  2544. } else {
  2545. existing.push(listener);
  2546. }
  2547. // Check for listener leak
  2548. m = _getMaxListeners(target);
  2549. if (m > 0 && existing.length > m && !existing.warned) {
  2550. existing.warned = true;
  2551. // No error code for this since it is a Warning
  2552. // eslint-disable-next-line no-restricted-syntax
  2553. var w = new Error('Possible EventEmitter memory leak detected. ' +
  2554. existing.length + ' ' + String(type) + ' listeners ' +
  2555. 'added. Use emitter.setMaxListeners() to ' +
  2556. 'increase limit');
  2557. w.name = 'MaxListenersExceededWarning';
  2558. w.emitter = target;
  2559. w.type = type;
  2560. w.count = existing.length;
  2561. ProcessEmitWarning(w);
  2562. }
  2563. }
  2564. return target;
  2565. }
  2566. EventEmitter.prototype.addListener = function addListener(type, listener) {
  2567. return _addListener(this, type, listener, false);
  2568. };
  2569. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  2570. EventEmitter.prototype.prependListener =
  2571. function prependListener(type, listener) {
  2572. return _addListener(this, type, listener, true);
  2573. };
  2574. function onceWrapper() {
  2575. if (!this.fired) {
  2576. this.target.removeListener(this.type, this.wrapFn);
  2577. this.fired = true;
  2578. if (arguments.length === 0)
  2579. return this.listener.call(this.target);
  2580. return this.listener.apply(this.target, arguments);
  2581. }
  2582. }
  2583. function _onceWrap(target, type, listener) {
  2584. var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
  2585. var wrapped = onceWrapper.bind(state);
  2586. wrapped.listener = listener;
  2587. state.wrapFn = wrapped;
  2588. return wrapped;
  2589. }
  2590. EventEmitter.prototype.once = function once(type, listener) {
  2591. checkListener(listener);
  2592. this.on(type, _onceWrap(this, type, listener));
  2593. return this;
  2594. };
  2595. EventEmitter.prototype.prependOnceListener =
  2596. function prependOnceListener(type, listener) {
  2597. checkListener(listener);
  2598. this.prependListener(type, _onceWrap(this, type, listener));
  2599. return this;
  2600. };
  2601. // Emits a 'removeListener' event if and only if the listener was removed.
  2602. EventEmitter.prototype.removeListener =
  2603. function removeListener(type, listener) {
  2604. var list, events, position, i, originalListener;
  2605. checkListener(listener);
  2606. events = this._events;
  2607. if (events === undefined)
  2608. return this;
  2609. list = events[type];
  2610. if (list === undefined)
  2611. return this;
  2612. if (list === listener || list.listener === listener) {
  2613. if (--this._eventsCount === 0)
  2614. this._events = Object.create(null);
  2615. else {
  2616. delete events[type];
  2617. if (events.removeListener)
  2618. this.emit('removeListener', type, list.listener || listener);
  2619. }
  2620. } else if (typeof list !== 'function') {
  2621. position = -1;
  2622. for (i = list.length - 1; i >= 0; i--) {
  2623. if (list[i] === listener || list[i].listener === listener) {
  2624. originalListener = list[i].listener;
  2625. position = i;
  2626. break;
  2627. }
  2628. }
  2629. if (position < 0)
  2630. return this;
  2631. if (position === 0)
  2632. list.shift();
  2633. else {
  2634. spliceOne(list, position);
  2635. }
  2636. if (list.length === 1)
  2637. events[type] = list[0];
  2638. if (events.removeListener !== undefined)
  2639. this.emit('removeListener', type, originalListener || listener);
  2640. }
  2641. return this;
  2642. };
  2643. EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
  2644. EventEmitter.prototype.removeAllListeners =
  2645. function removeAllListeners(type) {
  2646. var listeners, events, i;
  2647. events = this._events;
  2648. if (events === undefined)
  2649. return this;
  2650. // not listening for removeListener, no need to emit
  2651. if (events.removeListener === undefined) {
  2652. if (arguments.length === 0) {
  2653. this._events = Object.create(null);
  2654. this._eventsCount = 0;
  2655. } else if (events[type] !== undefined) {
  2656. if (--this._eventsCount === 0)
  2657. this._events = Object.create(null);
  2658. else
  2659. delete events[type];
  2660. }
  2661. return this;
  2662. }
  2663. // emit removeListener for all listeners on all events
  2664. if (arguments.length === 0) {
  2665. var keys = Object.keys(events);
  2666. var key;
  2667. for (i = 0; i < keys.length; ++i) {
  2668. key = keys[i];
  2669. if (key === 'removeListener') continue;
  2670. this.removeAllListeners(key);
  2671. }
  2672. this.removeAllListeners('removeListener');
  2673. this._events = Object.create(null);
  2674. this._eventsCount = 0;
  2675. return this;
  2676. }
  2677. listeners = events[type];
  2678. if (typeof listeners === 'function') {
  2679. this.removeListener(type, listeners);
  2680. } else if (listeners !== undefined) {
  2681. // LIFO order
  2682. for (i = listeners.length - 1; i >= 0; i--) {
  2683. this.removeListener(type, listeners[i]);
  2684. }
  2685. }
  2686. return this;
  2687. };
  2688. function _listeners(target, type, unwrap) {
  2689. var events = target._events;
  2690. if (events === undefined)
  2691. return [];
  2692. var evlistener = events[type];
  2693. if (evlistener === undefined)
  2694. return [];
  2695. if (typeof evlistener === 'function')
  2696. return unwrap ? [evlistener.listener || evlistener] : [evlistener];
  2697. return unwrap ?
  2698. unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
  2699. }
  2700. EventEmitter.prototype.listeners = function listeners(type) {
  2701. return _listeners(this, type, true);
  2702. };
  2703. EventEmitter.prototype.rawListeners = function rawListeners(type) {
  2704. return _listeners(this, type, false);
  2705. };
  2706. EventEmitter.listenerCount = function(emitter, type) {
  2707. if (typeof emitter.listenerCount === 'function') {
  2708. return emitter.listenerCount(type);
  2709. } else {
  2710. return listenerCount.call(emitter, type);
  2711. }
  2712. };
  2713. EventEmitter.prototype.listenerCount = listenerCount;
  2714. function listenerCount(type) {
  2715. var events = this._events;
  2716. if (events !== undefined) {
  2717. var evlistener = events[type];
  2718. if (typeof evlistener === 'function') {
  2719. return 1;
  2720. } else if (evlistener !== undefined) {
  2721. return evlistener.length;
  2722. }
  2723. }
  2724. return 0;
  2725. }
  2726. EventEmitter.prototype.eventNames = function eventNames() {
  2727. return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
  2728. };
  2729. function arrayClone(arr, n) {
  2730. var copy = new Array(n);
  2731. for (var i = 0; i < n; ++i)
  2732. copy[i] = arr[i];
  2733. return copy;
  2734. }
  2735. function spliceOne(list, index) {
  2736. for (; index + 1 < list.length; index++)
  2737. list[index] = list[index + 1];
  2738. list.pop();
  2739. }
  2740. function unwrapListeners(arr) {
  2741. var ret = new Array(arr.length);
  2742. for (var i = 0; i < ret.length; ++i) {
  2743. ret[i] = arr[i].listener || arr[i];
  2744. }
  2745. return ret;
  2746. }
  2747. function once(emitter, name) {
  2748. return new Promise(function (resolve, reject) {
  2749. function eventListener() {
  2750. if (errorListener !== undefined) {
  2751. emitter.removeListener('error', errorListener);
  2752. }
  2753. resolve([].slice.call(arguments));
  2754. };
  2755. var errorListener;
  2756. // Adding an error listener is not optional because
  2757. // if an error is thrown on an event emitter we cannot
  2758. // guarantee that the actual event we are waiting will
  2759. // be fired. The result could be a silent way to create
  2760. // memory or file descriptor leaks, which is something
  2761. // we should avoid.
  2762. if (name !== 'error') {
  2763. errorListener = function errorListener(err) {
  2764. emitter.removeListener(name, eventListener);
  2765. reject(err);
  2766. };
  2767. emitter.once('error', errorListener);
  2768. }
  2769. emitter.once(name, eventListener);
  2770. });
  2771. }
  2772. /***/ }),
  2773. /* 14 */
  2774. /***/ (function(module, exports, __webpack_require__) {
  2775. "use strict";
  2776. var SafeString = __webpack_require__(2).SafeString;
  2777. /**
  2778. * Returns `true` if the object is a function, otherwise `false`.
  2779. * @param { any } value
  2780. * @returns { boolean }
  2781. */
  2782. function callable(value) {
  2783. return typeof value === 'function';
  2784. }
  2785. exports.callable = callable;
  2786. /**
  2787. * Returns `true` if the object is strictly not `undefined`.
  2788. * @param { any } value
  2789. * @returns { boolean }
  2790. */
  2791. function defined(value) {
  2792. return value !== undefined;
  2793. }
  2794. exports.defined = defined;
  2795. /**
  2796. * Returns `true` if the operand (one) is divisble by the test's argument
  2797. * (two).
  2798. * @param { number } one
  2799. * @param { number } two
  2800. * @returns { boolean }
  2801. */
  2802. function divisibleby(one, two) {
  2803. return one % two === 0;
  2804. }
  2805. exports.divisibleby = divisibleby;
  2806. /**
  2807. * Returns true if the string has been escaped (i.e., is a SafeString).
  2808. * @param { any } value
  2809. * @returns { boolean }
  2810. */
  2811. function escaped(value) {
  2812. return value instanceof SafeString;
  2813. }
  2814. exports.escaped = escaped;
  2815. /**
  2816. * Returns `true` if the arguments are strictly equal.
  2817. * @param { any } one
  2818. * @param { any } two
  2819. */
  2820. function equalto(one, two) {
  2821. return one === two;
  2822. }
  2823. exports.equalto = equalto; // Aliases
  2824. exports.eq = exports.equalto;
  2825. exports.sameas = exports.equalto;
  2826. /**
  2827. * Returns `true` if the value is evenly divisible by 2.
  2828. * @param { number } value
  2829. * @returns { boolean }
  2830. */
  2831. function even(value) {
  2832. return value % 2 === 0;
  2833. }
  2834. exports.even = even;
  2835. /**
  2836. * Returns `true` if the value is falsy - if I recall correctly, '', 0, false,
  2837. * undefined, NaN or null. I don't know if we should stick to the default JS
  2838. * behavior or attempt to replicate what Python believes should be falsy (i.e.,
  2839. * empty arrays, empty dicts, not 0...).
  2840. * @param { any } value
  2841. * @returns { boolean }
  2842. */
  2843. function falsy(value) {
  2844. return !value;
  2845. }
  2846. exports.falsy = falsy;
  2847. /**
  2848. * Returns `true` if the operand (one) is greater or equal to the test's
  2849. * argument (two).
  2850. * @param { number } one
  2851. * @param { number } two
  2852. * @returns { boolean }
  2853. */
  2854. function ge(one, two) {
  2855. return one >= two;
  2856. }
  2857. exports.ge = ge;
  2858. /**
  2859. * Returns `true` if the operand (one) is greater than the test's argument
  2860. * (two).
  2861. * @param { number } one
  2862. * @param { number } two
  2863. * @returns { boolean }
  2864. */
  2865. function greaterthan(one, two) {
  2866. return one > two;
  2867. }
  2868. exports.greaterthan = greaterthan; // alias
  2869. exports.gt = exports.greaterthan;
  2870. /**
  2871. * Returns `true` if the operand (one) is less than or equal to the test's
  2872. * argument (two).
  2873. * @param { number } one
  2874. * @param { number } two
  2875. * @returns { boolean }
  2876. */
  2877. function le(one, two) {
  2878. return one <= two;
  2879. }
  2880. exports.le = le;
  2881. /**
  2882. * Returns `true` if the operand (one) is less than the test's passed argument
  2883. * (two).
  2884. * @param { number } one
  2885. * @param { number } two
  2886. * @returns { boolean }
  2887. */
  2888. function lessthan(one, two) {
  2889. return one < two;
  2890. }
  2891. exports.lessthan = lessthan; // alias
  2892. exports.lt = exports.lessthan;
  2893. /**
  2894. * Returns `true` if the string is lowercased.
  2895. * @param { string } value
  2896. * @returns { boolean }
  2897. */
  2898. function lower(value) {
  2899. return value.toLowerCase() === value;
  2900. }
  2901. exports.lower = lower;
  2902. /**
  2903. * Returns `true` if the operand (one) is less than or equal to the test's
  2904. * argument (two).
  2905. * @param { number } one
  2906. * @param { number } two
  2907. * @returns { boolean }
  2908. */
  2909. function ne(one, two) {
  2910. return one !== two;
  2911. }
  2912. exports.ne = ne;
  2913. /**
  2914. * Returns true if the value is strictly equal to `null`.
  2915. * @param { any }
  2916. * @returns { boolean }
  2917. */
  2918. function nullTest(value) {
  2919. return value === null;
  2920. }
  2921. exports.null = nullTest;
  2922. /**
  2923. * Returns true if value is a number.
  2924. * @param { any }
  2925. * @returns { boolean }
  2926. */
  2927. function number(value) {
  2928. return typeof value === 'number';
  2929. }
  2930. exports.number = number;
  2931. /**
  2932. * Returns `true` if the value is *not* evenly divisible by 2.
  2933. * @param { number } value
  2934. * @returns { boolean }
  2935. */
  2936. function odd(value) {
  2937. return value % 2 === 1;
  2938. }
  2939. exports.odd = odd;
  2940. /**
  2941. * Returns `true` if the value is a string, `false` if not.
  2942. * @param { any } value
  2943. * @returns { boolean }
  2944. */
  2945. function string(value) {
  2946. return typeof value === 'string';
  2947. }
  2948. exports.string = string;
  2949. /**
  2950. * Returns `true` if the value is not in the list of things considered falsy:
  2951. * '', null, undefined, 0, NaN and false.
  2952. * @param { any } value
  2953. * @returns { boolean }
  2954. */
  2955. function truthy(value) {
  2956. return !!value;
  2957. }
  2958. exports.truthy = truthy;
  2959. /**
  2960. * Returns `true` if the value is undefined.
  2961. * @param { any } value
  2962. * @returns { boolean }
  2963. */
  2964. function undefinedTest(value) {
  2965. return value === undefined;
  2966. }
  2967. exports.undefined = undefinedTest;
  2968. /**
  2969. * Returns `true` if the string is uppercased.
  2970. * @param { string } value
  2971. * @returns { boolean }
  2972. */
  2973. function upper(value) {
  2974. return value.toUpperCase() === value;
  2975. }
  2976. exports.upper = upper;
  2977. /**
  2978. * If ES6 features are available, returns `true` if the value implements the
  2979. * `Symbol.iterator` method. If not, it's a string or Array.
  2980. *
  2981. * Could potentially cause issues if a browser exists that has Set and Map but
  2982. * not Symbol.
  2983. *
  2984. * @param { any } value
  2985. * @returns { boolean }
  2986. */
  2987. function iterable(value) {
  2988. if (typeof Symbol !== 'undefined') {
  2989. return !!value[Symbol.iterator];
  2990. } else {
  2991. return Array.isArray(value) || typeof value === 'string';
  2992. }
  2993. }
  2994. exports.iterable = iterable;
  2995. /**
  2996. * If ES6 features are available, returns `true` if the value is an object hash
  2997. * or an ES6 Map. Otherwise just return if it's an object hash.
  2998. * @param { any } value
  2999. * @returns { boolean }
  3000. */
  3001. function mapping(value) {
  3002. // only maps and object hashes
  3003. var bool = value !== null && value !== undefined && typeof value === 'object' && !Array.isArray(value);
  3004. if (Set) {
  3005. return bool && !(value instanceof Set);
  3006. } else {
  3007. return bool;
  3008. }
  3009. }
  3010. exports.mapping = mapping;
  3011. /***/ }),
  3012. /* 15 */
  3013. /***/ (function(module, exports, __webpack_require__) {
  3014. "use strict";
  3015. function _cycler(items) {
  3016. var index = -1;
  3017. return {
  3018. current: null,
  3019. reset: function reset() {
  3020. index = -1;
  3021. this.current = null;
  3022. },
  3023. next: function next() {
  3024. index++;
  3025. if (index >= items.length) {
  3026. index = 0;
  3027. }
  3028. this.current = items[index];
  3029. return this.current;
  3030. }
  3031. };
  3032. }
  3033. function _joiner(sep) {
  3034. sep = sep || ',';
  3035. var first = true;
  3036. return function () {
  3037. var val = first ? '' : sep;
  3038. first = false;
  3039. return val;
  3040. };
  3041. } // Making this a function instead so it returns a new object
  3042. // each time it's called. That way, if something like an environment
  3043. // uses it, they will each have their own copy.
  3044. function globals() {
  3045. return {
  3046. range: function range(start, stop, step) {
  3047. if (typeof stop === 'undefined') {
  3048. stop = start;
  3049. start = 0;
  3050. step = 1;
  3051. } else if (!step) {
  3052. step = 1;
  3053. }
  3054. var arr = [];
  3055. if (step > 0) {
  3056. for (var i = start; i < stop; i += step) {
  3057. arr.push(i);
  3058. }
  3059. } else {
  3060. for (var _i = start; _i > stop; _i += step) {
  3061. // eslint-disable-line for-direction
  3062. arr.push(_i);
  3063. }
  3064. }
  3065. return arr;
  3066. },
  3067. cycler: function cycler() {
  3068. return _cycler(Array.prototype.slice.call(arguments));
  3069. },
  3070. joiner: function joiner(sep) {
  3071. return _joiner(sep);
  3072. }
  3073. };
  3074. }
  3075. module.exports = globals;
  3076. /***/ }),
  3077. /* 16 */
  3078. /***/ (function(module, exports, __webpack_require__) {
  3079. var path = __webpack_require__(0);
  3080. module.exports = function express(env, app) {
  3081. function NunjucksView(name, opts) {
  3082. this.name = name;
  3083. this.path = name;
  3084. this.defaultEngine = opts.defaultEngine;
  3085. this.ext = path.extname(name);
  3086. if (!this.ext && !this.defaultEngine) {
  3087. throw new Error('No default engine was specified and no extension was provided.');
  3088. }
  3089. if (!this.ext) {
  3090. this.name += this.ext = (this.defaultEngine[0] !== '.' ? '.' : '') + this.defaultEngine;
  3091. }
  3092. }
  3093. NunjucksView.prototype.render = function render(opts, cb) {
  3094. env.render(this.name, opts, cb);
  3095. };
  3096. app.set('view', NunjucksView);
  3097. app.set('nunjucksEnv', env);
  3098. return env;
  3099. };
  3100. /***/ }),
  3101. /* 17 */
  3102. /***/ (function(module, exports, __webpack_require__) {
  3103. function installCompat() {
  3104. 'use strict';
  3105. /* eslint-disable camelcase */
  3106. // This must be called like `nunjucks.installCompat` so that `this`
  3107. // references the nunjucks instance
  3108. var runtime = this.runtime;
  3109. var lib = this.lib; // Handle slim case where these 'modules' are excluded from the built source
  3110. var Compiler = this.compiler.Compiler;
  3111. var Parser = this.parser.Parser;
  3112. var nodes = this.nodes;
  3113. var lexer = this.lexer;
  3114. var orig_contextOrFrameLookup = runtime.contextOrFrameLookup;
  3115. var orig_memberLookup = runtime.memberLookup;
  3116. var orig_Compiler_assertType;
  3117. var orig_Parser_parseAggregate;
  3118. if (Compiler) {
  3119. orig_Compiler_assertType = Compiler.prototype.assertType;
  3120. }
  3121. if (Parser) {
  3122. orig_Parser_parseAggregate = Parser.prototype.parseAggregate;
  3123. }
  3124. function uninstall() {
  3125. runtime.contextOrFrameLookup = orig_contextOrFrameLookup;
  3126. runtime.memberLookup = orig_memberLookup;
  3127. if (Compiler) {
  3128. Compiler.prototype.assertType = orig_Compiler_assertType;
  3129. }
  3130. if (Parser) {
  3131. Parser.prototype.parseAggregate = orig_Parser_parseAggregate;
  3132. }
  3133. }
  3134. runtime.contextOrFrameLookup = function contextOrFrameLookup(context, frame, key) {
  3135. var val = orig_contextOrFrameLookup.apply(this, arguments);
  3136. if (val !== undefined) {
  3137. return val;
  3138. }
  3139. switch (key) {
  3140. case 'True':
  3141. return true;
  3142. case 'False':
  3143. return false;
  3144. case 'None':
  3145. return null;
  3146. default:
  3147. return undefined;
  3148. }
  3149. };
  3150. function getTokensState(tokens) {
  3151. return {
  3152. index: tokens.index,
  3153. lineno: tokens.lineno,
  3154. colno: tokens.colno
  3155. };
  3156. }
  3157. if (false) {
  3158. // i.e., not slim mode
  3159. var Slice = nodes.Node.extend('Slice', {
  3160. fields: ['start', 'stop', 'step'],
  3161. init: function init(lineno, colno, start, stop, step) {
  3162. start = start || new nodes.Literal(lineno, colno, null);
  3163. stop = stop || new nodes.Literal(lineno, colno, null);
  3164. step = step || new nodes.Literal(lineno, colno, 1);
  3165. this.parent(lineno, colno, start, stop, step);
  3166. }
  3167. });
  3168. Compiler.prototype.assertType = function assertType(node) {
  3169. if (node instanceof Slice) {
  3170. return;
  3171. }
  3172. orig_Compiler_assertType.apply(this, arguments);
  3173. };
  3174. Compiler.prototype.compileSlice = function compileSlice(node, frame) {
  3175. this._emit('(');
  3176. this._compileExpression(node.start, frame);
  3177. this._emit('),(');
  3178. this._compileExpression(node.stop, frame);
  3179. this._emit('),(');
  3180. this._compileExpression(node.step, frame);
  3181. this._emit(')');
  3182. };
  3183. Parser.prototype.parseAggregate = function parseAggregate() {
  3184. var _this = this;
  3185. var origState = getTokensState(this.tokens); // Set back one accounting for opening bracket/parens
  3186. origState.colno--;
  3187. origState.index--;
  3188. try {
  3189. return orig_Parser_parseAggregate.apply(this);
  3190. } catch (e) {
  3191. var errState = getTokensState(this.tokens);
  3192. var rethrow = function rethrow() {
  3193. lib._assign(_this.tokens, errState);
  3194. return e;
  3195. }; // Reset to state before original parseAggregate called
  3196. lib._assign(this.tokens, origState);
  3197. this.peeked = false;
  3198. var tok = this.peekToken();
  3199. if (tok.type !== lexer.TOKEN_LEFT_BRACKET) {
  3200. throw rethrow();
  3201. } else {
  3202. this.nextToken();
  3203. }
  3204. var node = new Slice(tok.lineno, tok.colno); // If we don't encounter a colon while parsing, this is not a slice,
  3205. // so re-raise the original exception.
  3206. var isSlice = false;
  3207. for (var i = 0; i <= node.fields.length; i++) {
  3208. if (this.skip(lexer.TOKEN_RIGHT_BRACKET)) {
  3209. break;
  3210. }
  3211. if (i === node.fields.length) {
  3212. if (isSlice) {
  3213. this.fail('parseSlice: too many slice components', tok.lineno, tok.colno);
  3214. } else {
  3215. break;
  3216. }
  3217. }
  3218. if (this.skip(lexer.TOKEN_COLON)) {
  3219. isSlice = true;
  3220. } else {
  3221. var field = node.fields[i];
  3222. node[field] = this.parseExpression();
  3223. isSlice = this.skip(lexer.TOKEN_COLON) || isSlice;
  3224. }
  3225. }
  3226. if (!isSlice) {
  3227. throw rethrow();
  3228. }
  3229. return new nodes.Array(tok.lineno, tok.colno, [node]);
  3230. }
  3231. };
  3232. }
  3233. function sliceLookup(obj, start, stop, step) {
  3234. obj = obj || [];
  3235. if (start === null) {
  3236. start = step < 0 ? obj.length - 1 : 0;
  3237. }
  3238. if (stop === null) {
  3239. stop = step < 0 ? -1 : obj.length;
  3240. } else if (stop < 0) {
  3241. stop += obj.length;
  3242. }
  3243. if (start < 0) {
  3244. start += obj.length;
  3245. }
  3246. var results = [];
  3247. for (var i = start;; i += step) {
  3248. if (i < 0 || i > obj.length) {
  3249. break;
  3250. }
  3251. if (step > 0 && i >= stop) {
  3252. break;
  3253. }
  3254. if (step < 0 && i <= stop) {
  3255. break;
  3256. }
  3257. results.push(runtime.memberLookup(obj, i));
  3258. }
  3259. return results;
  3260. }
  3261. function hasOwnProp(obj, key) {
  3262. return Object.prototype.hasOwnProperty.call(obj, key);
  3263. }
  3264. var ARRAY_MEMBERS = {
  3265. pop: function pop(index) {
  3266. if (index === undefined) {
  3267. return this.pop();
  3268. }
  3269. if (index >= this.length || index < 0) {
  3270. throw new Error('KeyError');
  3271. }
  3272. return this.splice(index, 1);
  3273. },
  3274. append: function append(element) {
  3275. return this.push(element);
  3276. },
  3277. remove: function remove(element) {
  3278. for (var i = 0; i < this.length; i++) {
  3279. if (this[i] === element) {
  3280. return this.splice(i, 1);
  3281. }
  3282. }
  3283. throw new Error('ValueError');
  3284. },
  3285. count: function count(element) {
  3286. var count = 0;
  3287. for (var i = 0; i < this.length; i++) {
  3288. if (this[i] === element) {
  3289. count++;
  3290. }
  3291. }
  3292. return count;
  3293. },
  3294. index: function index(element) {
  3295. var i;
  3296. if ((i = this.indexOf(element)) === -1) {
  3297. throw new Error('ValueError');
  3298. }
  3299. return i;
  3300. },
  3301. find: function find(element) {
  3302. return this.indexOf(element);
  3303. },
  3304. insert: function insert(index, elem) {
  3305. return this.splice(index, 0, elem);
  3306. }
  3307. };
  3308. var OBJECT_MEMBERS = {
  3309. items: function items() {
  3310. return lib._entries(this);
  3311. },
  3312. values: function values() {
  3313. return lib._values(this);
  3314. },
  3315. keys: function keys() {
  3316. return lib.keys(this);
  3317. },
  3318. get: function get(key, def) {
  3319. var output = this[key];
  3320. if (output === undefined) {
  3321. output = def;
  3322. }
  3323. return output;
  3324. },
  3325. has_key: function has_key(key) {
  3326. return hasOwnProp(this, key);
  3327. },
  3328. pop: function pop(key, def) {
  3329. var output = this[key];
  3330. if (output === undefined && def !== undefined) {
  3331. output = def;
  3332. } else if (output === undefined) {
  3333. throw new Error('KeyError');
  3334. } else {
  3335. delete this[key];
  3336. }
  3337. return output;
  3338. },
  3339. popitem: function popitem() {
  3340. var keys = lib.keys(this);
  3341. if (!keys.length) {
  3342. throw new Error('KeyError');
  3343. }
  3344. var k = keys[0];
  3345. var val = this[k];
  3346. delete this[k];
  3347. return [k, val];
  3348. },
  3349. setdefault: function setdefault(key, def) {
  3350. if (def === void 0) {
  3351. def = null;
  3352. }
  3353. if (!(key in this)) {
  3354. this[key] = def;
  3355. }
  3356. return this[key];
  3357. },
  3358. update: function update(kwargs) {
  3359. lib._assign(this, kwargs);
  3360. return null; // Always returns None
  3361. }
  3362. };
  3363. OBJECT_MEMBERS.iteritems = OBJECT_MEMBERS.items;
  3364. OBJECT_MEMBERS.itervalues = OBJECT_MEMBERS.values;
  3365. OBJECT_MEMBERS.iterkeys = OBJECT_MEMBERS.keys;
  3366. runtime.memberLookup = function memberLookup(obj, val, autoescape) {
  3367. if (arguments.length === 4) {
  3368. return sliceLookup.apply(this, arguments);
  3369. }
  3370. obj = obj || {}; // If the object is an object, return any of the methods that Python would
  3371. // otherwise provide.
  3372. if (lib.isArray(obj) && hasOwnProp(ARRAY_MEMBERS, val)) {
  3373. return ARRAY_MEMBERS[val].bind(obj);
  3374. }
  3375. if (lib.isObject(obj) && hasOwnProp(OBJECT_MEMBERS, val)) {
  3376. return OBJECT_MEMBERS[val].bind(obj);
  3377. }
  3378. return orig_memberLookup.apply(this, arguments);
  3379. };
  3380. return uninstall;
  3381. }
  3382. module.exports = installCompat;
  3383. /***/ })
  3384. /******/ ]);
  3385. });
  3386. //# sourceMappingURL=nunjucks-slim.js.map