index.cjs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. const fs = require('fs');
  3. const url = require('url');
  4. const pathe = require('pathe');
  5. /**
  6. * This file is part of the iconify.design libraries.
  7. *
  8. * (c) Vjacheslav Trushkin <cyberalien@gmail.com>
  9. *
  10. * @license MIT
  11. *
  12. * For the full copyright and license information, please view the license.txt
  13. * file that is available in this file's directory.
  14. */
  15. const _dirname = typeof __dirname !== "undefined" ? __dirname : pathe.dirname(url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href))));
  16. const dir = pathe.join(_dirname, "/..");
  17. const locate = (name) => pathe.join(dir, `./json/${name}.json`);
  18. const loadCollection = async (path) => {
  19. return JSON.parse(await fs.promises.readFile(path, "utf8"));
  20. };
  21. const lookupCollection = async (name) => {
  22. return await loadCollection(locate(name));
  23. };
  24. const lookupCollections = async () => {
  25. return JSON.parse(
  26. await fs.promises.readFile(pathe.join(dir, "./collections.json"), "utf8")
  27. );
  28. };
  29. exports.loadCollection = loadCollection;
  30. exports.locate = locate;
  31. exports.lookupCollection = lookupCollection;
  32. exports.lookupCollections = lookupCollections;