### Install NPM Dependencies and Build
Source: https://iconify.design/docs/api/hosting-js
Run these commands to install necessary dependencies and build the project before starting the server.
```bash
npm install
npm run build
```
--------------------------------
### Download NPM Package Example
Source: https://iconify.design/docs/libraries/tools/package/npm.html
Demonstrates how to use the downloadNPMPackage function to download a specified NPM package to a target directory. Ensure the '@iconify/tools' package is installed.
```typescript
import { downloadNPMPackage } from '@iconify/tools';
(async () => {
console.log(
await downloadNPMPackage({
target: 'downloads/icon-sets/mdi-light',
package: '@iconify-json/mdi-light',
})
);
})();
```
--------------------------------
### Keywords API Response with Prefix
Source: https://iconify.design/docs/api/keywords.html
Example response when using the 'prefix' parameter. It lists all keywords starting with the given prefix.
```json
{
"prefix": "hom",
"pretty": "1",
"exists": false,
"matches": [
"home",
"home2",
"home3",
"homee",
"homify",
"homewav",
"homebrew",
"homestay",
"homebridge",
"homeadvisor",
"homeassistant",
"homeassistantcommunitystore"
]
}
```
--------------------------------
### Icon Name Examples
Source: https://iconify.design/docs/iconify-icon/icon-name.html
Provides examples of how to format icon names using different providers and prefixes.
```APIDOC
## Examples
### Example 1: Default Provider
`md:home`
```json
{
"provider": "",
"prefix": "md",
"name": "home"
}
```
Because prefix does not contain hyphen, icon can also be referred as 'md-home'.
### Example 2: Custom Provider
`@local:line-icons:arrow-left`
```json
{
"provider": "local",
"prefix": "line-icons",
"name": "arrow-left"
}
```
```
--------------------------------
### Install Iconify Tools
Source: https://iconify.design/docs/libraries/tools
Install the latest version of the Iconify Tools library using npm.
```bash
npm install @iconify/tools --save
```
--------------------------------
### resolve('plus') Example Output
Source: https://iconify.design/docs/libraries/tools/icon-set/resolve.html
Example of the partial icon data returned by resolve('plus').
```APIDOC
## Response Example for resolve('plus')
### Success Response (200)
```json
{
"body": ""
}
```
```
--------------------------------
### Installation
Source: https://iconify.design/docs/icon-components/react
Install the Iconify React component using NPM or Yarn.
```APIDOC
## Installation
If you are using NPM:
`npm install --save-dev @iconify/react`
If you are using Yarn:
`yarn add --dev @iconify/react`
### Version 4
As of version 5, the component is a modern functional component that uses React hooks. If you want to use the icon component with an older version of React, you can install version 4 using @legacy tag:
`npm install --save-dev @iconify/react@legacy`
```
--------------------------------
### resolve('plus', true) Example Output
Source: https://iconify.design/docs/libraries/tools/icon-set/resolve.html
Example of the full icon data returned by resolve('plus', true).
```APIDOC
## Response Example for resolve('plus', true)
### Success Response (200)
```json
{
"left": 0,
"top": 0,
"width": 16,
"height": 16,
"rotate": 0,
"vFlip": false,
"hFlip": false,
"body": ""
}
```
```
--------------------------------
### Installation
Source: https://iconify.design/docs/icon-components/ember
Instructions on how to install the Iconify for Ember component using NPM or Yarn.
```APIDOC
## Installation
If you are using NPM:
`npm install --save-dev @iconify/ember`
If you are using Yarn:
`yarn add --dev @iconify/ember`
```
--------------------------------
### resolve('triangle-right') Example Output
Source: https://iconify.design/docs/libraries/tools/icon-set/resolve.html
Example of the partial icon data returned by resolve('triangle-right').
```APIDOC
## Response Example for resolve('triangle-right')
### Success Response (200)
```json
{
"body": "",
"hFlip": true
}
```
```
--------------------------------
### resolve('triangle-right', true) Example Output
Source: https://iconify.design/docs/libraries/tools/icon-set/resolve.html
Example of the full icon data returned by resolve('triangle-right', true).
```APIDOC
## Response Example for resolve('triangle-right', true)
### Success Response (200)
```json
{
"left": 0,
"top": 0,
"width": 16,
"height": 16,
"rotate": 0,
"vFlip": false,
"hFlip": true,
"body": ""
}
```
```
--------------------------------
### Install Iconify Utils
Source: https://iconify.design/docs/libraries/utils
Install the Iconify Utils library using npm. This command adds the library as a dependency to your project.
```bash
npm install @iconify/utils --save
```
--------------------------------
### Install @iconify/tailwind
Source: https://iconify.design/docs/usage/css/tailwind/tailwind3
Command to install the Iconify Tailwind plugin as a development dependency.
```bash
npm i -D @iconify/tailwind
```
--------------------------------
### Install @iconify-icon/react Package
Source: https://iconify.design/docs/iconify-icon/react.html
Install the Iconify Icon React wrapper package using npm or yarn.
```bash
npm install --save-dev @iconify-icon/react
```
```bash
yarn add --dev @iconify-icon/react
```
--------------------------------
### resolve('debug-pause', true) Example Output
Source: https://iconify.design/docs/libraries/tools/icon-set/resolve.html
Example of the full icon data returned by resolve('debug-pause', true).
```APIDOC
## Response Example for resolve('debug-pause', true)
### Success Response (200)
```json
{
"left": 0,
"top": 0,
"width": 16,
"height": 16,
"rotate": 0,
"vFlip": false,
"hFlip": false,
"body": "",
"hidden": true
}
```
```
--------------------------------
### Install Iconify Tools for CommonJS
Source: https://iconify.design/docs/libraries/tools
If CommonJS support is needed, install version 4 of the Iconify Tools library.
```bash
npm install @iconify/tools@cjs --save
```
--------------------------------
### Install Astro Icon
Source: https://iconify.design/docs/usage/svg/astro
Install the astro-icon package as a development dependency using npm.
```bash
npm i -D astro-icon
```
--------------------------------
### Install Iconify Svelte Package
Source: https://iconify.design/docs/usage/svg-css/svelte
Install the necessary package for the desired icon set using npm.
```bash
npm install @iconify-svelte/material-symbols
```
--------------------------------
### resolve('debug-pause') Example Output
Source: https://iconify.design/docs/libraries/tools/icon-set/resolve.html
Example of the partial icon data returned by resolve('debug-pause').
```APIDOC
## Response Example for resolve('debug-pause')
### Success Response (200)
```json
{
"body": "",
"hidden": true
}
```
```
--------------------------------
### Install Iconify for Vue 2 using NPM
Source: https://iconify.design/docs/icon-components/vue2
Use this command to install the @iconify/vue2 package if you are using NPM.
```bash
npm install --save-dev @iconify/vue2
```
--------------------------------
### Install All Icon Sets for Iconify
Source: https://iconify.design/docs/usage/css/tailwind/tailwind4
To use all open-source icon sets with the Iconify plugin, install the @iconify/json package as a dev dependency.
```bash
npm i -D @iconify/json
```
--------------------------------
### Example Usage
Source: https://iconify.design/docs/libraries/tools/package/gitlab.html
This example demonstrates how to use the `downloadGitLabRepo` function in a Node.js script, retrieving the GitLab API token from an environment variable.
```typescript
import { downloadGitLabRepo } from '@iconify/tools';
// GITLAB_TOKEN=qwertyuiop node example.js
const token = process.env.GITLAB_TOKEN || '';
(async () => {
try {
const result = await downloadGitLabRepo({
target: 'downloads/eos-icons',
project: '4600360',
branch: 'master',
token,
});
console.log(result);
} catch (error) {
console.error('Error downloading GitLab repo:', error);
}
})();
```
--------------------------------
### PHP: Get Root Directory of Package
Source: https://iconify.design/docs/icons/all.html
Use the static rootDir() function from the Iconify\IconsJSON\Finder class to get the installation path of the icon sets package. This function is synchronous.
```php
use Iconify\IconsJSON\Finder;
$rootDir = Finder::rootDir();
```
--------------------------------
### Example Usage of setIcon()
Source: https://iconify.design/docs/libraries/tools/icon-set/set-icon.html
This example demonstrates how to create an IconSet, add multiple icons using setIcon(), set variations, and export the icon set.
```typescript
import { blankIconSet } from '@iconify/tools';
// Create icon set, add few icons
const iconSet = blankIconSet('test-prefix');
iconSet.setIcon('add', {
body: '',
});
iconSet.setIcon('triangle-left', {
body: '',
});
iconSet.setVariation('triangle-right', 'triangle-left', {
hFlip: true,
});
// Set information
iconSet.info = {
name: 'Test',
author: {
name: 'Me',
},
license: {
title: 'MIT',
},
};
// Export icon set
const data = iconSet.export();
console.log(JSON.stringify(data, null, '\t'));
```
--------------------------------
### Load Icon with Promise Syntax
Source: https://iconify.design/docs/icon-components/react/load-icon.html
Use this snippet when you need to get icon data inside an asynchronous function using Promise syntax. Ensure '@iconify/react' is installed.
```javascript
import { loadIcon } from '@iconify/react';
const iconName = 'mdi:home';
loadIcon(iconName)
.then((data) => {
console.log(
`Icon ${iconName} have been loaded and is ready to be renderered.`
);
console.log(data);
})
.catch((err) => {
console.log(`Icon ${iconName} does not exist.`);
});
```
--------------------------------
### Download Git Repository Example
Source: https://iconify.design/docs/libraries/tools/package/git.html
Use this function to clone a Git repository. Ensure Git is installed and accessible. The 'ifModifiedSince' option can be used to conditionally download only if the repository has been updated.
```typescript
import { downloadGitRepo } from '@iconify/tools';
(async () => {
console.log(
await downloadGitRepo({
target: 'downloads/boxicons-{hash}',
remote: 'git@github.com:atisawd/boxicons.git',
branch: 'master',
ifModifiedSince: true,
log: true,
})
);
})();
```
--------------------------------
### Icon Name Examples
Source: https://iconify.design/docs/icon-components/react/icon-name.html
Provides examples of how to format icon names, including simple and complex cases with different providers and prefixes.
```APIDOC
## Examples
### Simple Icon Name
`md:home`
```json
{
"provider": "",
"prefix": "md",
"name": "home"
}
```
Because the prefix does not contain a hyphen, the icon can also be referred to as 'md-home'.
### Complex Icon Name with Custom Provider
`@local:line-icons:arrow-left`
```json
{
"provider": "local",
"prefix": "line-icons",
"name": "arrow-left"
}
```
```
--------------------------------
### Get CSS for one icon with custom selector
Source: https://iconify.design/docs/api/css.html
Use the 'selector' parameter to apply custom CSS to a specific icon. This example generates CSS for the 'axe' icon with the selector '.axe-icon'.
```css
.axe-icon {
display: inline-block;
width: 1em;
height: 1em;
background: no-repeat center / 100%;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 72 72' width='72' height='72'%3E%3Cpath fill='%239b9b9a' d='m7.95 17.47l18.13-4.237s.217 2.51.541 4.237a19.196 19.196 0 0 0 3.561 6.474c.756.54-7.482 11.88-10.24 12.42c-4.92.954-13.4-18.33-11.99-18.89z'/%3E%3Cpath fill='%23a57939' d='M36.41 23.25c-1.189.792-2.352.923-1.771 2.228a7.128 7.128 0 0 1 .434 1.297c.501 2.172 1.503 3.675 5.345 5.847c3.412 1.929 10.38 15.58 11.9 18.61a2.94 2.94 0 0 1 .31 1.257l.13 5.842a2.963 2.963 0 0 0 .663 1.803l1.863 2.293a2.963 2.963 0 0 0 4.132.46l3.502-2.757a2.963 2.963 0 0 0 .703-3.86l-21.27-35.2c-.873-1.445-.81-1.416-2.215-.48z'/%3E%3Crect width='13.63' height='13.53' x='14.18' y='24.84' fill='%23d0cfce' rx='2.359' ry='2.359' transform='rotate(-30)'/%3E%3Cg fill='none' stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-width='2'%3E%3Cpath d='M34.66 24.76c-.04.204-.002.45.138.767a7.1 7.1 0 0 1 .432 1.29c.499 2.163 1.495 3.659 5.317 5.82c3.394 1.919 10.32 15.51 11.83 18.53c.195.388.3.816.31 1.25l.128 5.815a2.95 2.95 0 0 0 .66 1.794l1.852 2.283a2.946 2.946 0 0 0 4.11.457l3.483-2.744a2.95 2.95 0 0 0 .7-3.842L42.48 21.44c-.315-.52-.525-.808-.732-.918'/%3E%3Crect width='13.56' height='13.46' x='14.32' y='25.04' rx='2.359' ry='2.359' transform='rotate(-30.014) skewX(-.028)'/%3E%3Cpath d='m31.02 24.98l-9.465 11.24c-3.463 4.049-17.14-17.64-12.65-19.27l17.34-3.026'/%3E%3C/g%3E%3C/svg%3E");
}
```
--------------------------------
### Example GitHub Repository Download
Source: https://iconify.design/docs/libraries/tools/package/github.html
Demonstrates how to download a GitHub repository using the downloadGitHubRepo function. Ensure the GITHUB_TOKEN environment variable is set for authentication.
```typescript
import { downloadGitHubRepo } from '@iconify/tools';
// GITHUB_TOKEN=ghp_12345 node example.js
const token = process.env.GITHUB_TOKEN || '';
(async () => {
console.log(
await downloadGitHubRepo({
target: 'downloads/jam',
user: 'michaelampr',
repo: 'jam',
branch: 'master',
token,
})
);
})();
```
--------------------------------
### Set Fetch API Implementation in Iconify for React
Source: https://iconify.design/docs/icon-components/react/set-fetch.html
Use this code on the server-side when Node.js environment does not support Fetch API. Ensure you have installed 'cross-fetch' or 'node-fetch'. Browsers do not require this setup.
```javascript
import { _api } from '@iconify/react';
import fetch from 'cross-fetch';
//
// import fetch from 'node-fetch';
// Set Fetch API before doing anything
_api.setFetch(fetch);
```
--------------------------------
### Render Icons with Multiple Plugin Configurations
Source: https://iconify.design/docs/usage/css/tailwind/iconify/selectors.html
Demonstrates rendering icons using different configurations from multiple addIconSelectors plugin instances. Includes examples for default sizing, custom width/height, and specific alignment with custom dimensions.
```html
Icon with 1em size:
Icon without size (using custom width/height):
24px icon aligned to bottom:
```
--------------------------------
### Generate SVG from Icon Set (TypeScript)
Source: https://iconify.design/docs/libraries/utils/examples/export-svg-from-icon-set.html
Use Iconify Utils to generate SVG from an icon set. This example shows how to import an icon set, get icon data, and convert it to an SVG string.
```typescript
// Import full icon set
import { icons } from '@iconify-json/mdi-light';
// Various functions from Iconify Utils
import { getIconData, iconToSVG, iconToHTML } from '@iconify/utils';
// Get ful data for 'mdi-light:home'
const iconData = getIconData(icons, 'home');
if (!iconData) {
throw new Error('Home icon does not exist');
}
// Generate data for rendering SVG
// Second optional parameter is customisations
const renderData = iconToSVG(iconData);
/*
Result of iconToSVG() can be used to either generate HTML code or to use in various components
renderData = {
attributes: {
width: '1em',
height: '1em',
viewBox: '0 0 24 24'
},
body: ''
}
*/
// Generate SVG
const svg = iconToHTML(renderData.body, renderData.attributes);
// Log SVG
console.log(svg);
```
--------------------------------
### Install Iconify Utils and JSON Dependencies
Source: https://iconify.design/docs/usage/css/utils
Install the necessary dependencies for generating CSS with Iconify Utils. This command saves them as development dependencies.
```bash
npm install --save-dev @iconify/utils @iconify/json
```
--------------------------------
### List and Locate Icon Sets in Node.js
Source: https://iconify.design/docs/icons/all.html
Use lookupCollections() to get a list of all available icon sets and locate() to find the JSON file path for a specific icon set. Ensure @iconify/json is installed.
```javascript
// Installation: npm install --save @iconify/json
import { lookupCollections, locate } from '@iconify/json';
(async () => {
// Get list of all icon sets
const iconSets = await lookupCollections();
const prefixes = Object.keys(iconSets);
console.log(`Available ${prefixes.length} icon sets`);
// List icon sets in format: "prefix: name (total icons)"
console.log(
prefixes
.map((prefix) => {
const item = iconSets[prefix];
// prefix: name (total icons)
return prefix + ': ' + item.name + ' (' + item.total + ' icons)';
})
.join('\n')
);
// Get location of Taber Icons JSON file
const tabler = locate('tabler');
console.log('Tabler icons JSON file is located at:', tabler);
})();
```
--------------------------------
### Get NPM Package Version and URL with TypeScript
Source: https://iconify.design/docs/libraries/tools/package/npm-version.html
Use the getNPMVersion function to retrieve the latest version number and download URL for a specified NPM package. The function accepts an options object with 'package' and 'tag' properties. Ensure you have '@iconify/tools' installed.
```typescript
import { getNPMVersion } from '@iconify/tools';
(async () => {
console.log(
await getNPMVersion({
package: '@iconify-json/mdi-light',
// tag: 'latest',
})
);
})();
```
--------------------------------
### Install Iconify for Svelte (Yarn)
Source: https://iconify.design/docs/icon-components/svelte
Install the Iconify Svelte component using Yarn. This command installs the latest version compatible with Svelte 5.
```bash
yarn add --dev @iconify/svelte
```
--------------------------------
### Install Iconify for Svelte (NPM)
Source: https://iconify.design/docs/icon-components/svelte
Install the Iconify Svelte component using NPM. This command installs the latest version compatible with Svelte 5.
```bash
npm install --save-dev @iconify/svelte
```
--------------------------------
### Download GitLab Repository Example
Source: https://iconify.design/docs/libraries/tools/package/gitlab.html
Example of how to use the downloadGitLabRepo function to download icons from a GitLab repository. It demonstrates setting options like target directory, project ID, branch, and token, and logs the result. The GitLab token is expected to be provided via an environment variable.
```typescript
import { downloadGitLabRepo } from '@iconify/tools';
// GITLAB_TOKEN=qwertyuiop node example.js
const token = process.env.GITLAB_TOKEN || '';
(async () => {
console.log(
await downloadGitLabRepo({
target: 'downloads/eos-icons',
project: '4600360',
branch: 'master',
token,
})
);
})();
```
--------------------------------
### Configure Icon Sets from JSON and Folder
Source: https://iconify.design/docs/usage/css/tailwind/tailwind4/custom-icons.html
Use the `icon-sets` option within the plugin configuration to specify sources for icon sets. This example demonstrates loading from both a JSON file and a folder.
```css
@plugin "@iconify/tailwind4" {
icon-sets: from-json(test, "./icon-sets/test.json"), from-folder(test2, "./assets/svg");
}
```
--------------------------------
### Load Icon with Async/Await Syntax
Source: https://iconify.design/docs/icon-components/svelte/load-icon.html
This example demonstrates loading an icon using the async/await syntax within a function. It handles potential errors during the icon loading process. Import 'loadIcon' from '@iconify/svelte'.
```javascript
import { loadIcon } from '@iconify/svelte';
/**
* Usage example in async function
*/
async function test() {
try {
const data = await loadIcon('mdi:home');
console.log('Loaded home icon!');
} catch (err) {
console.error('Failed to load home icon');
}
}
test();
```
--------------------------------
### Install Iconify for React (Legacy Version)
Source: https://iconify.design/docs/icon-components/react
Install version 4 of the Iconify React component using the @legacy tag if you need to support older React versions. This installs the legacy version as a development dependency.
```bash
npm install --save-dev @iconify/react@legacy
```
--------------------------------
### Start Iconify API Server
Source: https://iconify.design/docs/api/hosting-js
Execute this command to start the Iconify API server. By default, it loads the latest icons and serves data on port 3000.
```bash
npm run start
```
--------------------------------
### Configure API Providers Globally (HTML)
Source: https://iconify.design/docs/api/providers.html
This example demonstrates how to configure API providers globally using a script tag in HTML. It allows setting custom resources and rotation timeouts for the default provider. Remember to include the Iconify script.
```html
```
--------------------------------
### Usage Example
Source: https://iconify.design/docs/libraries/utils/icon-to-svg.html
This example demonstrates how to use iconToSVG() along with other Iconify Utils functions to fetch icon data, convert it to SVG, and generate an SVG string.
```APIDOC
## Example
```typescript
import { icons } from '@iconify-json/codicon';
import { getIconData, iconToSVG, iconToHTML, replaceIDs } from '@iconify/utils';
const iconName = 'debug-console';
// Get content for icon
const iconData = getIconData(icons, iconName);
if (!iconData) {
throw new Error(`Icon "${iconName}" is missing");
}
// Use it to render icon
const renderData = iconToSVG(iconData, {
height: 'auto',
});
// Generate SVG string
const svg = iconToHTML(replaceIDs(renderData.body), renderData.attributes);
// Log SVG
console.log(svg);
```
```
--------------------------------
### Install Iconify for Vue with Yarn
Source: https://iconify.design/docs/icon-components/vue
Use this command to install the Iconify for Vue package if you are using Yarn.
```bash
yarn add --dev @iconify/vue
```
--------------------------------
### Install Iconify for Vue with NPM
Source: https://iconify.design/docs/icon-components/vue
Use this command to install the Iconify for Vue package if you are using NPM.
```bash
npm install --save-dev @iconify/vue
```
--------------------------------
### Render Icons with Multiple Size Configurations
Source: https://iconify.design/docs/usage/css/tailwind/dynamic/size.html
Demonstrates rendering icons using different configurations: default 1em size, no predefined size requiring custom dimensions, and fixed pixel sizes.
```html
Icon with 1em size:
Icon without size (using custom width/height):
```
--------------------------------
### Iconify API Query Example
Source: https://iconify.design/docs/api/icon-data.html
Example of an API query to retrieve multiple icons from the 'mdi' icon set. The 'pretty=1' parameter is optional for formatted output.
```http
/mdi.json?icons=account-box,account-cash,account,home&pretty=1
```