54 lines
1.4 KiB
Plaintext
54 lines
1.4 KiB
Plaintext
import { matchIconName } from '../icon/name.mjs';
|
|
import { defaultIconDimensions, defaultExtendedIconProps } from '../icon/defaults.mjs';
|
|
|
|
const optionalPropertyDefaults = {
|
|
provider: "",
|
|
aliases: {},
|
|
not_found: {},
|
|
...defaultIconDimensions
|
|
};
|
|
function checkOptionalProps(item, defaults) {
|
|
for (const prop in defaults) {
|
|
if (prop in item && typeof item[prop] !== typeof defaults[prop]) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
function quicklyValidateIconSet(obj) {
|
|
if (typeof obj !== "object" || obj === null) {
|
|
return null;
|
|
}
|
|
const data = obj;
|
|
if (typeof data.prefix !== "string" || !obj.icons || typeof obj.icons !== "object") {
|
|
return null;
|
|
}
|
|
if (!checkOptionalProps(obj, optionalPropertyDefaults)) {
|
|
return null;
|
|
}
|
|
const icons = data.icons;
|
|
for (const name in icons) {
|
|
const icon = icons[name];
|
|
if (!name.match(matchIconName) || typeof icon.body !== "string" || !checkOptionalProps(
|
|
icon,
|
|
defaultExtendedIconProps
|
|
)) {
|
|
return null;
|
|
}
|
|
}
|
|
const aliases = data.aliases || /* @__PURE__ */ Object.create(null);
|
|
for (const name in aliases) {
|
|
const icon = aliases[name];
|
|
const parent = icon.parent;
|
|
if (!name.match(matchIconName) || typeof parent !== "string" || !icons[parent] && !aliases[parent] || !checkOptionalProps(
|
|
icon,
|
|
defaultExtendedIconProps
|
|
)) {
|
|
return null;
|
|
}
|
|
}
|
|
return data;
|
|
}
|
|
|
|
export { quicklyValidateIconSet };
|