2
0
mirror of https://github.com/iconify/collections-json.git synced 2024-12-22 10:58:56 +00:00

Use @iconify/types for types, convert info, publish next version

This commit is contained in:
Vjacheslav Trushkin 2021-09-30 11:59:53 +03:00
parent 401dca6ab6
commit 86d9e44642
7 changed files with 1599 additions and 1217 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
"name": "@iconify/json",
"description": "Iconify icons collection in JSON format",
"license": "MIT",
"version": "1.1.408",
"version": "2.0.0-beta.0",
"homepage": "https://iconify.design/icon-sets/",
"bugs": "https://github.com/iconify/collections-json/issues",
"repository": {
@ -32,9 +32,11 @@
"test-esm": "jest --clearCache && cross-env NODE_OPTIONS=--experimental-vm-modules npx jest --config=jest.esm.config.ts",
"test-cjs": "yarn build && jest --clearCache && jest --config=jest.cjs.config.ts",
"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",
"test-locate-cjs": "yarn build && jest --clearCache && jest --config=jest.cjs.config.ts src/locate.cjs.test.ts -i"
"test-locate-cjs": "yarn build && jest --clearCache && jest --config=jest.cjs.config.ts src/locate.cjs.test.ts -i",
"test": "yarn test-esm && yarn test-cjs && yarn test-locate-esm && yarn test-locate-cjs"
},
"dependencies": {
"@iconify/types": "^1.0.9",
"pathe": "^0.0.2"
},
"devDependencies": {

View File

@ -8,391 +8,17 @@
* For the full copyright and license information, please view the license.txt
* file that is available in this file's directory.
*/
import { PathLike, promises as fs } from 'fs';
import type { PathLike } from 'fs';
import { promises as fs } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'pathe';
/**
* Icon dimensions.
*
* Used in:
* icon (as is)
* alias (overwrite icon's properties)
* root of JSON file (default values)
*/
export interface IconifyDimensions {
/**
* Left position of viewBox.
*
* @default 0
*/
left?: number;
/**
* Top position of viewBox.
*
* @default 0
*/
top?: number;
/**
* Width of viewBox.
*
* @default 16
*/
width?: number;
/**
* height of viewBox.
*
* @default 16
*/
height?: number;
}
/**
* Icon transformations.
*
* Used in:
* icon (as is)
* alias (merged with icon's properties)
* root of JSON file (default values)
*/
export interface IconifyTransformations {
/**
* rotation, values: 0 = 0deg, 1 = 90deg, 2 = 180deg, 3 = 270deg
*
* @default 0
*/
rotate?: 0 | 1 | 2 | 3;
/**
* horizontal flip
*
* @default false
*/
hFlip?: boolean;
/**
* vertical flip
*
* @default false
*/
vFlip?: boolean;
}
/**
* Icon alignment.
*/
export interface IconifyAlignment {
/**
* Icon horizontal alignment.
*
* @default 'center'
*/
horizontal: 'center' | 'left' | 'right';
/**
* Icon vertical alignment.
*
* @default 'middle'
*/
vertical: 'middle' | 'top' | 'bottom';
/**
* Slice?
*
* @default false
*/
slice: boolean;
}
/**
* Combination of dimensions and transformations.
*/
export interface IconifyOptional
extends IconifyDimensions,
IconifyTransformations {}
/**
* Alias.
*/
export interface IconifyAlias extends IconifyOptional {
/**
* Parent icon index without prefix, required.
*/
parent: string;
// IconifyOptional properties.
// Alias should have only properties that it overrides.
// Transformations are merged, not overridden. See IconifyTransformations comments.
}
/**
* Icon.
*/
export interface IconifyIcon extends IconifyOptional {
/**
* Icon body: <path d="..." />, required.
*/
body: string;
// IconifyOptional properties.
// If property is missing in JSON file, look in root object for default value.
}
/**
* Icon with optional parameters that are provided by API and affect only search
*/
interface APIIconAttributes {
/**
* True if icon is hidden.
*
* Used in icon sets to keep icons that no longer exist, but should still be accessible
* from API, preventing websites from breaking when icon is removed by developer.
*
* @default false
*/
hidden?: boolean;
}
export interface ExtendedIconifyIcon extends IconifyIcon, APIIconAttributes {}
export interface ExtendedIconifyAlias extends IconifyAlias, APIIconAttributes {}
/**
* "icons" field of JSON file.
*/
export interface IconifyIcons {
/**
* Index is name of icon, without prefix. Value is ExtendedIconifyIcon object.
*/
[index: string]: ExtendedIconifyIcon;
}
/**
* "aliases" field of JSON file.
*/
export interface IconifyAliases {
/**
* Index is name of icon, without prefix. Value is ExtendedIconifyAlias object.
*/
[index: string]: ExtendedIconifyAlias;
}
/**
* Iconify collection info.
*/
export interface IconifyInfo {
/**
* Icon set name.
*/
name: string;
/**
* Total number of icons.
*/
total?: number;
/**
* Version string.
*/
version?: string;
/**
* Author information.
*/
author:
| string
| {
/**
* Author name.
*/
name: string;
/**
* Link to author's website or icon set website.
*/
url?: string;
};
/**
* Link to author's website or icon set website.
*/
url?: string;
/**
* License.
*/
license:
| string
| {
/**
* Human readable license.
*/
title: string;
/**
* SPDX license identifier.
*/
spdx?: string;
/**
* License URL.
*/
url?: string;
};
/**
* License URL.
*/
licenseURL?: string;
/**
* Array of icons that should be used for samples in icon sets list.
*/
samples: string[];
/**
* Icon grid: number or array of numbers.
*/
height?: number | number[];
/**
* Display height for samples: 16 - 24.
*
* @default 16
*/
displayHeight?: number;
/**
* Category on Iconify collections list.
*/
category?: string;
/**
* Palette status.
*
* True if icons have predefined color scheme, false if icons use currentColor.
* Icon set should not mix icons with and without palette to simplify search.
*/
palette: string | boolean;
}
/**
* Optional themes, old format.
*
* Deprecated because format is unnecessary complicated. Key is meaningless, suffixes and prefixes are mixed together.
*/
export interface LegacyIconifyThemes {
/**
* Key is unique string.
*/
[index: string]: {
/**
* Theme title.
*/
title: string;
/**
* Icon prefix or suffix, including dash.
*
* All icons that start with prefix and end with suffix belong to theme.
*
* Example: 'baseline-'
*/
prefix?: string;
/**
* Icon suffix or suffix, including dash.
*
* All icons that start with prefix and end with suffix belong to theme.
*
* Example: '-filled'
*/
suffix?: string;
};
}
/**
* Characters used in font.
*/
export interface IconifyChars {
/**
* Index is character, such as "f000".
*
* Value is icon name.
*/
[index: string]: string;
}
/**
* Icon categories
*/
export interface IconifyCategories {
/**
* Index is category title, such as "Weather".
*
* Value is array of icons that belong to that category.
* Each icon can belong to multiple categories or no categories.
*/
[index: string]: string[];
}
/**
* Meta data stored in JSON file, used for browsing icon set.
*/
export interface IconifyMetaData {
/**
* Icon set information block.
*
* Used for public icon sets, can be skipped for private icon sets.
*/
info?: IconifyInfo;
/**
* Characters used in font.
*
* Used for searching by character for icon sets imported from font, exporting icon set to font.
*/
chars?: IconifyChars;
/**
* Categories.
*
* Used for filtering icons.
*/
categories?: IconifyCategories;
/**
* Optional themes (old format).
*/
themes?: LegacyIconifyThemes;
/**
* Optional themes prefixes (new format).
*
* Key is prefix, value is title.
*/
prefixes?: Record<string, string>;
/**
* Optional themes suffixes (new format).
*
* Key is suffix, value is title.
*/
suffixes?: Record<string, string>;
}
/**
* JSON structure.
*
* All optional values can exist in root of JSON file, used as defaults.
*/
export interface IconifyJSON extends IconifyOptional, IconifyMetaData {
/**
* Prefix for icons in JSON file, required.
*/
prefix: string;
/**
* API provider, optional.
*/
provider?: string;
/**
* List of icons, required.
*/
icons: IconifyIcons;
/**
* Optional aliases.
*/
aliases?: IconifyAliases;
/**
* Optional list of missing icons.
*
* Returned by Iconify API when querying for icons that do not exist.
*/
not_found?: string[];
// IconifyOptional properties that are used as default values for icons when icon is missing value.
// If property exists in both icon and root, use value from icon.
// This is used to reduce duplication.
}
import type { IconifyInfo, IconifyJSON } from '@iconify/types';
/**
* Collection info map
*/
export type IconifyMetaDataCollection = {
[prefix: string]: IconifyMetaData;
[prefix: string]: IconifyInfo;
};
const _dirname =
@ -402,24 +28,6 @@ const _dirname =
const dir = join(_dirname, '/..');
// todo@userquin: cleanup
// console.log(`_dirname: ${_dirname}`)
// if (typeof __dirname === 'undefined') {
// if (false/* process.platform === 'win32' */) {
// console.log(`_dirname3: ${dirname(import.meta.url)}`)
// console.log(`_dirname3: ${join(dirname(import.meta.url), '/..')}`)
// console.log(`_dirname3: ${resolve(join(dirname(import.meta.url), '/..'))}`)
// }
// else {
// console.log(`_dirname2: ${dirname(fileURLToPath(import.meta.url))}`)
// console.log(`_dirname2: ${join(fileURLToPath(dirname(import.meta.url)), '/..')}`)
// console.log(`_dirname2: ${normalize(join(dirname(fileURLToPath(import.meta.url)), '/..'))}`)
// }
// }
// console.log(`Normalized _dirname: ${normalize(_dirname)}`)
// console.log(`Resolve _dirname: ${resolve(_dirname, '..')}`)
// console.log(`Normalized _dirname: ${dir}`)
/**
* Locate JSON file
*

View File

@ -1,5 +1,5 @@
import type { IconifyJSON } from '@iconify/types';
import type { IconifyMetaDataCollection } from '.';
import { IconifyJSON } from '.';
export const lookupCollectionTest = (
lookupCollection: (name: string) => Promise<IconifyJSON>,

View File

@ -1,4 +1,4 @@
import { PathLike } from 'fs';
import type { PathLike } from 'fs';
import { resolve, normalize } from 'pathe';
export const locateTest = (locate: (name: string) => PathLike) => {

View File

@ -9,6 +9,7 @@
"moduleResolution": "Node",
"resolveJsonModule": true,
"skipLibCheck": true,
"importsNotUsedAsValues": "error"
},
"exclude": [
"**/dist",

View File

@ -350,6 +350,11 @@
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.0.tgz#87de7af9c231826fdd68ac7258f77c429e0e5fcf"
integrity sha512-wdppn25U8z/2yiaT6YGquE6X8sSv7hNMWSXYSSU1jGv/yd6XqjXgTDJ8KP4NgjTXfJ3GbRjeeb8RTV7a/VpM+w==
"@iconify/types@^1.0.9":
version "1.0.9"
resolved "https://registry.yarnpkg.com/@iconify/types/-/types-1.0.9.tgz#c0dfcb3c325e808aa1830979108d5def106bdb61"
integrity sha512-ALO6IGXBEztcySLq+vGJrgUJqGgiZJ8sTQ8mM6e3i77okM9fw8F23h6GLbbaMz/pNfeK8QHJBAOmx3LjhZ3YZw==
"@istanbuljs/load-nyc-config@^1.0.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz#fd3db1d59ecf7cf121e80650bb86712f9b55eced"