index.mjs 981 B

123456789101112131415161718192021222324252627282930
  1. import { promises } from 'fs';
  2. import { fileURLToPath } from 'url';
  3. import { dirname, join } from 'pathe';
  4. /**
  5. * This file is part of the iconify.design libraries.
  6. *
  7. * (c) Vjacheslav Trushkin <cyberalien@gmail.com>
  8. *
  9. * @license MIT
  10. *
  11. * For the full copyright and license information, please view the license.txt
  12. * file that is available in this file's directory.
  13. */
  14. const _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
  15. const dir = join(_dirname, "/..");
  16. const locate = (name) => join(dir, `./json/${name}.json`);
  17. const loadCollection = async (path) => {
  18. return JSON.parse(await promises.readFile(path, "utf8"));
  19. };
  20. const lookupCollection = async (name) => {
  21. return await loadCollection(locate(name));
  22. };
  23. const lookupCollections = async () => {
  24. return JSON.parse(
  25. await promises.readFile(join(dir, "./collections.json"), "utf8")
  26. );
  27. };
  28. export { loadCollection, locate, lookupCollection, lookupCollections };