@iconify/vue
Advanced tools
Comparing version 3.2.0 to 3.2.1
@@ -55,4 +55,5 @@ (function (global, factory) { | ||
} | ||
if (data.aliases?.[name2] !== void 0) { | ||
const item = data.aliases?.[name2]; | ||
const aliases = data.aliases; | ||
if (aliases && aliases[name2] !== void 0) { | ||
const item = aliases[name2]; | ||
const result2 = getIcon(item.parent, iteration + 1); | ||
@@ -64,4 +65,5 @@ if (result2) { | ||
} | ||
if (iteration === 0 && data.chars?.[name2] !== void 0) { | ||
return getIcon(data.chars?.[name2], iteration + 1); | ||
const chars = data.chars; | ||
if (!iteration && chars && chars[name2] !== void 0) { | ||
return getIcon(chars[name2], iteration + 1); | ||
} | ||
@@ -81,218 +83,2 @@ return null; | ||
const matchChar = /^[a-f0-9]+(-[a-f0-9]+)*$/; | ||
function validateIconProps(item, fix) { | ||
for (const key in item) { | ||
const attr = key; | ||
const value = item[attr]; | ||
const type = typeof value; | ||
if (type === "undefined") { | ||
delete item[attr]; | ||
continue; | ||
} | ||
switch (key) { | ||
case "body": | ||
case "parent": | ||
if (type !== "string") { | ||
return key; | ||
} | ||
break; | ||
case "hFlip": | ||
case "vFlip": | ||
case "hidden": | ||
if (type !== "boolean") { | ||
if (fix) { | ||
delete item[attr]; | ||
} else { | ||
return key; | ||
} | ||
} | ||
break; | ||
case "width": | ||
case "height": | ||
case "left": | ||
case "top": | ||
case "rotate": | ||
case "inlineHeight": | ||
case "inlineTop": | ||
case "verticalAlign": | ||
if (type !== "number") { | ||
if (fix) { | ||
delete item[attr]; | ||
} else { | ||
return key; | ||
} | ||
} | ||
break; | ||
default: | ||
if (type === "object") { | ||
if (fix) { | ||
delete item[attr]; | ||
} else { | ||
return key; | ||
} | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
function validateIconSet(obj, options) { | ||
const fix = !!options?.fix; | ||
if (typeof obj !== "object" || obj === null || typeof obj.icons !== "object" || !obj.icons) { | ||
throw new Error("Bad icon set"); | ||
} | ||
const data = obj; | ||
if (typeof options?.prefix === "string") { | ||
data.prefix = options.prefix; | ||
} else if (typeof data.prefix !== "string" || !data.prefix.match(matchName)) { | ||
throw new Error("Invalid prefix"); | ||
} | ||
if (typeof options?.provider === "string") { | ||
data.provider = options.provider; | ||
} else if (data.provider !== void 0) { | ||
const value = data.provider; | ||
if (typeof value !== "string" || value !== "" && !value.match(matchName)) { | ||
if (fix) { | ||
delete data.provider; | ||
} else { | ||
throw new Error("Invalid provider"); | ||
} | ||
} | ||
} | ||
const icons = data.icons; | ||
Object.keys(icons).forEach((name) => { | ||
if (!name.match(matchName)) { | ||
if (fix) { | ||
delete icons[name]; | ||
return; | ||
} | ||
throw new Error(`Invalid icon name: "${name}"`); | ||
} | ||
const item = icons[name]; | ||
if (typeof item !== "object" || item === null || typeof item.body !== "string") { | ||
if (fix) { | ||
delete icons[name]; | ||
return; | ||
} | ||
throw new Error(`Invalid icon: "${name}"`); | ||
} | ||
const key = typeof item.parent === "string" ? "parent" : validateIconProps(item, fix); | ||
if (key !== null) { | ||
if (fix) { | ||
delete icons[name]; | ||
return; | ||
} | ||
throw new Error(`Invalid property "${key}" in icon "${name}"`); | ||
} | ||
}); | ||
if (data.not_found !== void 0 && !(data.not_found instanceof Array)) { | ||
if (fix) { | ||
delete data.not_found; | ||
} else { | ||
throw new Error("Invalid not_found list"); | ||
} | ||
} | ||
if (!Object.keys(data.icons).length && !data.not_found?.length) { | ||
throw new Error("Icon set is empty"); | ||
} | ||
if (data.aliases !== void 0) { | ||
if (typeof data.aliases !== "object" || data.aliases === null) { | ||
if (fix) { | ||
delete data.aliases; | ||
} else { | ||
throw new Error("Invalid aliases list"); | ||
} | ||
} | ||
} | ||
if (typeof data.aliases === "object") { | ||
let validateAlias = function(name, iteration) { | ||
if (validatedAliases.has(name)) { | ||
return !failedAliases.has(name); | ||
} | ||
const item = aliases[name]; | ||
if (iteration > 5 || typeof item !== "object" || item === null || typeof item.parent !== "string" || !name.match(matchName)) { | ||
if (fix) { | ||
delete aliases[name]; | ||
failedAliases.add(name); | ||
return false; | ||
} | ||
throw new Error(`Invalid icon alias: "${name}"`); | ||
} | ||
const parent = item.parent; | ||
if (data.icons[parent] === void 0) { | ||
if (aliases[parent] === void 0 || !validateAlias(parent, iteration + 1)) { | ||
if (fix) { | ||
delete aliases[name]; | ||
failedAliases.add(name); | ||
return false; | ||
} | ||
throw new Error(`Missing parent icon for alias "${name}`); | ||
} | ||
} | ||
if (fix && item.body !== void 0) { | ||
delete item.body; | ||
} | ||
const key = item.body !== void 0 ? "body" : validateIconProps(item, fix); | ||
if (key !== null) { | ||
if (fix) { | ||
delete aliases[name]; | ||
failedAliases.add(name); | ||
return false; | ||
} | ||
throw new Error(`Invalid property "${key}" in alias "${name}"`); | ||
} | ||
validatedAliases.add(name); | ||
return true; | ||
}; | ||
const aliases = data.aliases; | ||
const validatedAliases = new Set(); | ||
const failedAliases = new Set(); | ||
Object.keys(aliases).forEach((name) => { | ||
validateAlias(name, 0); | ||
}); | ||
if (fix && !Object.keys(data.aliases).length) { | ||
delete data.aliases; | ||
} | ||
} | ||
Object.keys(iconDefaults).forEach((prop) => { | ||
const expectedType = typeof iconDefaults[prop]; | ||
const actualType = typeof data[prop]; | ||
if (actualType !== "undefined" && actualType !== expectedType) { | ||
throw new Error(`Invalid value type for "${prop}"`); | ||
} | ||
}); | ||
if (data.chars !== void 0) { | ||
if (typeof data.chars !== "object" || data.chars === null) { | ||
if (fix) { | ||
delete data.chars; | ||
} else { | ||
throw new Error("Invalid characters map"); | ||
} | ||
} | ||
} | ||
if (typeof data.chars === "object") { | ||
const chars = data.chars; | ||
Object.keys(chars).forEach((char) => { | ||
if (!matchChar.exec(char) || typeof chars[char] !== "string") { | ||
if (fix) { | ||
delete chars[char]; | ||
return; | ||
} | ||
throw new Error(`Invalid character "${char}"`); | ||
} | ||
const target = chars[char]; | ||
if (data.icons[target] === void 0 && data.aliases?.[target] === void 0) { | ||
if (fix) { | ||
delete chars[char]; | ||
return; | ||
} | ||
throw new Error(`Character "${char}" points to missing icon "${target}"`); | ||
} | ||
}); | ||
if (fix && !Object.keys(data.chars).length) { | ||
delete data.chars; | ||
} | ||
} | ||
return data; | ||
} | ||
function isVariation(item) { | ||
@@ -312,10 +98,2 @@ for (const key in iconDefaults) { | ||
} | ||
const validate = options.validate; | ||
if (validate !== false) { | ||
try { | ||
validateIconSet(data, typeof validate === "object" ? validate : { fix: true }); | ||
} catch (err) { | ||
return names; | ||
} | ||
} | ||
if (data.not_found instanceof Array) { | ||
@@ -352,2 +130,53 @@ data.not_found.forEach((name) => { | ||
const optionalProperties = { | ||
provider: "string", | ||
aliases: "object", | ||
not_found: "object" | ||
}; | ||
for (const prop in iconDefaults) { | ||
optionalProperties[prop] = typeof iconDefaults[prop]; | ||
} | ||
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; | ||
} | ||
for (const prop in optionalProperties) { | ||
if (obj[prop] !== void 0 && typeof obj[prop] !== optionalProperties[prop]) { | ||
return null; | ||
} | ||
} | ||
const icons = data.icons; | ||
for (const name in icons) { | ||
const icon = icons[name]; | ||
if (!name.match(matchName) || typeof icon.body !== "string") { | ||
return null; | ||
} | ||
for (const prop in iconDefaults) { | ||
if (icon[prop] !== void 0 && typeof icon[prop] !== typeof iconDefaults[prop]) { | ||
return null; | ||
} | ||
} | ||
} | ||
const aliases = data.aliases; | ||
if (aliases) { | ||
for (const name in aliases) { | ||
const icon = aliases[name]; | ||
const parent = icon.parent; | ||
if (!name.match(matchName) || typeof parent !== "string" || !icons[parent] && !aliases[parent]) { | ||
return null; | ||
} | ||
for (const prop in iconDefaults) { | ||
if (icon[prop] !== void 0 && typeof icon[prop] !== typeof iconDefaults[prop]) { | ||
return null; | ||
} | ||
} | ||
} | ||
} | ||
return data; | ||
} | ||
const defaults = Object.freeze({ | ||
@@ -829,13 +658,8 @@ inline: false, | ||
: ''; | ||
parseIconSet(data, (name, icon) => { | ||
if (icon) { | ||
storage[iconPrefix + name] = icon; | ||
} | ||
}, { | ||
// Allow empty prefix | ||
validate: { | ||
fix: true, | ||
prefix: iconPrefix, | ||
}, | ||
}); | ||
quicklyValidateIconSet(data) && | ||
parseIconSet(data, (name, icon) => { | ||
if (icon) { | ||
storage[iconPrefix + name] = icon; | ||
} | ||
}); | ||
} | ||
@@ -842,0 +666,0 @@ /** |
@@ -5,3 +5,3 @@ { | ||
"author": "Vjacheslav Trushkin", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"license": "MIT", | ||
@@ -47,4 +47,4 @@ "bugs": "https://github.com/iconify/iconify/issues", | ||
"@babel/preset-env": "^7.16.11", | ||
"@iconify/core": "^1.3.0", | ||
"@microsoft/api-extractor": "^7.19.4", | ||
"@iconify/core": "^1.3.2", | ||
"@microsoft/api-extractor": "^7.19.5", | ||
"@rollup/plugin-node-resolve": "^13.1.3", | ||
@@ -55,6 +55,6 @@ "@types/jest": "^27.4.1", | ||
"jsdom": "^19.0.0", | ||
"rollup": "^2.66.0", | ||
"typescript": "^4.5.5", | ||
"vitest": "^0.7.6", | ||
"vue": "3" | ||
"rollup": "^2.70.1", | ||
"typescript": "^4.6.2", | ||
"vitest": "^0.7.7", | ||
"vue": "^3.2.31" | ||
}, | ||
@@ -61,0 +61,0 @@ "peerDependencies": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
202530
11
6304