
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@iconify/json
Advanced tools
@iconify/json is a package that provides a collection of icon sets in JSON format. It allows developers to access a wide range of icons from different icon sets and use them in their projects. The package is useful for integrating icons into web applications, customizing icon sets, and managing icon data programmatically.
Accessing Icon Data
This feature allows you to access icon data from various icon sets included in the @iconify/json package. The code sample demonstrates how to require the package and access the Material Design Icons (mdi) set, logging the icon data to the console.
const iconData = require('@iconify/json');
const mdiIcons = iconData['mdi'];
console.log(mdiIcons);
Listing Available Icon Sets
This feature enables you to list all available icon sets included in the @iconify/json package. The code sample shows how to retrieve and log the names of all icon sets.
const iconData = require('@iconify/json');
const availableSets = Object.keys(iconData);
console.log(availableSets);
Retrieving Specific Icon Information
This feature allows you to retrieve information about a specific icon from an icon set. The code sample demonstrates how to access the 'home' icon from the Material Design Icons set and log its data.
const iconData = require('@iconify/json');
const mdiIcons = iconData['mdi'];
const specificIcon = mdiIcons.icons['home'];
console.log(specificIcon);
react-icons is a popular package that provides a collection of icons for React applications. It includes icons from various icon libraries like Font Awesome, Material Design, and more. Unlike @iconify/json, which provides raw JSON data, react-icons offers React components for easy integration into React projects.
fontawesome is a widely used icon library that offers a comprehensive set of icons. It provides both free and pro versions with different levels of access. While @iconify/json offers a variety of icon sets in JSON format, fontawesome focuses on its own extensive icon collection and provides tools for web and design integration.
heroicons is a set of free, MIT-licensed high-quality SVG icons for web projects. It is designed specifically for Tailwind CSS but can be used in any project. Unlike @iconify/json, which aggregates multiple icon sets, heroicons focuses on providing a consistent style of icons for modern web design.
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:
npm 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:
import { locate } from '@iconify/json';
// returns location of mdi-light.json
const mdiLightFilename = locate('mdi-light');
Install and initialize Composer project. See documentation at https://getcomposer.org
Then open composer.json and add following code:
"require": {
"php": ">=5.6",
"iconify/json": "*"
}
then run:
composer 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:
// Returns location of mdi-light.json
$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:
{
"prefix": "mdi-light",
"icons": {
"icon-name": {
"body": "<g />",
"width": 24,
"height": 24
}
},
"aliases": {
"icon-alias": {
"parent": "icon-name"
}
}
}
"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:
{
"prefix": "mdi-light",
"icons": {
"icon1": {
"body": "<g />"
},
"icon2": {
"body": "<g />"
},
"icon-20": {
"body": "<g />",
"width": 20,
"height": 20
}
},
"width": 24,
"height": 24
}
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):
import { promises as fs } from 'fs';
// Function to locate JSON file
import { locate } from '@iconify/json';
// Various functions from Iconify Utils
import { parseIconSet } from '@iconify/utils/lib/icon-set/parse';
import { iconToSVG } from '@iconify/utils/lib/svg/build';
import { defaults } from '@iconify/utils/lib/customisations';
(async () => {
// Locate icons
const filename = locate('mdi');
// Load icon set
const icons = JSON.parse(await fs.readFile(filename, 'utf8'));
// Parse all icons
const exportedSVG: Record<string, string> = Object.create(null);
parseIconSet(icons, (iconName, iconData) => {
if (!iconData) {
// Invalid icon
console.error(`Error parsing icon ${iconName}`);
return;
}
// Render icon
const renderData = iconToSVG(iconData, {
...defaults,
height: 'auto',
});
// Generate attributes for SVG element
const svgAttributes: Record<string, string> = {
'xmlns': 'http://www.w3.org/2000/svg',
'xmlns:xlink': 'http://www.w3.org/1999/xlink',
...renderData.attributes,
};
const svgAttributesStr = Object.keys(svgAttributes)
.map(
(attr) =>
// No need to check attributes for special characters, such as quotes,
// they cannot contain anything that needs escaping.
`${attr}="${svgAttributes[attr as keyof typeof svgAttributes]}"`
)
.join(' ');
// Generate SVG
const svg = `<svg ${svgAttributesStr}>${renderData.body}</svg>`;
exportedSVG[iconName] = svg;
});
// Output directory
const outputDir = 'mdi-export';
try {
await fs.mkdir(outputDir, {
recursive: true,
});
} catch (err) {
//
}
// Save all files
const filenames = Object.keys(exportedSVG);
for (let i = 0; i < filenames.length; i++) {
const filename = filenames[i];
const svg = exportedSVG[filename];
await fs.writeFile(outputDir + '/' + filename + '.svg', svg, 'utf8');
}
})();
Same example using Iconify Tools:
import { readFile, writeFile, mkdir } from 'fs';
import { SVG } from '@iconify/tools';
const outputDir = 'mdi-export';
// Create target directory
try {
await mkdir(outputDir, {
recursive: true,
});
} catch (err) {
//
}
// Locate icons
const filename = locate('mdi');
// Load icon set
const data = JSON.parse(await fs.readFile(filename, 'utf8'));
// Create IconSet instance
const iconSet = new IconSet(data);
// Export all icons
await iconSet.forEach(async (name) => {
const svg = iconSet.toString(name);
if (!svg) {
return;
}
// Save to file
await writeFile(`${outputDir}/${name}.svg`, svg, 'utf8');
console.log(`Saved ${outputDir}/${name}.svg (${svg.length} bytes)`);
});
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.
FAQs
Hundreds of open source icon sets in IconifyJSON format
We found that @iconify/json demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.