parse.cjs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use strict';
  2. const iconSet_getIcon = require('./get-icon.cjs');
  3. const iconSet_tree = require('./tree.cjs');
  4. require('../icon/merge.cjs');
  5. require('../icon/defaults.cjs');
  6. require('../icon/transformations.cjs');
  7. function parseIconSet(data, callback) {
  8. const names = [];
  9. if (typeof data !== "object" || typeof data.icons !== "object") {
  10. return names;
  11. }
  12. if (data.not_found instanceof Array) {
  13. data.not_found.forEach((name) => {
  14. callback(name, null);
  15. names.push(name);
  16. });
  17. }
  18. const tree = iconSet_tree.getIconsTree(data);
  19. for (const name in tree) {
  20. const item = tree[name];
  21. if (item) {
  22. callback(name, iconSet_getIcon.internalGetIconData(data, name, item));
  23. names.push(name);
  24. }
  25. }
  26. return names;
  27. }
  28. async function parseIconSetAsync(data, callback) {
  29. const names = [];
  30. if (typeof data !== "object" || typeof data.icons !== "object") {
  31. return names;
  32. }
  33. if (data.not_found instanceof Array) {
  34. for (let i = 0; i < data.not_found.length; i++) {
  35. const name = data.not_found[i];
  36. await callback(name, null);
  37. names.push(name);
  38. }
  39. }
  40. const tree = iconSet_tree.getIconsTree(data);
  41. for (const name in tree) {
  42. const item = tree[name];
  43. if (item) {
  44. await callback(name, iconSet_getIcon.internalGetIconData(data, name, item));
  45. names.push(name);
  46. }
  47. }
  48. return names;
  49. }
  50. exports.parseIconSet = parseIconSet;
  51. exports.parseIconSetAsync = parseIconSetAsync;