Type definitions for using Iconify icon sets with TypeScript.
## Files structure
Iconify icon sets are available in several formats:
- Big JSON files that combine many icons in one file
- Node.js packages split into individual icons
### Icon format
Each icon is represented by the `IconifyIcon` type. It is a simple object with multiple string, number or boolean attributes.
The only required attribute is:
-`body`: string. Value contains inner HTML of an icon as a string, for example `<path d="..."/>`.
Optional attributes are represented by type `IconifyOptional`. They are split into several types: dimensions (`IconifyDimenisons` type) and transformations (`IconifyTransformations` type).
Dimensions attributes:
-`width`: number. viewBox width, number. If missing, value is set to 16.
-`height`: number. viewBox height, number. If missing, value is set to 16.
-`left`: number. viewBox left, number. If missing, the value is set to 0.
-`top`: number. viewBox top, number. If missing, the value is set to 0.
Transformations:
-`rotate`: number. Icon rotation. Iconify icons can be rotated in 90 degrees increments, allowing to reuse the same source icon for multiple icons, such as arrow-up being a copy of arrow-left rotated by 90 degrees. Values are 0 for 0 degrees, 1 for 90 degrees, 2 for 180 degrees, 3 for 270 degrees. The default value is 0.
-`hFlip`: boolean. Horizontal flip. Similar to the rotation transformation, an icon can be flipped horizontally and vertically. It can be used to quickly create aliases, such as arrow-left being an alias of arrow-right, but with hFlip set to true. The default value is false.
-`vFlip`: boolean. Vertical flip. The default value is false.
Iconify icon sets format is available from multiple sources:
- NPM package `@iconify/json` that includes all icon sets
- API responses used by SVG framework
Icon set format structure is available as the `IconifyJSON` type. It is an object with several fields:
-`prefix`: string. Icon set prefix.
-`icons`: object. Icons data. Value is an object that represents a set of icons, where the key is an icon name and value is `IconifyIcon` object (see "Icon format" above).
-`aliases`: object. Icon aliases, similar to the `icons` object (see "Aliases" section below).
All icon properties except for `body` are optional and are represented by type `IconifyOptional`. Type `IconifyJSON` also extends type `IconifyOptional`, allowing all optional properties to be placed in the root object.
If an icon is missing a property, look in the root object for the default value. If the root object does not have the default value, use Iconify default value for that property (see list of properties and default values in the "Icon format" section above).
Default values in the root object make it possible to reduce duplication.
In this example `arrow-circle-left` and `barcode` have width of 512, `arrow-left` has width of 448. All icons have a height of 512.
#### Aliases
In addition to `icons`, another important field in icon set object is `aliases`.
Aliases object is similar to icons object, except that instead of icon body icons reference another icon.
Each entry has the same attributes as an icon, except for `body` and has required attribute `parent` that contains the name of the parent icon. The parent icon must be present in the icon set file.
If both icon and alias have same attribute, following rules apply:
-`rotate`: attributes are combined. For example, icon has rotate = 1, alias has rotate = 1. Result will have rotate = 2. To prevent overflow, if rotate > 3, rotate = rotate - 4.
-`hFlip` and `vFlip`: attributes are combined. For example, icon has hFlip = true, alias also has hFlip = true (icon.hFlip !== alias.hFlip). Result is false. false + false = false, false + true = true, true + true = false.
Information block is part of the metadata, it is used for browsing or searching icon sets. It also contains the license for icons in the icon set and information about the author.
Info block is represented by the type `IconifyInfo`. You can see an example above in "info" property.
IconifyInfo type has the following properties, most of them are optional:
-`name`: string. Icon set name. This field is always set.
-`total`: number. The total number of icons, optional.
-`version`: string. The current version, optional.
-`author`: object. Information about the author, always set. Author information has the following properties:
-`name`: string. Author name. This field is always set.
-`url`: string. Link to icon set, optional. Usually links to GitHub repository.
-`license`: object. Information about the license, always set. License information has the following properties:
-`title`: string. License title. This field is always set.
-`samples`: string[]. Value is an array of icon names that should be used as samples when showing the icon set in an icon sets list.
-`height`: number | number[]. Value is a number or array of numbers, values are pixel grids used in the icon set. If any icons in an icon set do not match the grid, this attribute should not be set.
-`displayHeight`: number. The height value that should be used for displaying samples. Value is a number between 16 and 30 (inclusive).
##### Characters map
Characters map is part of the metadata, it is used for icon sets that are either imported from icon fonts or intended to be exported to icon font.
Characters map allows storing characters for export as well as searching icons by character used in an icon font.
It is a simple object, where the key is character code in hexadecimal form, value is an icon name.
Important: each icon can have multiple characters!
Example:
```json
{
"prefix": "fa",
"icons": {
// Icons here
},
"chars": {
"f000": "glass",
"f001": "music",
"f002": "search",
"f003": "envelope-o",
"f004": "heart",
"f005": "star"
// and so on...
}
}
```
##### Categories
Categories are part of the metadata, used to allow filtering icons when showing the entire icons set.
Categories list is a simple object, where the key is category name, value is the list of icons.
Important: each icon can belong to multiple categories!
```json
{
"prefix": "fa-solid",
"icons": {
// Icons here
},
"categories": {
"Accessibility": [
"american-sign-language-interpreting",
"assistive-listening-systems",
"audio-description",
"blind",
"braille",
"closed-captioning",
"deaf",
"low-vision",
"phone-volume",
"question-circle",
"sign-language",
"tty",
"universal-access",
"wheelchair"
],
"Alert": [
"bell",
"bell-slash",
"exclamation",
"exclamation-circle",
"exclamation-triangle",
"radiation",
"radiation-alt",
"skull-crossbones"
]
// and so on...
}
}
```
##### Themes
Themes are part of the metadata, similar to categories, but using prefixes or suffixes to identify icons that belong to a theme.
This is useful when icon set has variations of icons, such as "baseline-_", "outline-_".
Example:
```json
{
"prefix": "ic",
"icons": {
// Icons here
},
"themes": {
"baseline": {
"title": "Baseline",
"prefix": "baseline-"
},
"outline": {
"title": "Outline",
"prefix": "outline-"
},
"round": {
"title": "Round",
"prefix": "round-"
},
"sharp": {
"title": "Sharp",
"prefix": "sharp-"
},
"twotone": {
"title": "Two-Tone",
"prefix": "twotone-"
}
}
}
```
Each theme can have one of the attributes: `prefix` or `suffix`. The prefix must end with `-`, suffix must start with `-`.
In an example above, all icons that start with "baseline-", such as "baseline-home", are considered part of the "Baseline" theme.
#### All attributes
For an example of full icon set files that include metadata, look in icon set files in `@iconify/json` package or browse it at GitHub: [https://github.com/iconify/collections-json](https://github.com/iconify/collections-json)
For an example of individual icons, look in JavaScript files in NPM packages such as `@iconify/icons-mdi`.
## Usage
This repository is intended to be used with any Iconify packages.
At the moment of writing, multiple Iconify packages are written without TypeScript. At the beginning of the year 2020 plan is to rewrite all of them with TypeScript to make sure data is consistent and avoid duplication, this package will be used for sharing types between Iconify packages.
Previous versions of this package were dual-licensed under Apache 2.0 and GPL 2.0 licence, which was messy and confusing. This was later changed to MIT for simplicity.