2
0
mirror of https://github.com/iconify/collections-json.git synced 2024-09-16 17:19:03 +00:00

Change formatting rules to work with Prettier

This commit is contained in:
Vjacheslav Trushkin 2021-09-25 14:17:12 +03:00
parent a783e97b0f
commit 02b2abb627
13 changed files with 175 additions and 1135 deletions

View File

@ -2,9 +2,12 @@
root = true root = true
[*] [*]
end_of_line = lf
insert_final_newline = true
indent_style = space indent_style = space
indent_size = 2 indent_size = 2
end_of_line = lf
charset = utf-8 charset = utf-8
trim_trailing_whitespace = true trim_trailing_whitespace = true
insert_final_newline = true
[*.json]
indent_style = tab

View File

@ -1,3 +1,3 @@
{ {
"extends": "@antfu" "extends": "eslint:recommended"
} }

1
.prettierignore Normal file
View File

@ -0,0 +1 @@
*.json

7
.prettierrc Normal file
View File

@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"singleQuote": true,
"semi": true,
"quoteProps": "consistent",
"endOfLine": "lf"
}

View File

@ -38,7 +38,6 @@
"pathe": "^0.0.2" "pathe": "^0.0.2"
}, },
"devDependencies": { "devDependencies": {
"@antfu/eslint-config": "^0.9.0",
"@types/jest": "^27.0.1", "@types/jest": "^27.0.1",
"@types/node": "^16.9.1", "@types/node": "^16.9.1",
"@typescript-eslint/eslint-plugin": "^4.31.0", "@typescript-eslint/eslint-plugin": "^4.31.0",

View File

@ -8,9 +8,9 @@
* For the full copyright and license information, please view the license.txt * For the full copyright and license information, please view the license.txt
* file that is available in this file's directory. * file that is available in this file's directory.
*/ */
import { PathLike, promises as fs } from 'fs' import { PathLike, promises as fs } from 'fs';
import { fileURLToPath } from 'url' import { fileURLToPath } from 'url';
import { dirname, join } from 'pathe' import { dirname, join } from 'pathe';
/** /**
* Icon dimensions. * Icon dimensions.
@ -26,25 +26,25 @@ export interface IconifyDimensions {
* *
* @default 0 * @default 0
*/ */
left?: number left?: number;
/** /**
* Top position of viewBox. * Top position of viewBox.
* *
* @default 0 * @default 0
*/ */
top?: number top?: number;
/** /**
* Width of viewBox. * Width of viewBox.
* *
* @default 16 * @default 16
*/ */
width?: number width?: number;
/** /**
* height of viewBox. * height of viewBox.
* *
* @default 16 * @default 16
*/ */
height?: number height?: number;
} }
/** /**
@ -61,19 +61,19 @@ export interface IconifyTransformations {
* *
* @default 0 * @default 0
*/ */
rotate?: 0 | 1 | 2 | 3 rotate?: 0 | 1 | 2 | 3;
/** /**
* horizontal flip * horizontal flip
* *
* @default false * @default false
*/ */
hFlip?: boolean hFlip?: boolean;
/** /**
* vertical flip * vertical flip
* *
* @default false * @default false
*/ */
vFlip?: boolean vFlip?: boolean;
} }
/** /**
@ -85,26 +85,27 @@ export interface IconifyAlignment {
* *
* @default 'center' * @default 'center'
*/ */
horizontal: 'center' | 'left' | 'right' horizontal: 'center' | 'left' | 'right';
/** /**
* Icon vertical alignment. * Icon vertical alignment.
* *
* @default 'middle' * @default 'middle'
*/ */
vertical: 'middle' | 'top' | 'bottom' vertical: 'middle' | 'top' | 'bottom';
/** /**
* Slice? * Slice?
* *
* @default false * @default false
*/ */
slice: boolean slice: boolean;
} }
/** /**
* Combination of dimensions and transformations. * Combination of dimensions and transformations.
*/ */
export interface IconifyOptional extends IconifyDimensions, IconifyTransformations { export interface IconifyOptional
} extends IconifyDimensions,
IconifyTransformations {}
/** /**
* Alias. * Alias.
@ -113,7 +114,7 @@ export interface IconifyAlias extends IconifyOptional {
/** /**
* Parent icon index without prefix, required. * Parent icon index without prefix, required.
*/ */
parent: string parent: string;
// IconifyOptional properties. // IconifyOptional properties.
// Alias should have only properties that it overrides. // Alias should have only properties that it overrides.
@ -127,7 +128,7 @@ export interface IconifyIcon extends IconifyOptional {
/** /**
* Icon body: <path d="..." />, required. * Icon body: <path d="..." />, required.
*/ */
body: string body: string;
// IconifyOptional properties. // IconifyOptional properties.
// If property is missing in JSON file, look in root object for default value. // If property is missing in JSON file, look in root object for default value.
@ -145,7 +146,7 @@ interface APIIconAttributes {
* *
* @default false * @default false
*/ */
hidden?: boolean hidden?: boolean;
} }
export interface ExtendedIconifyIcon extends IconifyIcon, APIIconAttributes {} export interface ExtendedIconifyIcon extends IconifyIcon, APIIconAttributes {}
@ -158,7 +159,7 @@ export interface IconifyIcons {
/** /**
* Index is name of icon, without prefix. Value is ExtendedIconifyIcon object. * Index is name of icon, without prefix. Value is ExtendedIconifyIcon object.
*/ */
[index: string]: ExtendedIconifyIcon [index: string]: ExtendedIconifyIcon;
} }
/** /**
@ -168,7 +169,7 @@ export interface IconifyAliases {
/** /**
* Index is name of icon, without prefix. Value is ExtendedIconifyAlias object. * Index is name of icon, without prefix. Value is ExtendedIconifyAlias object.
*/ */
[index: string]: ExtendedIconifyAlias [index: string]: ExtendedIconifyAlias;
} }
/** /**
@ -178,78 +179,82 @@ export interface IconifyInfo {
/** /**
* Icon set name. * Icon set name.
*/ */
name: string name: string;
/** /**
* Total number of icons. * Total number of icons.
*/ */
total?: number total?: number;
/** /**
* Version string. * Version string.
*/ */
version?: string version?: string;
/** /**
* Author information. * Author information.
*/ */
author: string | { author:
/** | string
* Author name. | {
*/ /**
name: string * Author name.
/** */
* Link to author's website or icon set website. name: string;
*/ /**
url?: string * Link to author's website or icon set website.
} */
url?: string;
};
/** /**
* Link to author's website or icon set website. * Link to author's website or icon set website.
*/ */
url?: string url?: string;
/** /**
* License. * License.
*/ */
license: string | { license:
/** | string
* Human readable license. | {
*/ /**
title: string * Human readable license.
/** */
* SPDX license identifier. title: string;
*/ /**
spdx?: string * SPDX license identifier.
/** */
* License URL. spdx?: string;
*/ /**
url?: string * License URL.
} */
url?: string;
};
/** /**
* License URL. * License URL.
*/ */
licenseURL?: string licenseURL?: string;
/** /**
* Array of icons that should be used for samples in icon sets list. * Array of icons that should be used for samples in icon sets list.
*/ */
samples: string[] samples: string[];
/** /**
* Icon grid: number or array of numbers. * Icon grid: number or array of numbers.
*/ */
height?: number | number[] height?: number | number[];
/** /**
* Display height for samples: 16 - 24. * Display height for samples: 16 - 24.
* *
* @default 16 * @default 16
*/ */
displayHeight?: number displayHeight?: number;
/** /**
* Category on Iconify collections list. * Category on Iconify collections list.
*/ */
category?: string category?: string;
/** /**
* Palette status. * Palette status.
* *
* True if icons have predefined color scheme, false if icons use currentColor. * 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. * Icon set should not mix icons with and without palette to simplify search.
*/ */
palette: string | boolean palette: string | boolean;
} }
/** /**
@ -265,7 +270,7 @@ export interface LegacyIconifyThemes {
/** /**
* Theme title. * Theme title.
*/ */
title: string title: string;
/** /**
* Icon prefix or suffix, including dash. * Icon prefix or suffix, including dash.
* *
@ -273,7 +278,7 @@ export interface LegacyIconifyThemes {
* *
* Example: 'baseline-' * Example: 'baseline-'
*/ */
prefix?: string prefix?: string;
/** /**
* Icon suffix or suffix, including dash. * Icon suffix or suffix, including dash.
* *
@ -281,8 +286,8 @@ export interface LegacyIconifyThemes {
* *
* Example: '-filled' * Example: '-filled'
*/ */
suffix?: string suffix?: string;
} };
} }
/** /**
@ -294,7 +299,7 @@ export interface IconifyChars {
* *
* Value is icon name. * Value is icon name.
*/ */
[index: string]: string [index: string]: string;
} }
/** /**
@ -307,7 +312,7 @@ export interface IconifyCategories {
* Value is array of icons that belong to that category. * Value is array of icons that belong to that category.
* Each icon can belong to multiple categories or no categories. * Each icon can belong to multiple categories or no categories.
*/ */
[index: string]: string[] [index: string]: string[];
} }
/** /**
@ -319,35 +324,35 @@ export interface IconifyMetaData {
* *
* Used for public icon sets, can be skipped for private icon sets. * Used for public icon sets, can be skipped for private icon sets.
*/ */
info?: IconifyInfo info?: IconifyInfo;
/** /**
* Characters used in font. * Characters used in font.
* *
* Used for searching by character for icon sets imported from font, exporting icon set to font. * Used for searching by character for icon sets imported from font, exporting icon set to font.
*/ */
chars?: IconifyChars chars?: IconifyChars;
/** /**
* Categories. * Categories.
* *
* Used for filtering icons. * Used for filtering icons.
*/ */
categories?: IconifyCategories categories?: IconifyCategories;
/** /**
* Optional themes (old format). * Optional themes (old format).
*/ */
themes?: LegacyIconifyThemes themes?: LegacyIconifyThemes;
/** /**
* Optional themes prefixes (new format). * Optional themes prefixes (new format).
* *
* Key is prefix, value is title. * Key is prefix, value is title.
*/ */
prefixes?: Record<string, string> prefixes?: Record<string, string>;
/** /**
* Optional themes suffixes (new format). * Optional themes suffixes (new format).
* *
* Key is suffix, value is title. * Key is suffix, value is title.
*/ */
suffixes?: Record<string, string> suffixes?: Record<string, string>;
} }
/** /**
@ -359,25 +364,25 @@ export interface IconifyJSON extends IconifyOptional, IconifyMetaData {
/** /**
* Prefix for icons in JSON file, required. * Prefix for icons in JSON file, required.
*/ */
prefix: string prefix: string;
/** /**
* API provider, optional. * API provider, optional.
*/ */
provider?: string provider?: string;
/** /**
* List of icons, required. * List of icons, required.
*/ */
icons: IconifyIcons icons: IconifyIcons;
/** /**
* Optional aliases. * Optional aliases.
*/ */
aliases?: IconifyAliases aliases?: IconifyAliases;
/** /**
* Optional list of missing icons. * Optional list of missing icons.
* *
* Returned by Iconify API when querying for icons that do not exist. * Returned by Iconify API when querying for icons that do not exist.
*/ */
not_found?: string[] not_found?: string[];
// IconifyOptional properties that are used as default values for icons when icon is missing value. // 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. // If property exists in both icon and root, use value from icon.
// This is used to reduce duplication. // This is used to reduce duplication.
@ -387,14 +392,15 @@ export interface IconifyJSON extends IconifyOptional, IconifyMetaData {
* Collection info map * Collection info map
*/ */
export type IconifyMetaDataCollection = { export type IconifyMetaDataCollection = {
[prefix: string]: IconifyMetaData [prefix: string]: IconifyMetaData;
} };
const _dirname = typeof __dirname !== 'undefined' const _dirname =
? __dirname typeof __dirname !== 'undefined'
: dirname(fileURLToPath(import.meta.url)) ? __dirname
: dirname(fileURLToPath(import.meta.url));
const dir = join(_dirname, '/..') const dir = join(_dirname, '/..');
// todo@userquin: cleanup // todo@userquin: cleanup
// console.log(`_dirname: ${_dirname}`) // console.log(`_dirname: ${_dirname}`)
@ -420,7 +426,8 @@ const dir = join(_dirname, '/..')
* @param {string} name Collection name * @param {string} name Collection name
* @returns {string} Path to collection json file * @returns {string} Path to collection json file
*/ */
export const locate = (name: string): PathLike => join(dir, `./json/${name}.json`) export const locate = (name: string): PathLike =>
join(dir, `./json/${name}.json`);
/** /**
* Loads a collection. * Loads a collection.
@ -428,9 +435,9 @@ export const locate = (name: string): PathLike => join(dir, `./json/${name}.json
* @param {PathLike} path The path to locate the `json` collection file. * @param {PathLike} path The path to locate the `json` collection file.
* @return {Promise<IconifyJSON>} * @return {Promise<IconifyJSON>}
*/ */
export const loadCollection = async(path: PathLike): Promise<IconifyJSON> => { export const loadCollection = async (path: PathLike): Promise<IconifyJSON> => {
return JSON.parse(await fs.readFile(path, 'utf8')) return JSON.parse(await fs.readFile(path, 'utf8'));
} };
/** /**
* Get a collection. * Get a collection.
@ -438,15 +445,18 @@ export const loadCollection = async(path: PathLike): Promise<IconifyJSON> => {
* @param {string} name The name of the collection * @param {string} name The name of the collection
* @return {Promise<IconifyJSON>} * @return {Promise<IconifyJSON>}
*/ */
export const lookupCollection = async(name: string): Promise<IconifyJSON> => { export const lookupCollection = async (name: string): Promise<IconifyJSON> => {
return await loadCollection(locate(name)) return await loadCollection(locate(name));
} };
/** /**
* Get list of collections info. * Get list of collections info.
* *
* @return {Promise<IconifyMetaDataCollection>} * @return {Promise<IconifyMetaDataCollection>}
*/ */
export const lookupCollections = async(): Promise<IconifyMetaDataCollection> => { export const lookupCollections =
return JSON.parse(await fs.readFile(join(dir, './collections.json'), 'utf8')) async (): Promise<IconifyMetaDataCollection> => {
} return JSON.parse(
await fs.readFile(join(dir, './collections.json'), 'utf8')
);
};

View File

@ -1,4 +1,4 @@
import { lookupCollection, lookupCollections } from '../dist' import { lookupCollection, lookupCollections } from '../dist';
import { lookupCollectionTest } from './loadCollection.test' import { lookupCollectionTest } from './loadCollection.test';
lookupCollectionTest(lookupCollection, lookupCollections) lookupCollectionTest(lookupCollection, lookupCollections);

View File

@ -1,4 +1,4 @@
import { lookupCollectionTest } from './loadCollection.test' import { lookupCollectionTest } from './loadCollection.test';
import { lookupCollection, lookupCollections } from '.' import { lookupCollection, lookupCollections } from '.';
lookupCollectionTest(lookupCollection, lookupCollections) lookupCollectionTest(lookupCollection, lookupCollections);

View File

@ -1,32 +1,34 @@
import type { IconifyMetaDataCollection } from '.' import type { IconifyMetaDataCollection } from '.';
import { IconifyJSON } from '.' import { IconifyJSON } from '.';
export const lookupCollectionTest = ( export const lookupCollectionTest = (
lookupCollection: (name: string) => Promise<IconifyJSON>, lookupCollection: (name: string) => Promise<IconifyJSON>,
lookupCollections: () => Promise<IconifyMetaDataCollection>, lookupCollections: () => Promise<IconifyMetaDataCollection>
) => { ) => {
let collections: IconifyMetaDataCollection let collections: IconifyMetaDataCollection;
describe('lookupCollection and lookupCollections', () => { describe('lookupCollection and lookupCollections', () => {
beforeAll(() => { beforeAll(() => {
return lookupCollections().then((c) => { return lookupCollections().then((c) => {
collections = c collections = c;
return Promise.resolve(c) return Promise.resolve(c);
}) });
}) });
test('lookupCollections has data', () => { test('lookupCollections has data', () => {
expect(collections ? Object.keys(collections).length : 0).toBeGreaterThan(0) expect(collections ? Object.keys(collections).length : 0).toBeGreaterThan(
}) 0
test('mdi collection has prefix mdi', async() => { );
const collection = await lookupCollection('mdi') });
expect(collection.prefix).toBe('mdi') test('mdi collection has prefix mdi', async () => {
}) const collection = await lookupCollection('mdi');
test('websymbol collection has prefix websymbol', async() => { expect(collection.prefix).toBe('mdi');
const collection = await lookupCollection('websymbol') });
expect(collection.prefix).toBe('websymbol') test('websymbol collection has prefix websymbol', async () => {
}) const collection = await lookupCollection('websymbol');
test('fa collection has prefix fa', async() => { expect(collection.prefix).toBe('websymbol');
const collection = await lookupCollection('fa') });
expect(collection.prefix).toBe('fa') test('fa collection has prefix fa', async () => {
}) const collection = await lookupCollection('fa');
}) expect(collection.prefix).toBe('fa');
} });
});
};

View File

@ -1,4 +1,4 @@
import { locate } from '../dist' import { locate } from '../dist';
import { locateTest } from './locate.test' import { locateTest } from './locate.test';
locateTest(locate) locateTest(locate);

View File

@ -1,4 +1,4 @@
import { locateTest } from './locate.test' import { locateTest } from './locate.test';
import { locate } from '.' import { locate } from '.';
locateTest(locate) locateTest(locate);

View File

@ -1,10 +1,10 @@
import { PathLike } from 'fs' import { PathLike } from 'fs';
import { resolve, normalize } from 'pathe' import { resolve, normalize } from 'pathe';
export const locateTest = (locate: (name: string) => PathLike) => { export const locateTest = (locate: (name: string) => PathLike) => {
test('mdi resolves the json collection', () => { test('mdi resolves the json collection', () => {
const received = locate('mdi') as string const received = locate('mdi') as string;
const expected = normalize(resolve('./json/mdi.json')) const expected = normalize(resolve('./json/mdi.json'));
expect(received).toBe(expected) expect(received).toBe(expected);
}) });
} };

1020
yarn.lock

File diff suppressed because it is too large Load Diff