2
0
mirror of https://github.com/iconify/collections-json.git synced 2024-11-22 12:35:12 +00:00
Go to file
2023-09-20 08:51:37 +03:00
.vscode chore: add vscode stuff and .editorconfig 2021-09-23 11:03:10 +02:00
jest test: hacking cjs tests 2021-09-18 14:42:03 +02:00
json Update 3 icon sets: Arcticons, Octicons, Gitlab SVGs 2023-09-20 08:51:37 +03:00
lib chore: refactor 2021-09-16 15:33:04 +02:00
src Update dependencies, build and test scripts, add unique ids to all icons 2023-01-01 22:14:53 +02:00
.editorconfig Change formatting rules to work with Prettier 2021-09-25 14:17:12 +03:00
.eslintignore Automatically update version in composer.json 2021-11-09 10:40:15 +02:00
.eslintrc.json Change formatting rules to work with Prettier 2021-09-25 14:17:12 +03:00
.gitignore feat: add esm support 2021-09-13 17:57:27 +02:00
.npmignore Add .npmignore 2021-09-30 12:02:09 +03:00
.prettierignore Change formatting rules to work with Prettier 2021-09-25 14:17:12 +03:00
.prettierrc Change formatting rules to work with Prettier 2021-09-25 14:17:12 +03:00
build.config.ts Update dependencies, build and test scripts, add unique ids to all icons 2023-01-01 22:14:53 +02:00
collections.json Update 3 icon sets: Arcticons, Octicons, Gitlab SVGs 2023-09-20 08:51:37 +03:00
collections.md Update 3 icon sets: Arcticons, Octicons, Gitlab SVGs 2023-09-20 08:51:37 +03:00
composer.json Update 3 icon sets: Arcticons, Octicons, Gitlab SVGs 2023-09-20 08:51:37 +03:00
package-lock.json Update 3 icon sets: Arcticons, Octicons, Gitlab SVGs 2023-09-20 08:51:37 +03:00
package.json Update 3 icon sets: Arcticons, Octicons, Gitlab SVGs 2023-09-20 08:51:37 +03:00
readme.md chore: update dependencies and readme 2023-05-31 23:52:27 +03:00
sync-version.cjs Update version for Composer 2023-01-01 22:17:18 +02:00
tsconfig.json chore: update dependencies and readme 2023-05-31 23:52:27 +03:00
vitest.config.cjs Update dependencies, build and test scripts, add unique ids to all icons 2023-01-01 22:14:53 +02:00
vitest.config.mjs Update dependencies, build and test scripts, add unique ids to all icons 2023-01-01 22:14:53 +02:00

Iconify icon sets in JSON format

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.

Validation and clean up

All icons have been processed with Iconify Tools to clean them up.

Icon parsing process includes:

  • Very strict validation and clean up. Icons do not contain scripts, even listeners, fonts, raster images, external resources and unknown elements.
  • Colors for monotone icons have been replaced with currentColor, making it easy to change icon color by changing text color.
  • Icon content has been optimised to reduce its size.

Maintenance

This repository is automatically updated several times a week, so it always contains the latest icons for all icon sets.

Format

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.

Usage

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.

How to get this repository

Instructions below are for Node.js and PHP projects.

Node.js

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');

PHP

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');

Data format

Icons used by Iconify are in directory json, in Iconify JSON format.

Why JSON instead of SVG? There are several reasons for that:

  • Easy to store images in bulk.
  • Contains only content of icon without <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.
  • Data can contain additional content: aliases for icons, icon set information, categories/tags/themes.

Why not XML?

  • JSON is much easier to parse without additional tools. All languages support it.

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:

  • body: icon body.
  • left, top: left and top coordinates of viewBox, default is 0.
  • width, height: dimensions of viewBox, default is 16.
  • rotate: rotation. Default = 0. Values: 0 = 0deg, 1 = 90deg, 2 = 180deg, 3 = 270deg.
  • hFlip: horizontal flip. Boolean value, default = false.
  • vFlip: vertical flip. Boolean value, default = false.
  • hidden: if set to true, icon is hidden. That means icon was removed from collection for some reason, but it is kept in JSON file to prevent applications that rely on old icon from breaking.

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

Extracting individual SVG icons

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.

License

This is collection of icon sets created by various authors.

See collections.md for list of icon sets and their licenses.