bajo 2.21.1 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsdoc.conf.json +1 -1
- package/class/app.js +139 -115
- package/class/bajo.js +96 -89
- package/class/base.js +25 -9
- package/class/cache.js +32 -19
- package/class/err.js +11 -9
- package/class/log.js +102 -52
- package/class/plugin.js +45 -35
- package/class/print.js +45 -44
- package/class/tools.js +7 -1
- package/docs/App.html +1 -23
- package/docs/Bajo.html +1 -6
- package/docs/Base.html +1 -1
- package/docs/Cache.html +1 -1
- package/docs/Err.html +2 -2
- package/docs/Log.html +4 -4
- package/docs/Plugin.html +1 -1
- package/docs/Print.html +1 -1
- package/docs/Tools.html +1 -1
- package/docs/class_app.js.html +141 -117
- package/docs/class_bajo.js.html +98 -91
- package/docs/class_base.js.html +27 -11
- package/docs/class_cache.js.html +34 -21
- package/docs/class_err.js.html +13 -11
- package/docs/class_log.js.html +104 -54
- package/docs/class_plugin.js.html +47 -37
- package/docs/class_print.js.html +47 -46
- package/docs/class_tools.js.html +9 -3
- package/docs/data/search.json +1 -1
- package/docs/global.html +1 -1
- package/docs/index.html +1 -1
- package/docs/index.js.html +8 -4
- package/docs/{class__helper.js.html → lib_helper.js.html} +208 -96
- package/docs/lib_hook.js.html +231 -0
- package/docs/module-Helper.html +8 -1
- package/docs/module-Hook.html +3 -0
- package/docs/module-Lib.html +1 -8
- package/index.js +1 -1
- package/{class/_helper.js → lib/helper.js} +206 -94
- package/lib/hook.js +228 -0
- package/package.json +1 -1
- package/wiki/CHANGES.md +6 -0
- package/docs/class_helper_bajo.js.html +0 -398
- package/docs/class_helper_base.js.html +0 -246
- package/docs/class_misc_err.js.html +0 -129
- package/docs/class_misc_log.js.html +0 -210
- package/docs/class_misc_print.js.html +0 -267
- package/docs/lib_current-loc.js.html +0 -36
- package/docs/lib_find-deep.js.html +0 -27
- package/docs/lib_formats.js.html +0 -68
- package/docs/lib_freeze.js.html +0 -54
- package/docs/lib_import-module.js.html +0 -61
- package/docs/lib_index.js.html +0 -9
- package/docs/lib_log-levels.js.html +0 -38
- package/docs/lib_parse-args-argv.js.html +0 -83
- package/docs/lib_parse-env.js.html +0 -53
- package/docs/lib_resolve-path.js.html +0 -27
- package/docs/lib_shim.js.html +0 -40
- package/docs/module-Helper_Bajo.html +0 -3
- package/docs/module-Helper_Base.html +0 -3
- package/lib/find-deep.js +0 -24
- package/lib/formats.js +0 -65
- package/lib/freeze.js +0 -51
- package/lib/import-module.js +0 -58
- package/lib/index.js +0 -6
- package/lib/log-levels.js +0 -35
package/docs/class_app.js.html
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<!DOCTYPE html><html lang="en" style="font-size:16px"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Source: class/app.js</title><!--[if lt IE 9]>
|
|
2
2
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
3
|
-
<![endif]--><script src="scripts/third-party/hljs.js" defer="defer"></script><script src="scripts/third-party/hljs-line-num.js" defer="defer"></script><script src="scripts/third-party/popper.js" defer="defer"></script><script src="scripts/third-party/tippy.js" defer="defer"></script><script src="scripts/third-party/tocbot.min.js"></script><script>var baseURL="/",locationPathname="";baseURL=(locationPathname=document.location.pathname).substr(0,locationPathname.lastIndexOf("/")+1)</script><link rel="stylesheet" href="styles/clean-jsdoc-theme.min.css"><svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none"><defs><symbol id="copy-icon" viewbox="0 0 488.3 488.3"><g><path d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z"/><path d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z"/></g></symbol><symbol id="search-icon" viewBox="0 0 512 512"><g><g><path d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z"/></g></g><g><g><path d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z"/></g></g></symbol><symbol id="font-size-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11.246 15H4.754l-2 5H.6L7 4h2l6.4 16h-2.154l-2-5zm-.8-2L8 6.885 5.554 13h4.892zM21 12.535V12h2v8h-2v-.535a4 4 0 1 1 0-6.93zM19 18a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></symbol><symbol id="add-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 11V5h2v6h6v2h-6v6h-2v-6H5v-2z"/></symbol><symbol id="minus-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M5 11h14v2H5z"/></symbol><symbol id="dark-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol><symbol id="light-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol><symbol id="reset-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.537 19.567A9.961 9.961 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 2.136-.67 4.116-1.81 5.74L17 12h3a8 8 0 1 0-2.46 5.772l.997 1.795z"/></symbol><symbol id="down-icon" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></symbol><symbol id="codepen-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.5 13.202L13 15.535v3.596L19.197 15 16.5 13.202zM14.697 12L12 10.202 9.303 12 12 13.798 14.697 12zM20 10.869L18.303 12 20 13.131V10.87zM19.197 9L13 4.869v3.596l3.5 2.333L19.197 9zM7.5 10.798L11 8.465V4.869L4.803 9 7.5 10.798zM4.803 15L11 19.131v-3.596l-3.5-2.333L4.803 15zM4 13.131L5.697 12 4 10.869v2.262zM2 9a1 1 0 0 1 .445-.832l9-6a1 1 0 0 1 1.11 0l9 6A1 1 0 0 1 22 9v6a1 1 0 0 1-.445.832l-9 6a1 1 0 0 1-1.11 0l-9-6A1 1 0 0 1 2 15V9z"/></symbol><symbol id="close-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></symbol><symbol id="menu-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 4h18v2H3V4zm0 7h18v2H3v-2zm0 7h18v2H3v-2z"/></symbol></defs></svg></head><body data-theme="light"><div class="sidebar-container"><div class="sidebar" id="sidebar"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo API</a><div class="sidebar-items-container"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="App.html">App</a></div><div class="sidebar-section-children"><a href="Bajo.html">Bajo</a></div><div class="sidebar-section-children"><a href="Base.html">Base</a></div><div class="sidebar-section-children"><a href="Cache.html">Cache</a></div><div class="sidebar-section-children"><a href="Err.html">Err</a></div><div class="sidebar-section-children"><a href="Log.html">Log</a></div><div class="sidebar-section-children"><a href="Plugin.html">Plugin</a></div><div class="sidebar-section-children"><a href="Print.html">Print</a></div><div class="sidebar-section-children"><a href="Tools.html">Tools</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-events"><div>Events</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#event:bajo:afterAll%257Bmethod%257D">bajo:afterAll{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterBootComplete">bajo:afterBootComplete</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterBuildCollection">bajo:afterBuildCollection</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:afterCollectHooks">bajo:afterCollectHooks</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:beforeAll%257Bmethod%257D">bajo:beforeAll{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:bajo:beforeBuildCollection">bajo:beforeBuildCollection</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:after%257Bmethod%257D">{ns}:after{method}</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:beforeAppletRun">{ns}:beforeAppletRun</a></div><div class="sidebar-section-children"><a href="global.html#event:%257Bns%257D:before%257Bmethod%257D">{ns}:before{method}</a></div><div class="sidebar-section-children"><a href="module-Helper%257Bns%257D_afterAppletRun.html">Helper{ns}:afterAppletRun</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-modules"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-Helper.html">Helper</a></div><div class="sidebar-section-children"><a href="module-Lib.html">Lib</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-global"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#TAppConfigHandler">TAppConfigHandler</a></div><div class="sidebar-section-children"><a href="global.html#TAppEnv">TAppEnv</a></div><div class="sidebar-section-children"><a href="global.html#TBajoDataType">TBajoDataType</a></div><div class="sidebar-section-children"><a href="global.html#TBajoFormatResult">TBajoFormatResult</a></div><div class="sidebar-section-children"><a href="global.html#TBajoFormatType">TBajoFormatType</a></div><div class="sidebar-section-children"><a href="global.html#TLogJson">TLogJson</a></div><div class="sidebar-section-children"><a href="global.html#TLogLevels">TLogLevels</a></div><div class="sidebar-section-children"><a href="global.html#TNsPathPairs">TNsPathPairs</a></div><div class="sidebar-section-children"><a href="global.html#TNsPathResult">TNsPathResult</a></div><div class="sidebar-section-children"><a href="global.html#TPrintOptions">TPrintOptions</a></div><div class="sidebar-section-children"><a href="global.html#boot">boot</a></div></div></div></div></div><div class="navbar-container" id="VuAckcnZhf"><nav class="navbar"><div class="navbar-left-items"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div><div class="navbar-item"><a id="" href="https://bajo.app" target="">Bajo</a></div></div><div class="navbar-right-items"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#dark-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div><nav></nav></nav></div><div class="toc-container"><div class="toc-content"><span class="bold">On this page</span><div id="eed4d2a0bfd64539bb9df78095dec881"></div></div></div><div class="body-wrapper"><div class="main-content"><div class="main-wrapper"><section id="source-page" class="source-page"><header><h1 id="title" class="has-anchor">class_app.js</h1></header><article><pre class="prettyprint source lang-js"><code>import util from 'util'
|
|
3
|
+
<![endif]--><script src="scripts/third-party/hljs.js" defer="defer"></script><script src="scripts/third-party/hljs-line-num.js" defer="defer"></script><script src="scripts/third-party/popper.js" defer="defer"></script><script src="scripts/third-party/tippy.js" defer="defer"></script><script src="scripts/third-party/tocbot.min.js"></script><script>var baseURL="/",locationPathname="";baseURL=(locationPathname=document.location.pathname).substr(0,locationPathname.lastIndexOf("/")+1)</script><link rel="stylesheet" href="styles/clean-jsdoc-theme.min.css"><svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none"><defs><symbol id="copy-icon" viewbox="0 0 488.3 488.3"><g><path d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z"/><path d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z"/></g></symbol><symbol id="search-icon" viewBox="0 0 512 512"><g><g><path d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z"/></g></g><g><g><path d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z"/></g></g></symbol><symbol id="font-size-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11.246 15H4.754l-2 5H.6L7 4h2l6.4 16h-2.154l-2-5zm-.8-2L8 6.885 5.554 13h4.892zM21 12.535V12h2v8h-2v-.535a4 4 0 1 1 0-6.93zM19 18a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></symbol><symbol id="add-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 11V5h2v6h6v2h-6v6h-2v-6H5v-2z"/></symbol><symbol id="minus-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M5 11h14v2H5z"/></symbol><symbol id="dark-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol><symbol id="light-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol><symbol id="reset-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.537 19.567A9.961 9.961 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 2.136-.67 4.116-1.81 5.74L17 12h3a8 8 0 1 0-2.46 5.772l.997 1.795z"/></symbol><symbol id="down-icon" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></symbol><symbol id="codepen-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.5 13.202L13 15.535v3.596L19.197 15 16.5 13.202zM14.697 12L12 10.202 9.303 12 12 13.798 14.697 12zM20 10.869L18.303 12 20 13.131V10.87zM19.197 9L13 4.869v3.596l3.5 2.333L19.197 9zM7.5 10.798L11 8.465V4.869L4.803 9 7.5 10.798zM4.803 15L11 19.131v-3.596l-3.5-2.333L4.803 15zM4 13.131L5.697 12 4 10.869v2.262zM2 9a1 1 0 0 1 .445-.832l9-6a1 1 0 0 1 1.11 0l9 6A1 1 0 0 1 22 9v6a1 1 0 0 1-.445.832l-9 6a1 1 0 0 1-1.11 0l-9-6A1 1 0 0 1 2 15V9z"/></symbol><symbol id="close-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></symbol><symbol id="menu-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 4h18v2H3V4zm0 7h18v2H3v-2zm0 7h18v2H3v-2z"/></symbol></defs></svg></head><body data-theme="light"><div class="sidebar-container"><div class="sidebar" id="sidebar"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo API</a><div class="sidebar-items-container"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="App.html">App</a></div><div class="sidebar-section-children"><a href="Bajo.html">Bajo</a></div><div class="sidebar-section-children"><a href="Base.html">Base</a></div><div class="sidebar-section-children"><a href="Cache.html">Cache</a></div><div class="sidebar-section-children"><a href="Err.html">Err</a></div><div class="sidebar-section-children"><a href="Log.html">Log</a></div><div class="sidebar-section-children"><a href="Plugin.html">Plugin</a></div><div class="sidebar-section-children"><a href="Print.html">Print</a></div><div class="sidebar-section-children"><a href="Tools.html">Tools</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-modules"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-Helper.html">Helper</a></div><div class="sidebar-section-children"><a href="module-Hook.html">Hook</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-global"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#boot">boot</a></div></div></div></div></div><div class="navbar-container" id="VuAckcnZhf"><nav class="navbar"><div class="navbar-left-items"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div><div class="navbar-item"><a id="" href="https://bajo.app" target="">Bajo</a></div></div><div class="navbar-right-items"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#dark-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div><nav></nav></nav></div><div class="toc-container"><div class="toc-content"><span class="bold">On this page</span><div id="eed4d2a0bfd64539bb9df78095dec881"></div></div></div><div class="body-wrapper"><div class="main-content"><div class="main-wrapper"><section id="source-page" class="source-page"><header><h1 id="title" class="has-anchor">class_app.js</h1></header><article><pre class="prettyprint source lang-js"><code>import util from 'util'
|
|
4
4
|
import Bajo from './bajo.js'
|
|
5
5
|
import Base from './base.js'
|
|
6
6
|
import Cache from './cache.js'
|
|
7
7
|
import Tools from './tools.js'
|
|
8
8
|
import Plugin from './plugin.js'
|
|
9
|
-
import {
|
|
9
|
+
import { lib, runAsApplet } from '../lib/helper.js'
|
|
10
10
|
import { fileURLToPath } from 'url'
|
|
11
11
|
|
|
12
12
|
const { camelCase, isPlainObject, get, reverse, map, last, without, set } = lib._
|
|
@@ -33,10 +33,45 @@ function getCallerFilename () {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* @typedef {Object}
|
|
36
|
+
* @typedef {Object} TEnv
|
|
37
|
+
* @memberof App
|
|
37
38
|
* @property {string} dev=development
|
|
38
39
|
* @property {string} prod=production
|
|
39
|
-
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @callback readHandler
|
|
44
|
+
* @memberof App
|
|
45
|
+
* @param {string} text - Text to be parsed
|
|
46
|
+
* @param {object} options - Options object
|
|
47
|
+
* @returns {object} Parsed object
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @callback writeHandler
|
|
52
|
+
* @memberof App
|
|
53
|
+
* @param {Object} data - Data to be stringified
|
|
54
|
+
* @param {Object} [options={}] - Options
|
|
55
|
+
* @param {boolean} [options.writeToFile=false] - If true, write result to a file
|
|
56
|
+
* @param {string} [options.saveAsFile] - The file path to save result if writeToFile is true
|
|
57
|
+
* @returns {string} Stringified result
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @typedef {Object} TConfigHandler
|
|
62
|
+
* @memberof App
|
|
63
|
+
* @property {string} ns - Namespace
|
|
64
|
+
* @property {string} ext - File extension
|
|
65
|
+
* @property {App.readHandler} [readHandler] - Function to call for reading
|
|
66
|
+
* @property {App.writeHandler} [writeHandler] - Function to call for writing
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @typedef {Object} TOptions
|
|
71
|
+
* @memberof App
|
|
72
|
+
* @property {string} [cwd] - Set current working directory. Defaults to the script directory
|
|
73
|
+
* @property {string[]} [plugins] - Array of plugins to load. If provided, it override the list in `package.json` and `.plugins` file
|
|
74
|
+
* @property {Object} [config] - Plugin's config object. If provided, plugin configs will no longer be read from its config files
|
|
40
75
|
*/
|
|
41
76
|
|
|
42
77
|
/**
|
|
@@ -46,73 +81,53 @@ function getCallerFilename () {
|
|
|
46
81
|
*/
|
|
47
82
|
class App {
|
|
48
83
|
/**
|
|
49
|
-
*
|
|
50
|
-
* @param {
|
|
51
|
-
* @param {string[]} [options.plugins] - Array of plugins to load. If provided, it override the list in ```package.json``` and ```.plugins``` file.
|
|
52
|
-
* @param {Object} [options.config] - Plugin's config object. If provided, plugin configs will no longer be read from its config files.
|
|
84
|
+
* Constructor.
|
|
85
|
+
* @param {App.TOptions} [options={}] - Options object.
|
|
53
86
|
*/
|
|
54
87
|
constructor (options = {}) {
|
|
55
88
|
/**
|
|
56
89
|
* Copy of provided options.
|
|
57
|
-
*
|
|
58
|
-
* @type {Object}
|
|
90
|
+
* @type {App.TOptions}
|
|
59
91
|
*/
|
|
60
92
|
this.options = options
|
|
61
93
|
|
|
62
94
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @memberof App
|
|
66
|
-
* @constant {string}
|
|
67
|
-
* @default 'main'
|
|
95
|
+
* Main namespace.
|
|
96
|
+
* @type {string}
|
|
68
97
|
*/
|
|
69
98
|
this.mainNs = 'main'
|
|
70
99
|
|
|
71
100
|
/**
|
|
72
101
|
* App environments.
|
|
73
|
-
*
|
|
74
|
-
* @memberof App
|
|
75
|
-
* @constant {TAppEnv}
|
|
102
|
+
* @type {App.TEnv}
|
|
76
103
|
*/
|
|
77
104
|
this.envs = { dev: 'development', prod: 'production' }
|
|
78
105
|
|
|
79
106
|
/**
|
|
80
107
|
* Date/time when your app start.
|
|
81
|
-
*
|
|
82
108
|
* @type {Date}
|
|
83
109
|
*/
|
|
84
110
|
this.runAt = new Date()
|
|
85
111
|
|
|
86
112
|
/**
|
|
87
113
|
* Applets container.
|
|
88
|
-
*
|
|
89
114
|
* @type {Array}
|
|
90
115
|
*/
|
|
91
116
|
this.applets = []
|
|
92
117
|
|
|
93
118
|
/**
|
|
94
|
-
* Plugin's package names container. This is the list of plugins to load.
|
|
95
|
-
*
|
|
96
|
-
* @type {Array}
|
|
119
|
+
* Plugin's package names container. This is the list of plugins to load.
|
|
120
|
+
* @type {string[]}
|
|
97
121
|
*/
|
|
98
122
|
this.pluginPkgs = options.plugins ?? []
|
|
99
123
|
|
|
100
|
-
/**
|
|
101
|
-
* @typedef {Object} TAppConfigHandler
|
|
102
|
-
* @property {string} ext - File extension.
|
|
103
|
-
* @property {function} [readHandler] - Function to call for reading.
|
|
104
|
-
* @property {function} [writeHandler] - Function to call for writing.
|
|
105
|
-
* @see App#configHandlers
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
124
|
/**
|
|
109
125
|
* Config handlers.
|
|
110
126
|
*
|
|
111
|
-
* By default, there are
|
|
112
|
-
* and
|
|
113
|
-
* lets you to use
|
|
114
|
-
*
|
|
115
|
-
* @type {TAppConfigHandler[]}
|
|
127
|
+
* By default, there are three built-in handlers: `.js`, `.json`
|
|
128
|
+
* and `.yml/.yaml`. Use plugins to add more, e.g {@link https://github.com/ardhi/bajo-config|bajo-config}
|
|
129
|
+
* lets you to use `.toml`.
|
|
130
|
+
* @type {Array<App.TConfigHandler>}
|
|
116
131
|
*/
|
|
117
132
|
this.configHandlers = []
|
|
118
133
|
|
|
@@ -120,17 +135,14 @@ class App {
|
|
|
120
135
|
* Gives you direct access to the most commonly used 3rd party library in a Bajo based app.
|
|
121
136
|
* No manual import necessary, always available, anywhere, anytime!
|
|
122
137
|
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
138
|
+
* @type {App.TLib}
|
|
139
|
+
* @example
|
|
125
140
|
* const { camelCase, kebabCase } = this.app.lib._
|
|
126
141
|
* console.log(camelCase('Elit commodo sit et aliqua'))
|
|
127
|
-
* ```
|
|
128
|
-
*
|
|
129
|
-
* @type {TAppLib}
|
|
130
142
|
*/
|
|
131
143
|
this.lib = lib
|
|
132
|
-
this.lib.outmatchNs = outmatchNs.bind(this)
|
|
133
|
-
this.lib.parseObject = parseObject.bind(this)
|
|
144
|
+
this.lib.outmatchNs = this.lib.outmatchNs.bind(this)
|
|
145
|
+
this.lib.parseObject = this.lib.parseObject.bind(this)
|
|
134
146
|
|
|
135
147
|
/**
|
|
136
148
|
* Instance of system log.
|
|
@@ -141,47 +153,47 @@ class App {
|
|
|
141
153
|
|
|
142
154
|
/**
|
|
143
155
|
* All plugin's base class are saved here as key-value pairs with plugin name as its key.
|
|
144
|
-
* The special key
|
|
145
|
-
* create your own plugin, just
|
|
156
|
+
* The special key `Base` && `Tools` is for {@link Base} & {@link Tools} class so that anytime you want to
|
|
157
|
+
* create your own plugin, you can just write something like this:
|
|
146
158
|
*
|
|
147
|
-
*
|
|
159
|
+
* `javascript
|
|
148
160
|
* class MyPlugin extends this.app.baseClass.Base {
|
|
149
161
|
* ... your class
|
|
150
162
|
* }
|
|
163
|
+
*
|
|
164
|
+
* @type {Object}
|
|
151
165
|
*/
|
|
152
166
|
this.baseClass = { Base, Tools }
|
|
153
167
|
|
|
154
168
|
/**
|
|
155
169
|
* If app runs in applet mode, this will be the applet's name.
|
|
156
|
-
*
|
|
157
170
|
* @type {string}
|
|
158
171
|
*/
|
|
159
172
|
this.applet = undefined
|
|
160
173
|
|
|
161
174
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
175
|
+
* Parsed program arguments.
|
|
176
|
+
* @type {string[]}
|
|
177
|
+
* @see module:Helper.parseArgsArgv
|
|
178
|
+
* @example
|
|
165
179
|
* $ node index.js arg1 arg2
|
|
166
180
|
* ...
|
|
167
181
|
* console.log(this.args) // it should print: ['arg1', 'arg2']
|
|
168
|
-
* ```
|
|
169
|
-
*
|
|
170
|
-
* @type {string[]}
|
|
171
|
-
* @see module:Lib.parseArgsArgv
|
|
172
182
|
*/
|
|
173
183
|
this.args = []
|
|
174
184
|
|
|
175
185
|
/**
|
|
176
|
-
*
|
|
186
|
+
* Parsed program options.
|
|
177
187
|
*
|
|
178
|
-
* - Dash (
|
|
179
|
-
* - While colon (
|
|
188
|
+
* - Dash (`-`) breaks the string into object keys
|
|
189
|
+
* - While colon (`:`) is used as namespace separator. If no namespace found, it is saved under `_` key.
|
|
180
190
|
*
|
|
181
191
|
* Values are parsed automatically. See {@link https://github.com/ladjs/dotenv-parse-variables|dotenv-parse-variables}
|
|
182
192
|
* for details.
|
|
183
193
|
*
|
|
184
|
-
*
|
|
194
|
+
* @type {Object}
|
|
195
|
+
* @see module:Helper.parseArgsArgv
|
|
196
|
+
* @example
|
|
185
197
|
* $ node index.js --my-name-first=John --my-name-last=Doe --my-birthDay=secret --nameSpace:path-subPath=true
|
|
186
198
|
* ...
|
|
187
199
|
* // {
|
|
@@ -193,38 +205,39 @@ class App {
|
|
|
193
205
|
* // },
|
|
194
206
|
* // nameSpace: { path: { subPath: true } }
|
|
195
207
|
* // }
|
|
196
|
-
* ```
|
|
197
|
-
*
|
|
198
|
-
* @type {Object}
|
|
199
|
-
* @see module:Lib.parseArgsArgv
|
|
200
208
|
*/
|
|
201
209
|
this.argv = {}
|
|
202
210
|
|
|
203
211
|
/**
|
|
204
|
-
* Environment variables. Support dotenv (
|
|
212
|
+
* Environment variables. Support dotenv (`.env`) file too!
|
|
205
213
|
*
|
|
206
|
-
* - Underscore (
|
|
207
|
-
* - Double underscores (
|
|
208
|
-
* - While dot (
|
|
214
|
+
* - Underscore (`_`) translates key to camel-cased one
|
|
215
|
+
* - Double underscores (`__`) breaks the key into object keys
|
|
216
|
+
* - While dot (`.`) is used as namespace separator. If no namespace found, it is saved under `_` key.
|
|
209
217
|
*
|
|
210
218
|
* Values are also parsed automatically using {@link https://github.com/ladjs/dotenv-parse-variables|dotenv-parse-variables}.
|
|
211
219
|
*
|
|
212
|
-
*
|
|
220
|
+
* E.g.:
|
|
213
221
|
*
|
|
214
|
-
* -
|
|
215
|
-
* -
|
|
216
|
-
* -
|
|
222
|
+
* - `MY_KEY=secret` → `{ _: { myKey: 'secret' } }`
|
|
223
|
+
* - `MY_KEY__SUB_KEY=supersecret` → `{ _: { myKey: { subKey: 'supersecret' } } }`
|
|
224
|
+
* - `MY_NS.MY_NAME=John` → `{ myNs: { myName: 'John' } }`
|
|
217
225
|
*
|
|
218
226
|
* @type {Object}
|
|
219
|
-
* @see module:
|
|
227
|
+
* @see module:Helper.parseEnv
|
|
220
228
|
*/
|
|
221
229
|
this.envVars = {}
|
|
222
230
|
|
|
223
231
|
/**
|
|
224
|
-
* Placeholder for boxen that will get imported from
|
|
232
|
+
* Placeholder for boxen that will get imported from `bajoCli` later during boot process.
|
|
233
|
+
* @type {Object}
|
|
225
234
|
*/
|
|
226
235
|
this.boxen = null
|
|
227
236
|
|
|
237
|
+
/**
|
|
238
|
+
* Cache instance. This is used to store temporary data in memory for faster access.
|
|
239
|
+
* @type {Cache}
|
|
240
|
+
*/
|
|
228
241
|
this.cache = new Cache(this)
|
|
229
242
|
|
|
230
243
|
if (!options.cwd) options.cwd = process.cwd()
|
|
@@ -287,7 +300,7 @@ class App {
|
|
|
287
300
|
*
|
|
288
301
|
* @method
|
|
289
302
|
* @param {string} name - Plugin name/namespace or alias.
|
|
290
|
-
* @param {boolean} [silent] - If
|
|
303
|
+
* @param {boolean} [silent] - If `true`, silently return undefined even on error.
|
|
291
304
|
* @returns {Object} Plugin object.
|
|
292
305
|
*/
|
|
293
306
|
getPlugin = (name, silent) => {
|
|
@@ -315,7 +328,7 @@ class App {
|
|
|
315
328
|
*
|
|
316
329
|
* @method
|
|
317
330
|
* @param {string} name - Plugin name (namespace) or alias.
|
|
318
|
-
* @param {boolean} [ensureDir=true] - Set
|
|
331
|
+
* @param {boolean} [ensureDir=true] - Set `true` (default) to ensure directory is existed.
|
|
319
332
|
* @returns {string}
|
|
320
333
|
*/
|
|
321
334
|
getPluginDataDir = (name, ensureDir = true) => {
|
|
@@ -330,8 +343,8 @@ class App {
|
|
|
330
343
|
* Resolve file path from:
|
|
331
344
|
*
|
|
332
345
|
* - local/absolute file
|
|
333
|
-
* - TNsPath (
|
|
334
|
-
* - file under node_modules, e.g.
|
|
346
|
+
* - TNsPath (`myPlugin:/path/to/file.txt`)
|
|
347
|
+
* - file under node_modules, e.g. `myPlugin:node_modules/some-package/file.txt`
|
|
335
348
|
*
|
|
336
349
|
* @method
|
|
337
350
|
* @param {string} file - File path, see above for supported types.
|
|
@@ -358,15 +371,15 @@ class App {
|
|
|
358
371
|
}
|
|
359
372
|
|
|
360
373
|
/**
|
|
361
|
-
* Dumping variable on screen. Like
|
|
374
|
+
* Dumping variable on screen. Like `console.log` with configurable options. Useful for quick debugging and testing. You can also use it to dump variables in production without worrying about performance because it is using Bajo's built-in cache to store the result of util's inspect, so it will only be processed once for each unique variable.
|
|
362
375
|
*
|
|
363
376
|
* Any argument passed to this method will be displayed on screen.
|
|
364
|
-
* If the last argument is a boolean
|
|
377
|
+
* If the last argument is a boolean `true`, app will quit rightaway after dumping.
|
|
365
378
|
*
|
|
366
|
-
* If you have
|
|
367
|
-
* Otherwise, it will fallback to
|
|
379
|
+
* If you have `bajoCli` plugin installed, variables will be displayed in a nice box using `boxen` package.
|
|
380
|
+
* Otherwise, it will fallback to `console.log` with util's inspect result.
|
|
368
381
|
*
|
|
369
|
-
* To have more control on how the variable is displayed, you can set options in Bajo's config under
|
|
382
|
+
* To have more control on how the variable is displayed, you can set options in Bajo's config under `dump` key.
|
|
370
383
|
* See {@link Bajo#config} for details.
|
|
371
384
|
*
|
|
372
385
|
* @method
|
|
@@ -393,23 +406,29 @@ class App {
|
|
|
393
406
|
}
|
|
394
407
|
|
|
395
408
|
/**
|
|
396
|
-
*
|
|
409
|
+
* Run application:
|
|
397
410
|
*
|
|
398
|
-
* - Parsing {@link module:
|
|
411
|
+
* - Parsing {@link module:Helper.parseArgsArgv|program arguments, options} and {@link module:Helper.parseEnv|environment values}
|
|
399
412
|
* - Create {@link Bajo|Bajo} instance & initialize it
|
|
400
|
-
* - {@link module:Helper/Bajo.runAsApplet|Run in applet mode} if
|
|
413
|
+
* - {@link module:Helper/Bajo.runAsApplet|Run in applet mode} if `-a` or `--applet` is given
|
|
401
414
|
*
|
|
402
|
-
* After boot process is completed, event
|
|
415
|
+
* After boot process is completed, event `bajo:afterBootCompleted` is emitted.
|
|
403
416
|
*
|
|
404
|
-
* If app mode is
|
|
417
|
+
* If app mode is `applet`, it runs your choosen applet instead.
|
|
405
418
|
*
|
|
406
|
-
* @method
|
|
407
419
|
* @async
|
|
408
|
-
* @
|
|
409
|
-
* @
|
|
420
|
+
* @method
|
|
421
|
+
* @returns {Promise<App>} App instance.
|
|
410
422
|
*/
|
|
411
|
-
|
|
423
|
+
run = async () => {
|
|
412
424
|
this.bajo = new Bajo(this)
|
|
425
|
+
this.configHandlers = [
|
|
426
|
+
{ ns: 'bajo', ext: '.js', readHandler: this.bajo.fromJs },
|
|
427
|
+
{ ns: 'bajo', ext: '.json', readHandler: this.bajo.fromJson, writeHandler: this.bajo.toJson },
|
|
428
|
+
{ ns: 'bajo', ext: '.yaml', readHandler: this.bajo.fromYaml, writeHandler: this.bajo.toYaml },
|
|
429
|
+
{ ns: 'bajo', ext: '.yml', readHandler: this.bajo.fromYml, writeHandler: this.bajo.toYml }
|
|
430
|
+
]
|
|
431
|
+
|
|
413
432
|
const hooks = (this.options.hooks ?? []).map(item => {
|
|
414
433
|
item.src = item.src ?? 'bajo'
|
|
415
434
|
return item
|
|
@@ -435,14 +454,6 @@ class App {
|
|
|
435
454
|
// boot complete
|
|
436
455
|
const elapsed = new Date() - this.runAt
|
|
437
456
|
this.bajo.log.debug('bootCompleted%s', secToHms(elapsed, true))
|
|
438
|
-
/**
|
|
439
|
-
* Run after boot process is completed
|
|
440
|
-
*
|
|
441
|
-
* @global
|
|
442
|
-
* @event bajo:afterBootComplete
|
|
443
|
-
* @see {@tutorial hook}
|
|
444
|
-
* @see App#boot
|
|
445
|
-
*/
|
|
446
457
|
await this.bajo.runHook('bajo:afterBoot')
|
|
447
458
|
if (this.applet) await runAsApplet.call(this.bajo)
|
|
448
459
|
return this
|
|
@@ -452,7 +463,7 @@ class App {
|
|
|
452
463
|
* Terminate the app and back to console.
|
|
453
464
|
*
|
|
454
465
|
* @method
|
|
455
|
-
* @param {string} [signal=SIGINT] - Signal to send.
|
|
466
|
+
* @param {string|boolean} [signal=SIGINT] - Signal to send. Set to `true` to terminate immediately without sending any signal.
|
|
456
467
|
*/
|
|
457
468
|
exit = (signal = 'SIGINT') => {
|
|
458
469
|
if (signal === true) process.exit('1')
|
|
@@ -463,7 +474,7 @@ class App {
|
|
|
463
474
|
* Load internationalization & languages files for particular plugin.
|
|
464
475
|
*
|
|
465
476
|
* @method
|
|
466
|
-
* @param {string} ns - Plugin name
|
|
477
|
+
* @param {string} ns - Plugin name (namespace)
|
|
467
478
|
*/
|
|
468
479
|
loadIntl = (ns) => {
|
|
469
480
|
const { fs } = this.lib
|
|
@@ -480,6 +491,16 @@ class App {
|
|
|
480
491
|
}
|
|
481
492
|
}
|
|
482
493
|
|
|
494
|
+
/**
|
|
495
|
+
* Prepare translation text and parameters for translation.
|
|
496
|
+
*
|
|
497
|
+
* @method
|
|
498
|
+
* @private
|
|
499
|
+
* @param {string} ns
|
|
500
|
+
* @param {string} text
|
|
501
|
+
* @param {Array} params
|
|
502
|
+
* @returns {Object}
|
|
503
|
+
*/
|
|
483
504
|
_prepTrans = (ns, text, params) => {
|
|
484
505
|
const { fallback, supported } = this.bajo.config.intl
|
|
485
506
|
const { isSet } = this.lib.aneka
|
|
@@ -517,22 +538,23 @@ class App {
|
|
|
517
538
|
}
|
|
518
539
|
|
|
519
540
|
/**
|
|
520
|
-
* Translate text and interpolate with given
|
|
541
|
+
* Translate text and interpolate with given `params`.
|
|
542
|
+
*
|
|
543
|
+
* If the last parameter is an object with `lang` key, it will use that language instead of the default one.
|
|
521
544
|
*
|
|
522
545
|
* There is a shortcut to this method attached on all plugins. You'll normally call that shorcut
|
|
523
|
-
* instead of this method, because it is bound to plugin's
|
|
546
|
+
* instead of this method, because it is bound to plugin's namespace already
|
|
524
547
|
*
|
|
525
|
-
*
|
|
548
|
+
* @method
|
|
549
|
+
* @param {string} ns - Namespace
|
|
550
|
+
* @param {string} text - Text to translate
|
|
551
|
+
* @param {...any} params - Arguments
|
|
552
|
+
* @returns {string}
|
|
553
|
+
* @example
|
|
526
554
|
* ... within your main plugin
|
|
527
555
|
* const translated = this.app.t('main', 'My cute cat is %s', 'purring')
|
|
528
|
-
* // or
|
|
556
|
+
* // or within your plugin
|
|
529
557
|
* const translated = this.t('My cute cat is %s', 'purring')
|
|
530
|
-
* ```
|
|
531
|
-
* @method
|
|
532
|
-
* @param {string} ns - Namespace.
|
|
533
|
-
* @param {string} text - Text to translate.
|
|
534
|
-
* @param {...any} params - Arguments.
|
|
535
|
-
* @returns {string}
|
|
536
558
|
*/
|
|
537
559
|
t = (ns, text, ...params) => {
|
|
538
560
|
const { formatText, isSet } = this.lib.aneka
|
|
@@ -549,11 +571,11 @@ class App {
|
|
|
549
571
|
}
|
|
550
572
|
|
|
551
573
|
/**
|
|
552
|
-
* Check whether translation text/key exists
|
|
574
|
+
* Check whether translation text/key exists.
|
|
553
575
|
*
|
|
554
576
|
* @method
|
|
555
|
-
* @param {string} ns - Namespace
|
|
556
|
-
* @param {string} text - Text to translate
|
|
577
|
+
* @param {string} ns - Namespace
|
|
578
|
+
* @param {string} text - Text to translate
|
|
557
579
|
* @returns {boolean}
|
|
558
580
|
*/
|
|
559
581
|
te = (ns, text, ...params) => {
|
|
@@ -565,7 +587,7 @@ class App {
|
|
|
565
587
|
* Helper method to list all supported config formats.
|
|
566
588
|
*
|
|
567
589
|
* @method
|
|
568
|
-
* @param {boolean} [noDot] - If
|
|
590
|
+
* @param {boolean} [noDot] - If `true`, it will return the list without dot prefix
|
|
569
591
|
* @returns {string[]}
|
|
570
592
|
*/
|
|
571
593
|
getConfigFormats = (noDot) => {
|
|
@@ -576,8 +598,9 @@ class App {
|
|
|
576
598
|
/**
|
|
577
599
|
* Start a plugin.
|
|
578
600
|
*
|
|
601
|
+
* @method
|
|
579
602
|
* @param {string} ns - Plugin namespace.
|
|
580
|
-
* @param {...any} args - Arguments to pass to the plugin's start method
|
|
603
|
+
* @param {...any} args - Arguments to pass to the plugin's start method
|
|
581
604
|
*/
|
|
582
605
|
startPlugin = (ns, ...args) => {
|
|
583
606
|
this[ns].start(...args)
|
|
@@ -586,8 +609,9 @@ class App {
|
|
|
586
609
|
/**
|
|
587
610
|
* Stop a plugin.
|
|
588
611
|
*
|
|
612
|
+
* @method
|
|
589
613
|
* @param {string} ns - Plugin namespace.
|
|
590
|
-
* @param {...any} args - Arguments to pass to the plugin's stop method
|
|
614
|
+
* @param {...any} args - Arguments to pass to the plugin's stop method
|
|
591
615
|
*/
|
|
592
616
|
stopPlugin = (ns, ...args) => {
|
|
593
617
|
// Disabled for now, reserved for future use. It is not a good idea to stop a plugin because other plugins might be dependent on it.
|
|
@@ -596,4 +620,4 @@ class App {
|
|
|
596
620
|
}
|
|
597
621
|
|
|
598
622
|
export default App
|
|
599
|
-
</code></pre></article></section></div></div></div><div class="search-container" id="PkfLWpAbet" style="display:none"><div class="wrapper" id="iCxFxjkHbP"><button class="icon-button search-close-button" id="VjLlGakifb" aria-label="close search"><svg><use xlink:href="#close-icon"></use></svg></button><div class="search-box-c"><svg><use xlink:href="#search-icon"></use></svg> <input type="text" id="vpcKVYIppa" class="search-input" placeholder="Search..." autofocus></div><div class="search-result-c" id="fWwVHRuDuN"><span class="search-result-c-text">Type anything to view search result</span></div></div></div><div class="mobile-menu-icon-container"><button class="icon-button" id="mobile-menu" data-isopen="false" aria-label="menu"><svg><use xlink:href="#menu-icon"></use></svg></button></div><div id="mobile-sidebar" class="mobile-sidebar-container"><div class="mobile-sidebar-wrapper"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo API</a><div class="mobile-nav-links"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div><div class="navbar-item"><a id="" href="https://bajo.app" target="">Bajo</a></div></div><div class="mobile-sidebar-items-c"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="App.html">App</a></div><div class="sidebar-section-children"><a href="Bajo.html">Bajo</a></div><div class="sidebar-section-children"><a href="Base.html">Base</a></div><div class="sidebar-section-children"><a href="Cache.html">Cache</a></div><div class="sidebar-section-children"><a href="Err.html">Err</a></div><div class="sidebar-section-children"><a href="Log.html">Log</a></div><div class="sidebar-section-children"><a href="Plugin.html">Plugin</a></div><div class="sidebar-section-children"><a href="Print.html">Print</a></div><div class="sidebar-section-children"><a href="Tools.html">Tools</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-
|
|
623
|
+
</code></pre></article></section></div></div></div><div class="search-container" id="PkfLWpAbet" style="display:none"><div class="wrapper" id="iCxFxjkHbP"><button class="icon-button search-close-button" id="VjLlGakifb" aria-label="close search"><svg><use xlink:href="#close-icon"></use></svg></button><div class="search-box-c"><svg><use xlink:href="#search-icon"></use></svg> <input type="text" id="vpcKVYIppa" class="search-input" placeholder="Search..." autofocus></div><div class="search-result-c" id="fWwVHRuDuN"><span class="search-result-c-text">Type anything to view search result</span></div></div></div><div class="mobile-menu-icon-container"><button class="icon-button" id="mobile-menu" data-isopen="false" aria-label="menu"><svg><use xlink:href="#menu-icon"></use></svg></button></div><div id="mobile-sidebar" class="mobile-sidebar-container"><div class="mobile-sidebar-wrapper"><a href="/" class="sidebar-title sidebar-title-anchor">Bajo API</a><div class="mobile-nav-links"><div class="navbar-item"><a id="" href="https://www.npmjs.com/package/bajo" target="">NPM</a></div><div class="navbar-item"><a id="" href="https://github.com/ardhi/bajo" target="">Github</a></div><div class="navbar-item"><a id="" href="https://bajo.app" target="">Bajo</a></div></div><div class="mobile-sidebar-items-c"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="App.html">App</a></div><div class="sidebar-section-children"><a href="Bajo.html">Bajo</a></div><div class="sidebar-section-children"><a href="Base.html">Base</a></div><div class="sidebar-section-children"><a href="Cache.html">Cache</a></div><div class="sidebar-section-children"><a href="Err.html">Err</a></div><div class="sidebar-section-children"><a href="Log.html">Log</a></div><div class="sidebar-section-children"><a href="Plugin.html">Plugin</a></div><div class="sidebar-section-children"><a href="Print.html">Print</a></div><div class="sidebar-section-children"><a href="Tools.html">Tools</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-modules"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="module-Helper.html">Helper</a></div><div class="sidebar-section-children"><a href="module-Hook.html">Hook</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-global"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#boot">boot</a></div></div></div><div class="mobile-navbar-actions"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#dark-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div></div></div><script type="text/javascript" src="scripts/core.min.js"></script><script src="scripts/search.min.js" defer="defer"></script><script src="scripts/third-party/fuse.js" defer="defer"></script><script type="text/javascript">var tocbotInstance=tocbot.init({tocSelector:"#eed4d2a0bfd64539bb9df78095dec881",contentSelector:".main-content",headingSelector:"h1, h2, h3",hasInnerContainers:!0,scrollContainer:".main-content",headingsOffset:130,onClick:bringLinkToView})</script></body></html>
|