@iconify/json 2.0.0-beta.1 → 2.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,49 @@
1
+ import { PathLike } from 'fs';
2
+ import { IconifyInfo, IconifyJSON } from '@iconify/types';
3
+
4
+ /**
5
+ * This file is part of the iconify.design libraries.
6
+ *
7
+ * (c) Vjacheslav Trushkin <cyberalien@gmail.com>
8
+ *
9
+ * @license MIT
10
+ *
11
+ * For the full copyright and license information, please view the license.txt
12
+ * file that is available in this file's directory.
13
+ */
14
+
15
+ /**
16
+ * Collection info map
17
+ */
18
+ declare type IconifyMetaDataCollection = {
19
+ [prefix: string]: IconifyInfo;
20
+ };
21
+ /**
22
+ * Locate JSON file
23
+ *
24
+ * @param {string} name Collection name
25
+ * @returns {string} Path to collection json file
26
+ */
27
+ declare const locate: (name: string) => PathLike;
28
+ /**
29
+ * Loads a collection.
30
+ *
31
+ * @param {PathLike} path The path to locate the `json` collection file.
32
+ * @return {Promise<IconifyJSON>}
33
+ */
34
+ declare const loadCollection: (path: PathLike) => Promise<IconifyJSON>;
35
+ /**
36
+ * Get a collection.
37
+ *
38
+ * @param {string} name The name of the collection
39
+ * @return {Promise<IconifyJSON>}
40
+ */
41
+ declare const lookupCollection: (name: string) => Promise<IconifyJSON>;
42
+ /**
43
+ * Get list of collections info.
44
+ *
45
+ * @return {Promise<IconifyMetaDataCollection>}
46
+ */
47
+ declare const lookupCollections: () => Promise<IconifyMetaDataCollection>;
48
+
49
+ export { IconifyMetaDataCollection, loadCollection, locate, lookupCollection, lookupCollections };
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";var __import_meta_url = typeof document === 'undefined' ? 'file://' + __filename : new URL('index.js', document.baseURI).href;Object.defineProperty(exports, "__esModule", {value: true});// src/index.ts
2
+ var _fs = require('fs');
3
+ var _url = require('url');
4
+ var _pathe = require('pathe');
5
+ var _dirname = typeof __dirname !== "undefined" ? __dirname : _pathe.dirname.call(void 0, _url.fileURLToPath.call(void 0, __import_meta_url));
6
+ var dir = _pathe.join.call(void 0, _dirname, "/..");
7
+ var locate = (name) => _pathe.join.call(void 0, dir, `./json/${name}.json`);
8
+ var loadCollection = async (path) => {
9
+ return JSON.parse(await _fs.promises.readFile(path, "utf8"));
10
+ };
11
+ var lookupCollection = async (name) => {
12
+ return await loadCollection(locate(name));
13
+ };
14
+ var lookupCollections = async () => {
15
+ return JSON.parse(await _fs.promises.readFile(_pathe.join.call(void 0, dir, "./collections.json"), "utf8"));
16
+ };
17
+
18
+
19
+
20
+
21
+
22
+ exports.loadCollection = loadCollection; exports.locate = locate; exports.lookupCollection = lookupCollection; exports.lookupCollections = lookupCollections;
23
+ /**
24
+ * This file is part of the iconify.design libraries.
25
+ *
26
+ * (c) Vjacheslav Trushkin <cyberalien@gmail.com>
27
+ *
28
+ * @license MIT
29
+ *
30
+ * For the full copyright and license information, please view the license.txt
31
+ * file that is available in this file's directory.
32
+ */
package/dist/index.mjs ADDED
@@ -0,0 +1,32 @@
1
+ // src/index.ts
2
+ import { promises as fs } from "fs";
3
+ import { fileURLToPath } from "url";
4
+ import { dirname, join } from "pathe";
5
+ var _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
6
+ var dir = join(_dirname, "/..");
7
+ var locate = (name) => join(dir, `./json/${name}.json`);
8
+ var loadCollection = async (path) => {
9
+ return JSON.parse(await fs.readFile(path, "utf8"));
10
+ };
11
+ var lookupCollection = async (name) => {
12
+ return await loadCollection(locate(name));
13
+ };
14
+ var lookupCollections = async () => {
15
+ return JSON.parse(await fs.readFile(join(dir, "./collections.json"), "utf8"));
16
+ };
17
+ export {
18
+ loadCollection,
19
+ locate,
20
+ lookupCollection,
21
+ lookupCollections
22
+ };
23
+ /**
24
+ * This file is part of the iconify.design libraries.
25
+ *
26
+ * (c) Vjacheslav Trushkin <cyberalien@gmail.com>
27
+ *
28
+ * @license MIT
29
+ *
30
+ * For the full copyright and license information, please view the license.txt
31
+ * file that is available in this file's directory.
32
+ */
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@iconify/json",
3
3
  "description": "Iconify icons collection in JSON format",
