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

54 строки
1.4 KiB

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