This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env gjs | |
| (function (Gtk){'use strict'; | |
| Gtk.init(null); | |
| const | |
| win = new Gtk.Window({ | |
| type : Gtk.WindowType.TOPLEVEL, | |
| window_position: Gtk.WindowPosition.CENTER | |
| }) | |
| ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // base64.decode(base64.encode('💩')); | |
| // Browsers | |
| const base64 = { | |
| encode: str => btoa(unescape(encodeURIComponent(str))), | |
| decode: str => decodeURIComponent(escape(atob(str))) | |
| }; | |
| /* ES3 compat version | |
| var base64 = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ./components/form-secure.js | |
| const components = [ | |
| 'input-credit-card', | |
| 'input-human' | |
| ]; | |
| export default new Promise(async $export => { | |
| // import all required sub components | |
| await Promise.all(components.map( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // keeping the same pattern | |
| export default await new Promise(async $export => { | |
| // export the module | |
| $export({my: 'module'}); | |
| }); | |
| // dropping the Promise all together | |
| export default await (async () => { | |
| // await async dependencies | |
| // export the module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // grab the importer | |
| import imports from './imports.js'; | |
| // export through the same pattern | |
| export default new Promise(async $export => { | |
| // grab many modules at once | |
| const [a, b] = await imports( | |
| import('./a.js'), | |
| import('./b.js') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ES2017 version | |
| export default (...modules) => Promise.all( | |
| // flatten arguments to enable both | |
| // imports([m1, m2]) or imports(m1, m2) | |
| modules.concat.apply([], modules) | |
| // asynchronously await each module | |
| // and return its default | |
| .map(async m => (await m).default) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // CommonJS consumer and/or importer | |
| module.exports = new Promise(async $export => { | |
| const module = await require('./module'); | |
| $export({module, method(){}}); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ES2017 Asynchronous Export | |
| // module.js | |
| export default new Promise(async $export => { | |
| const module = await Promise.resolve( | |
| {my: 'module'} | |
| ); | |
| $export(module); | |
| }); | |
| // - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default new Promise(async $export => { | |
| // await anything that needs to be imported | |
| // await anything that asynchronous | |
| // finally export the module resolving the Promise | |
| // as object, function, class, ... anything | |
| $export( | |
| {module: 'object'} || | |
| function () {} || | |
| class Anything {} | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <!-- all it takes, you could also use unpkg: | |
| https://unpkg.com/import.js@latest --> | |
| <script src="import.js" | |
| data-main="js/main.js" | |
| ></script> |