4
4
  "license": "MIT",
5
- "version": "2.0.0-beta.1",
5
+ "version": "2.0.0-beta.2",
6
6
  "publishConfig": {
7
7
  "tag": "next"
8
8
  },
@@ -33,10 +33,11 @@
33
33
  "scripts": {
34
34
  "build": "rimraf dist && tsup src/index.ts --format cjs,esm --dts",
35
35
  "test-esm": "jest --clearCache && cross-env NODE_OPTIONS=--experimental-vm-modules npx jest --config=jest.esm.config.ts",
36
- "test-cjs": "yarn build && jest --clearCache && jest --config=jest.cjs.config.ts",
36
+ "test-cjs": "npm run build && jest --clearCache && jest --config=jest.cjs.config.ts",
37
37
  "test-locate-esm": "jest --clearCache && cross-env NODE_OPTIONS=--experimental-vm-modules npx jest --config=jest.esm.config.ts src/locate.esm.test.ts -i",
38
- "test-locate-cjs": "yarn build && jest --clearCache && jest --config=jest.cjs.config.ts src/locate.cjs.test.ts -i",
39
- "test": "yarn test-esm && yarn test-cjs && yarn test-locate-esm && yarn test-locate-cjs"
38
+ "test-locate-cjs": "npm run build && jest --clearCache && jest --config=jest.cjs.config.ts src/locate.cjs.test.ts -i",
39
+ "test": "npm run test-esm && npm run test-cjs && npm run test-locate-esm && npm run test-locate-cjs",
40
+ "prepublishOnly": "npm run build"
40
41
  },
