1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-11-16 00:59:07 +02:00

Don't enumerate the get method (#1555)

* Test that all elements when iterating simpleIcons are objects

* Refactor index template to hide .get method from enumeration
This commit is contained in:
Eric Cornelissen 2019-07-24 20:17:46 +01:00 committed by Johan Fagerberg
parent 0c275b7173
commit b1b2f339b8
2 changed files with 24 additions and 12 deletions

View File

@ -1,17 +1,21 @@
var icons = {%s};
module.exports = icons;
module.exports.get = function(targetName) {
if (icons[targetName]) {
return icons[targetName];
} else {
var normalizedName = targetName.toLowerCase();
for (var iconName in icons) {
var icon = icons[iconName];
if ((icon.title && icon.title.toLowerCase() === normalizedName)
|| (icon.slug && icon.slug === normalizedName)) {
return icon;
Object.defineProperty(icons, "get", {
enumerate: false,
value: function(targetName) {
if (icons[targetName]) {
return icons[targetName];
} else {
var normalizedName = targetName.toLowerCase();
for (var iconName in icons) {
var icon = icons[iconName];
if ((icon.title && icon.title.toLowerCase() === normalizedName)
|| (icon.slug && icon.slug === normalizedName)) {
return icon;
}
}
}
}
}
});
module.exports = icons;

View File

@ -44,3 +44,11 @@ icons.forEach(icon => {
expect(found.title).toEqual(icon.title);
});
});
test(`Iterating over simpleIcons only exposes icons`, () => {
const iconArray = Object.values(simpleIcons);
for (let icon of iconArray) {
expect(icon).toBeDefined();
expect(typeof icon).toBe('object');
}
});