mirror of
				https://github.com/Mibew/simple-icons.git
				synced 2025-10-31 02:25:59 +03: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:
		
							parent
							
								
									0c275b7173
								
							
						
					
					
						commit
						b1b2f339b8
					
				| @ -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; | ||||
|  | ||||
| @ -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'); | ||||
|   } | ||||
| }); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user