41
42
  "dependencies": {
42
43
  "@iconify/types": "^1.0.9",
package/readme.md CHANGED
@@ -1,20 +1,28 @@
1
- # Iconify icons collection in JSON format
1
+ # Iconify icon sets in JSON format
2
2
 
3
3
  This is collection of SVG icons created by various authors, released under various free licenses. Some collections require attribution when used for commercial purposes. See [collections.md](./collections.md) for list of collections and their licenses.
4
4
 
5
- All SVG icons have been cleaned up. Content has been optimized, colors for monotone icons have been replaced with currentColor, ready to be inserted in HTML. Tools used for creating this collection are available on [Iconify GitHub repository](https://github.com/iconify), more specifically [@iconify/tools](https://github.com/iconify/tools). You can use it to create your own JSON packages from custom icon sets.
5
+ All icons have been normalized:
6
6
 
7
- This library is intended to be used in packages that build components, such as [Iconify Tools](https://github.com/iconify/tools) and [Iconify React](https://github.com/iconify/iconify-react).
7
+ - Cleaned up, removing anything that is not needed to show icon.
8
+ - Colors for monotone icons have been replaced with `currentColor`, making it easy to change icon color by changing text color.
9
+ - Icon content has been optimised to reduce its size.
8
10
 
9
- Repository is updated daily by fully automated script, so it always contains latest icons from various sources.
11
+ Repository is updated by fully automated script, so it always contains latest icons from various sources.
10
12
 
13
+ ## Format and usage
14
+
15
+ Icon sets are stored in `IconifyJSON` format. TypeScript definition is available in `@iconify/types` package. Documentation is [available on Iconify Documentation website](https://docs.iconify.design/types/iconify-json.html).
16
+
17
+ To work with icon sets, use [Iconify Utils](https://docs.iconify.design/tools/utils/). Utils package works in any JavaScript environment: Node.js, Deno, browsers, isolated JavaScript environments. For PHP applications use [Iconify JSON Tools](https://docs.iconify.design/tools/json/).
18
+
19
+ To create icon sets, use [Iconify Tools](https://docs.iconify.design/tools/tools2/). Tools package works in Node.js, it can import icons from various sources, do cleanup, optimisation, export it in `IconifyJSON` format and generate NPM packages.
11
20
 
12
21
  ## How to get this repository
13
22
 
14
23
  Instructions below are for Node.js and PHP projects.
15
24
 
16
-
17
- #### Node.js
25
+ ### Node.js
18
26
 
19
27
  Run this command to add icons to your project:
20
28
 
@@ -24,17 +32,16 @@ npm install --save @iconify/json
24
32
 
25
33
  Icons will be available in node_modules/@iconify/json
26
34
 
27
- To resolve filename for any json file, use this:
35
+ To resolve filename for any json file, use this if you are using CommonJS syntax:
28
36
 
29
37
  ```js
30
- const icons = require('@iconify/json');
38
+ import { locate } from '@iconify/json';
31
39
 
32
- // returns location of fa.json
33
- let fa = icons.locate('fa');
40
+ // returns location of mdi-light.json
41
+ const mdiLightFilename = locate('mdi-light');
34
42
  ```
35
43
 
36
-
37
- #### PHP
44
+ ### PHP
38
45
 
39
46
  Install and initialize Composer project. See documentation at [https://getcomposer.org](https://getcomposer.org)
40
47
 
@@ -60,75 +67,113 @@ If you don't use Composer, clone GitHub repository and add necessary autoload co
60
67
  To resolve filename for any json file, use this:
61
68
 
62
69
  ```php
63
- // returns location of fa.json
64
- $fa = \Iconify\IconsJSON\Finder::locate('fa');
70
+ // Returns location of mdi-light.json
71
+ $mdiLightLocation = \Iconify\IconsJSON\Finder::locate('mdi-light');
65
72
  ```
66
73
 
67
-
68
- ## Format
74
+ ## Data format
69
75
 
70
76
  Icons used by Iconify are in directory json, in Iconify JSON format.
71
77
 
72
- Why JSON instead of SVG? To load images in bulk.
78
+ Why JSON instead of SVG? There are several reasons for that:
73
79
 
74
- If you need individual SVG images, you can generate them using Iconify JSON Tools. See instructions for [PHP version](https://github.com/iconify/json-tools.php) or [Node.js version](https://github.com/iconify/json-tools.js).
80
+ - Easy to store images in bulk.
81
+ - 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.
82
+ - Data can contain additional content: aliases for icons, icon set information, categories/tags/themes.
75
83
 
84
+ Why not XML?
85
+
86
+ - JSON is much easier to parse without additional tools. All languages support it.
76
87
 
77
88
  Format of json file is very simple:
78
89
 
79
- ```js
90
+ ```json
80
91
  {
81
- "icons": {
82
- "icon-name": {
83
- "body": "svg body",
84
- "width": width,
85
- "height": height
86
- }
87
- },
88
- "aliases": {
89
- "icon-alias": {
90
- "parent": "icon-name"
91
- }
92
- },
93
- "width": default width,
94
- "height": default height
92
+ "prefix": "mdi-light",
93
+ "icons": {
94
+ "icon-name": {
95
+ "body": "<g />",
96
+ "width": 24,
97
+ "height": 24
98
+ }
99
+ },
100
+ "aliases": {
101
+ "icon-alias": {
102
+ "parent": "icon-name"
103
+ }
104
+ }
95
105
  }
96
106
  ```
97
107
 
98
108
  "icons" object contains list of all icons.
99
109
 
100
110
  Each icon has following properties:
101
- * body - icon body
102
- * width - width in pixels
103
- * height - height in pixels
104
- * rotate - rotation. Default = 0. Values: 0 = 0deg, 1 = 90deg, 2 = 180deg, 3 = 270deg
105
- * hFlip - horizontal flip. Boolean value, default = false
106
- * vFlip - vertical flip. Boolean value, default = false
107
- * 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
108
111
 
109
- Width or height might be missing. If icon does not have width or height, use default width or height from root object.
110
- rotate, hFlip and vFlip are all optional.
112
+ - body: icon body.
113
+ - left, top: left and top coordinates of viewBox, default is 0.
114
+ - width, height: dimensions of viewBox, default is 16.
115
+ - rotate: rotation. Default = 0. Values: 0 = 0deg, 1 = 90deg, 2 = 180deg, 3 = 270deg.
116
+ - hFlip: horizontal flip. Boolean value, default = false.
117
+ - vFlip: vertical flip. Boolean value, default = false.
118
+ - 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.
119
+
120
+ 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.
121
+
122
+ When multiple icons have the same value, it is moved to root object to reduce duplication:
111
123
 
112
- Optional "aliases" object contains list of aliases for icons. Format is similar to "icons" object, with additional property "parent" that points to parent icon. Any other properties overwrite properties of parent icon.
124
+ ```json
125
+ {
126
+ "prefix": "mdi-light",
127
+ "icons": {
128
+ "icon1": {
129
+ "body": "<g />"
130
+ },
131
+ "icon2": {
132
+ "body": "<g />"
133
+ },
134
+ "icon-20": {
135
+ "body": "<g />",
136
+ "width": 20,
137
+ "height": 20
138
+ }
139
+ },
140
+ "width": 24,
141
+ "height": 24
142
+ }
143
+ ```
113
144
 
114
- For more information see developer documentation on [https://iconify.design/docs/json-icon-format/](https://iconify.design/docs/json-icon-format/)
145
+ In example above, "icon1" and "icon2" are 24x24, "icon-20" is 20x20.
115
146
 
147
+ For more information see developer documentation on [https://docs.iconify.design/types/iconify-json.html](https://docs.iconify.design/types/iconify-json.html)
116
148
 
117
149
  ## Extracting individual SVG icons
118
150
 
119
- See JSON tools readme for instructions for [PHP](https://github.com/iconify/json-tools.php) or [Node.js](https://github.com/iconify/json-tools.js).
151
+ For PHP use [Iconify JSON Tools](https://docs.iconify.design/tools/json/).
152
+
153
+ For JavaScript use [Iconify Utils](https://docs.iconify.design/tools/utils/), though Iconify JSON Tools are also available (but deprecated).
154
+
155
+ Example using Iconify Utils:
156
+
157
+ ```js
158
+
159
+ ```
160
+
161
+ Example using Iconify JSON Tools:
120
162
 
121
163
  ```js
122
164
  const fs = require('fs');
123
- const {SVG, Collection} = require('@iconify/json-tools');
165
+ const { SVG, Collection } = require('@iconify/json-tools');
124
166
 
125
167
  let collection = new Collection();
126
168
  collection.loadIconifyCollection('mdi');
127
- collection.listIcons(true).forEach(icon => {
128
- let svg = new SVG(collection.getIconData(icon));
129
- fs.writeFileSync('mdi-' + icon + '.svg', svg.getSVG({
130
- height: 'auto'
131
- }));
169
+ collection.listIcons(true).forEach((icon) => {
170
+ let svg = new SVG(collection.getIconData(icon));
171
+ fs.writeFileSync(
172
+ 'mdi-' + icon + '.svg',
173
+ svg.getSVG({
174
+ height: 'auto',
175
+ })
176
+ );
132
177
  });
133
178
  ```
134
179
 
@@ -146,7 +191,6 @@ foreach ($collection->listIcons(true) as $icon) {
146
191
  }
147
192
  ```
148
193
 
149
-
150
194
  ## License
151
195
 
152
196
  This is collection of works by various authors, not original collection.