favicons
Version:
Favicon generator for Node.js
114 lines (113 loc) • 4.04 kB
text/typescript
import { Transform, TransformCallback } from "stream";
import sharp from "sharp";
//#region src/platforms/index.d.ts
type PlatformName = "android" | "appleIcon" | "appleStartup" | "favicons" | "windows" | "yandex";
//#endregion
//#region src/config/defaults.d.ts
interface IconSize {
readonly width: number;
readonly height: number;
}
interface IconOptions {
readonly sizes: IconSize[];
readonly offset?: number;
readonly background?: string | boolean;
readonly transparent: boolean;
readonly rotate: boolean;
readonly purpose?: string;
readonly pixelArt?: boolean;
}
interface FileOptions {
readonly manifestFileName?: string;
}
interface ShortcutOptions {
readonly name: string;
readonly short_name?: string | undefined;
readonly description?: string | undefined;
readonly url: string;
readonly icon?: string | Buffer | (string | Buffer)[] | undefined;
}
interface Application {
readonly platform?: string;
readonly url?: string;
readonly id?: string;
}
interface OutputOptions {
readonly images?: boolean | undefined;
readonly files?: boolean | undefined;
readonly html?: boolean | undefined;
}
interface FaviconOptions {
readonly path?: string;
readonly appName?: string;
readonly appShortName?: string;
readonly appDescription?: string;
readonly developerName?: string;
readonly developerURL?: string;
readonly cacheBustingQueryParam?: string | null;
readonly dir?: string;
readonly lang?: string;
readonly background?: string;
readonly theme_color?: string;
readonly appleStatusBarStyle?: string;
readonly display?: string;
readonly orientation?: string;
readonly scope?: string;
readonly start_url?: string;
readonly version?: string;
readonly pixel_art?: boolean;
readonly loadManifestWithCredentials?: boolean;
readonly manifestRelativePaths?: boolean;
readonly manifestMaskable?: boolean | string | Buffer | (string | Buffer)[];
readonly preferRelatedApplications?: boolean;
readonly relatedApplications?: Application[];
readonly icons?: Partial<Record<PlatformName, IconOptions | boolean | string[]>> | undefined;
readonly files?: Record<PlatformName, FileOptions>;
readonly shortcuts?: ShortcutOptions[] | undefined;
readonly output?: OutputOptions;
}
type FullFaviconOptions = Omit<FaviconOptions, "icons" | "output"> & {
readonly icons: Record<PlatformName, IconOptions | boolean | string[]>;
readonly output: OutputOptions;
};
//#endregion
//#region src/index.d.ts
interface FaviconImage {
readonly name: string;
readonly contents: Buffer;
}
interface FaviconFile {
readonly name: string;
readonly contents: string;
}
declare const config: {
defaults: FullFaviconOptions;
};
type FaviconHtmlElement = string;
interface FaviconHtmlTag {
readonly tag: string;
readonly attrs: Partial<Record<string, string | boolean>>;
}
interface FaviconResponse {
readonly images: FaviconImage[];
readonly files: FaviconFile[];
readonly html: FaviconHtmlElement[];
readonly htmlTags: FaviconHtmlTag[];
}
type FaviconsSource = string | Buffer | (string | Buffer)[];
declare function favicons(source: FaviconsSource, options?: FaviconOptions): Promise<FaviconResponse>;
interface FaviconStreamOptions extends FaviconOptions {
readonly html?: string;
readonly pipeHTML?: boolean;
readonly emitBuffers?: boolean;
}
type HandleHTML = (html: FaviconHtmlElement[], htmlTags: FaviconHtmlTag[]) => void;
declare class FaviconStream extends Transform {
#private;
constructor(options: FaviconStreamOptions, handleHTML?: HandleHTML);
_transform(file: any, // eslint-disable-line @typescript-eslint/no-explicit-any -- superclass uses any
_encoding: BufferEncoding, callback: TransformCallback): void;
}
declare function stream(options: FaviconStreamOptions, handleHTML: HandleHTML): FaviconStream;
//#endregion
export { FaviconFile, FaviconHtmlElement, FaviconHtmlTag, FaviconImage, type FaviconOptions, FaviconResponse, FaviconStreamOptions, FaviconsSource, HandleHTML, config, favicons as default, favicons, stream };