Gathering detailed insights and metrics for @iconify/json
Gathering detailed insights and metrics for @iconify/json
Gathering detailed insights and metrics for @iconify/json
Gathering detailed insights and metrics for @iconify/json
150+ open source icon sets. Icons are validated, cleaned up, optimised, ready to render as SVG. Updated automatically 3 times a week.
npm install @iconify/json
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
665 Stars
1,151 Commits
64 Forks
12 Watching
2 Branches
4 Contributors
Updated on 27 Nov 2024
TypeScript (63.67%)
PHP (19.61%)
JavaScript (16.72%)
Cumulative downloads
Total Downloads
Last day
0.2%
18,894
Compared to previous day
Last week
-2.6%
107,320
Compared to previous week
Last month
7%
468,531
Compared to previous month
Last year
94.7%
4,264,013
Compared to previous year
2
This is a big collection of open source vector icons, all validated, cleaned up and converted to the same easy to use format.
Even though all icon sets are open source, some icon sets require attribution.
See collections.md for list of icon sets and their licenses.
All icons have been processed with Iconify Tools to clean them up.
Icon parsing process includes:
currentColor
, making it easy to change icon color by changing text color.This repository is automatically updated several times a week, so it always contains the latest icons for all icon sets.
Icon sets are stored in IconifyJSON
format. TypeScript definition is available in @iconify/types
package. Documentation is available on Iconify Documentation website.
To work with icon sets, use Iconify Utils. Utils package works in any JavaScript environment: Node.js, Deno, browsers, isolated JavaScript environments.
These icons can be used with many tools, plugins and components. They can also be exported as individual SVG files.
See Iconify documentation for more details.
Instructions below are for Node.js and PHP projects.
Run this command to add icons to your project:
1npm install --save @iconify/json
Icons will be available in node_modules/@iconify/json
To resolve filename for any json file, use this if you are using CommonJS syntax:
1import { locate } from '@iconify/json'; 2 3// returns location of mdi-light.json 4const mdiLightFilename = locate('mdi-light');
Install and initialize Composer project. See documentation at https://getcomposer.org
Then open composer.json and add following code:
1"require": { 2 "php": ">=5.6", 3 "iconify/json": "*" 4}
then run:
1composer install
Icons will be available in vendor/iconify/json/
If you don't use Composer, clone GitHub repository and add necessary autoload code.
To resolve filename for any json file, use this:
1// Returns location of mdi-light.json 2$mdiLightLocation = \Iconify\IconsJSON\Finder::locate('mdi-light');
Icons used by Iconify are in directory json, in Iconify JSON format.
Why JSON instead of SVG? There are several reasons for that:
<svg>
element, making it easy to manipulate content without doing complex parsing. It also makes it easier to create components, such as React icon component, allowing to use framework native SVG element.Why not XML?
Format of json file is very simple:
1{ 2 "prefix": "mdi-light", 3 "icons": { 4 "icon-name": { 5 "body": "<g />", 6 "width": 24, 7 "height": 24 8 } 9 }, 10 "aliases": { 11 "icon-alias": { 12 "parent": "icon-name" 13 } 14 } 15}
"icons" object contains list of all icons.
Each icon has following properties:
Optional "aliases" object contains list of aliases for icons. Format is similar to "icons" object, but without "body" property and with additional property "parent" that points to parent icon. Transformation properties (rotate, hFlip, vFlip) are merged with parent icon's properties. Any other properties overwrite properties of parent icon.
When multiple icons have the same value, it is moved to root object to reduce duplication:
1{ 2 "prefix": "mdi-light", 3 "icons": { 4 "icon1": { 5 "body": "<g />" 6 }, 7 "icon2": { 8 "body": "<g />" 9 }, 10 "icon-20": { 11 "body": "<g />", 12 "width": 20, 13 "height": 20 14 } 15 }, 16 "width": 24, 17 "height": 24 18}
In example above, "icon1" and "icon2" are 24x24, "icon-20" is 20x20.
For more information see developer documentation on https://iconify.design/docs/types/iconify-json.html
You can use Iconify Utils for simple export process or Iconify Tools for more options.
Example using Iconify Utils (TypeScript):
1import { promises as fs } from 'fs'; 2 3// Function to locate JSON file 4import { locate } from '@iconify/json'; 5 6// Various functions from Iconify Utils 7import { parseIconSet } from '@iconify/utils/lib/icon-set/parse'; 8import { iconToSVG } from '@iconify/utils/lib/svg/build'; 9import { defaults } from '@iconify/utils/lib/customisations'; 10 11(async () => { 12 // Locate icons 13 const filename = locate('mdi'); 14 15 // Load icon set 16 const icons = JSON.parse(await fs.readFile(filename, 'utf8')); 17 18 // Parse all icons 19 const exportedSVG: Record<string, string> = Object.create(null); 20 parseIconSet(icons, (iconName, iconData) => { 21 if (!iconData) { 22 // Invalid icon 23 console.error(`Error parsing icon ${iconName}`); 24 return; 25 } 26 27 // Render icon 28 const renderData = iconToSVG(iconData, { 29 ...defaults, 30 height: 'auto', 31 }); 32 33 // Generate attributes for SVG element 34 const svgAttributes: Record<string, string> = { 35 'xmlns': 'http://www.w3.org/2000/svg', 36 'xmlns:xlink': 'http://www.w3.org/1999/xlink', 37 ...renderData.attributes, 38 }; 39 const svgAttributesStr = Object.keys(svgAttributes) 40 .map( 41 (attr) => 42 // No need to check attributes for special characters, such as quotes, 43 // they cannot contain anything that needs escaping. 44 `${attr}="${svgAttributes[attr as keyof typeof svgAttributes]}"` 45 ) 46 .join(' '); 47 48 // Generate SVG 49 const svg = `<svg ${svgAttributesStr}>${renderData.body}</svg>`; 50 exportedSVG[iconName] = svg; 51 }); 52 53 // Output directory 54 const outputDir = 'mdi-export'; 55 try { 56 await fs.mkdir(outputDir, { 57 recursive: true, 58 }); 59 } catch (err) { 60 // 61 } 62 63 // Save all files 64 const filenames = Object.keys(exportedSVG); 65 for (let i = 0; i < filenames.length; i++) { 66 const filename = filenames[i]; 67 const svg = exportedSVG[filename]; 68 await fs.writeFile(outputDir + '/' + filename + '.svg', svg, 'utf8'); 69 } 70})();
Same example using Iconify Tools:
1import { readFile, writeFile, mkdir } from 'fs'; 2import { SVG } from '@iconify/tools'; 3 4const outputDir = 'mdi-export'; 5 6// Create target directory 7try { 8 await mkdir(outputDir, { 9 recursive: true, 10 }); 11} catch (err) { 12 // 13} 14 15// Locate icons 16const filename = locate('mdi'); 17 18// Load icon set 19const data = JSON.parse(await fs.readFile(filename, 'utf8')); 20 21// Create IconSet instance 22const iconSet = new IconSet(data); 23 24// Export all icons 25await iconSet.forEach(async (name) => { 26 const svg = iconSet.toString(name); 27 if (!svg) { 28 return; 29 } 30 31 // Save to file 32 await writeFile(`${outputDir}/${name}.svg`, svg, 'utf8'); 33 console.log(`Saved ${outputDir}/${name}.svg (${svg.length} bytes)`); 34});
See Iconify Tools documentation for more export options.
This is collection of icon sets created by various authors.
See collections.md for list of icon sets and their licenses.
No vulnerabilities found.
No security vulnerabilities found.