版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

56 строки
1.5 KiB

  1. 'use strict';
  2. const icon_name = require('../icon/name.cjs');
  3. const icon_defaults = require('../icon/defaults.cjs');
  4. const optionalPropertyDefaults = {
  5. provider: "",
  6. aliases: {},
  7. not_found: {},
  8. ...icon_defaults.defaultIconDimensions
  9. };
  10. function checkOptionalProps(item, defaults) {
  11. for (const prop in defaults) {
  12. if (prop in item && typeof item[prop] !== typeof defaults[prop]) {
  13. return false;
  14. }
  15. }
  16. return true;
  17. }
  18. function quicklyValidateIconSet(obj) {
  19. if (typeof obj !== "object" || obj === null) {
  20. return null;
  21. }
  22. const data = obj;
  23. if (typeof data.prefix !== "string" || !obj.icons || typeof obj.icons !== "object") {
  24. return null;
  25. }
  26. if (!checkOptionalProps(obj, optionalPropertyDefaults)) {
  27. return null;
  28. }
  29. const icons = data.icons;
  30. for (const name in icons) {
  31. const icon = icons[name];
  32. if (!name.match(icon_name.matchIconName) || typeof icon.body !== "string" || !checkOptionalProps(
  33. icon,
  34. icon_defaults.defaultExtendedIconProps
  35. )) {
  36. return null;
  37. }
  38. }
  39. const aliases = data.aliases || /* @__PURE__ */ Object.create(null);
  40. for (const name in aliases) {
  41. const icon = aliases[name];
  42. const parent = icon.parent;
  43. if (!name.match(icon_name.matchIconName) || typeof parent !== "string" || !icons[parent] && !aliases[parent] || !checkOptionalProps(
  44. icon,
  45. icon_defaults.defaultExtendedIconProps
  46. )) {
  47. return null;
  48. }
  49. }
  50. return data;
  51. }
  52. exports.quicklyValidateIconSet = quicklyValidateIconSet;