Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
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.

esm-utils.js 974B

12345678910111213141516171819202122232425262728293031
  1. const url = require('url');
  2. const path = require('path');
  3. const requireOrImport = async file => {
  4. file = path.resolve(file);
  5. if (path.extname(file) === '.mjs') {
  6. return import(url.pathToFileURL(file));
  7. }
  8. // This is currently the only known way of figuring out whether a file is CJS or ESM.
  9. // If Node.js or the community establish a better procedure for that, we can fix this code.
  10. // Another option here would be to always use `import()`, as this also supports CJS, but I would be
  11. // wary of using it for _all_ existing test files, till ESM is fully stable.
  12. try {
  13. return require(file);
  14. } catch (err) {
  15. if (err.code === 'ERR_REQUIRE_ESM') {
  16. return import(url.pathToFileURL(file));
  17. } else {
  18. throw err;
  19. }
  20. }
  21. };
  22. exports.loadFilesAsync = async (files, preLoadFunc, postLoadFunc) => {
  23. for (const file of files) {
  24. preLoadFunc(file);
  25. const result = await requireOrImport(file);
  26. postLoadFunc(file, result);
  27. }
  28. };