You've already forked simple-icons
mirror of
https://github.com/simple-icons/simple-icons.git
synced 2025-11-23 21:34:49 +02:00
Add type declarations for data JSON entry (#13510)
This commit is contained in:
59
data/simple-icons.d.ts
vendored
Normal file
59
data/simple-icons.d.ts
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
// @ts-check
|
||||
/**
|
||||
* @file Type definitions for icons JSON data.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The data for a Simple Icon.
|
||||
*/
|
||||
export type IconData = {
|
||||
title: string;
|
||||
hex: string;
|
||||
source: string;
|
||||
slug?: string;
|
||||
guidelines?: string;
|
||||
license?: Omit<SPDXLicense, 'url'> | CustomLicense;
|
||||
aliases?: Aliases;
|
||||
};
|
||||
|
||||
/**
|
||||
* The aliases for a Simple Icon.
|
||||
*
|
||||
* Corresponds to the `aliases` property in the *data/simple-icons.json* file.
|
||||
* @see {@link https://github.com/simple-icons/simple-icons/blob/develop/CONTRIBUTING.md#aliases Aliases}
|
||||
*/
|
||||
export type Aliases = {
|
||||
aka?: string[];
|
||||
dup?: DuplicateAlias[];
|
||||
loc?: Record<string, string>;
|
||||
old?: string[];
|
||||
};
|
||||
|
||||
export type DuplicateAlias = {
|
||||
title: string;
|
||||
hex?: string;
|
||||
guidelines?: string;
|
||||
loc?: Record<string, string>;
|
||||
};
|
||||
|
||||
/**
|
||||
* The license for a Simple Icon.
|
||||
* @see {@link https://github.com/simple-icons/simple-icons/blob/develop/CONTRIBUTING.md#optional-data Optional Data}
|
||||
*/
|
||||
export type License = SPDXLicense | CustomLicense;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
export type SPDXLicense = {
|
||||
type: string;
|
||||
url: string;
|
||||
};
|
||||
|
||||
export type CustomLicense = {
|
||||
type: 'custom';
|
||||
url: string;
|
||||
};
|
||||
|
||||
declare const icons: IconData[];
|
||||
|
||||
export default icons;
|
||||
export = icons;
|
||||
64
package.json
64
package.json
@@ -30,63 +30,31 @@
|
||||
"type": "commonjs",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.mjs"
|
||||
},
|
||||
"module": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"default": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.js"
|
||||
}
|
||||
"types": "./index.d.ts",
|
||||
"import": "./index.mjs",
|
||||
"module": "./index.mjs",
|
||||
"require": "./index.js",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"./icons": {
|
||||
"import": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index-icons.mjs"
|
||||
},
|
||||
"module": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index-icons.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index-icons.js"
|
||||
},
|
||||
"default": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index-icons.js"
|
||||
}
|
||||
"types": "./index.d.ts",
|
||||
"import": "./index-icons.mjs",
|
||||
"module": "./index-icons.mjs",
|
||||
"require": "./index-icons.js",
|
||||
"default": "./index-icons.js"
|
||||
},
|
||||
"./icons/*": [
|
||||
"./icons/*"
|
||||
],
|
||||
"./sdk": {
|
||||
"import": {
|
||||
"types": "./sdk.d.ts",
|
||||
"default": "./sdk.mjs"
|
||||
},
|
||||
"module": {
|
||||
"types": "./sdk.d.ts",
|
||||
"default": "./sdk.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./sdk.d.ts",
|
||||
"default": "./sdk.js"
|
||||
},
|
||||
"default": {
|
||||
"types": "./sdk.d.ts",
|
||||
"default": "./sdk.js"
|
||||
}
|
||||
"types": "./sdk.d.ts",
|
||||
"import": "./sdk.mjs",
|
||||
"module": "./sdk.mjs",
|
||||
"require": "./sdk.js",
|
||||
"default": "./sdk.js"
|
||||
},
|
||||
"./icons.json": {
|
||||
"types": "./data/simple-icons.d.ts",
|
||||
"import": "./data/simple-icons.json",
|
||||
"module": "./data/simple-icons.json",
|
||||
"require": "./data/simple-icons.json",
|
||||
|
||||
@@ -34,7 +34,7 @@ process.on('uncaughtException', (error) => {
|
||||
}
|
||||
});
|
||||
|
||||
/** @type {import('../sdk.js').IconData[]} */
|
||||
/** @type {import('../types.d.ts').IconData[]} */
|
||||
const iconsData = JSON.parse(await getIconsDataString());
|
||||
const jsonSchema = await getJsonSchemaData();
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ const iconObjectTemplateFile = path.resolve(
|
||||
/**
|
||||
* Merged type from icon data and icon JS object needed to build by reference
|
||||
* to not decrease performance in the build process.
|
||||
* @typedef {import('../../types.js').SimpleIcon & import('../../sdk.d.ts').IconData} IconDataAndObject
|
||||
* @typedef {import('../../types.js').SimpleIcon & import('../../types.d.ts').IconData} IconDataAndObject
|
||||
*/
|
||||
|
||||
const icons = await getIconsData();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import("../../sdk.mjs").IconData} IconData
|
||||
* @typedef {import("../../types.js").IconData} IconData
|
||||
* @typedef {import("../../types.js").CustomLicense} CustomLicense
|
||||
*/
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import path from 'node:path';
|
||||
import {collator, getIconSlug, getIconsDataPath, titleToSlug} from '../sdk.mjs';
|
||||
|
||||
/**
|
||||
* @typedef {import("../sdk.js").IconData} IconData
|
||||
* @typedef {import("../sdk.js").DuplicateAlias} DuplicateAlias
|
||||
* @typedef {import("../types.js").IconData} IconData
|
||||
* @typedef {import("../types.js").DuplicateAlias} DuplicateAlias
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
37
sdk.d.ts
vendored
37
sdk.d.ts
vendored
@@ -4,7 +4,9 @@
|
||||
* Types for Simple Icons SDK.
|
||||
*/
|
||||
|
||||
import type {CustomLicense, SPDXLicense} from './types.js';
|
||||
import type {IconData} from './types.d.ts';
|
||||
|
||||
export type {IconData, DuplicateAlias, Aliases} from './types.d.ts';
|
||||
|
||||
/**
|
||||
* The data for a third-party extension.
|
||||
@@ -23,39 +25,6 @@ type ThirdPartyExtensionSubject = {
|
||||
url: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* The aliases for a Simple Icon.
|
||||
*
|
||||
* Corresponds to the `aliases` property in the *data/simple-icons.json* file.
|
||||
* @see {@link https://github.com/simple-icons/simple-icons/blob/develop/CONTRIBUTING.md#aliases Aliases}
|
||||
*/
|
||||
export type Aliases = {
|
||||
aka?: string[];
|
||||
dup?: DuplicateAlias[];
|
||||
loc?: Record<string, string>;
|
||||
old?: string[];
|
||||
};
|
||||
|
||||
type DuplicateAlias = {
|
||||
title: string;
|
||||
hex?: string;
|
||||
guidelines?: string;
|
||||
loc?: Record<string, string>;
|
||||
};
|
||||
|
||||
/**
|
||||
* The data for a Simple Icon.
|
||||
*/
|
||||
export type IconData = {
|
||||
title: string;
|
||||
hex: string;
|
||||
source: string;
|
||||
slug?: string;
|
||||
guidelines?: string;
|
||||
license?: Omit<SPDXLicense, 'url'> | CustomLicense;
|
||||
aliases?: Aliases;
|
||||
};
|
||||
|
||||
/* The next code is autogenerated from sdk.mjs */
|
||||
/* eslint-disable */
|
||||
|
||||
|
||||
2
sdk.mjs
2
sdk.mjs
@@ -8,7 +8,7 @@ import path from 'node:path';
|
||||
|
||||
/**
|
||||
* @typedef {import("./sdk.d.ts").ThirdPartyExtension} ThirdPartyExtension
|
||||
* @typedef {import("./sdk.d.ts").IconData} IconData
|
||||
* @typedef {import("./types.js").IconData} IconData
|
||||
*/
|
||||
|
||||
/** @type {{ [key: string]: string }} */
|
||||
|
||||
@@ -13,7 +13,7 @@ const iconsDirectory = path.resolve(import.meta.dirname, '..', 'icons');
|
||||
|
||||
/**
|
||||
* Checks if icon data matches a subject icon.
|
||||
* @param {import('../sdk.d.ts').IconData} icon Icon data.
|
||||
* @param {import('../types.d.ts').IconData} icon Icon data.
|
||||
* @param {import('../types.d.ts').SimpleIcon} subject
|
||||
* Icon object to check against icon data.
|
||||
* @param {string} slug Icon data slug.
|
||||
|
||||
24
types.d.ts
vendored
24
types.d.ts
vendored
@@ -3,22 +3,16 @@
|
||||
* @file Types for Simple Icons package.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The license for a Simple Icon.
|
||||
* @see {@link https://github.com/simple-icons/simple-icons/blob/develop/CONTRIBUTING.md#optional-data Optional Data}
|
||||
*/
|
||||
export type License = SPDXLicense | CustomLicense;
|
||||
import type {License} from './data/simple-icons.d.ts';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
export type SPDXLicense = {
|
||||
type: string;
|
||||
url: string;
|
||||
};
|
||||
|
||||
export type CustomLicense = {
|
||||
type: 'custom';
|
||||
url: string;
|
||||
};
|
||||
export type {
|
||||
Aliases,
|
||||
CustomLicense,
|
||||
DuplicateAlias,
|
||||
IconData,
|
||||
License,
|
||||
SPDXLicense,
|
||||
} from './data/simple-icons.d.ts';
|
||||
|
||||
/**
|
||||
* The data for a Simple Icon as is exported by the npm package.
|
||||
|
||||
Reference in New Issue
Block a user