itgalaxy / favicons

Favicons generator for Node.js
MIT License
1.19k stars 164 forks source link

Improved typescript types #389

Closed IdkMan2Usertive closed 2 years ago

IdkMan2Usertive commented 2 years ago

I have created an improved version of the types for this project.

Improvements include:

declare module 'favicons' {
  import sharp from 'sharp';

  export interface Application {
    readonly platform?: string;
    readonly url?: string;
    readonly id?: string;
  }
  export interface IconSize {
    readonly width: number;
    readonly height: number;
  }
  export interface IconOptions {
    readonly sizes: IconSize[];
    readonly offset?: number;
    readonly background?: string | boolean;
    readonly transparent: boolean;
    readonly rotate: boolean;
    readonly purpose?: string;
    readonly pixelArt?: boolean;
  }
  export interface FileOptions {
    readonly manifestFileName?: string;
  }
  export interface ShortcutOptions {
    readonly name: string;
    readonly short_name?: string;
    readonly description?: string;
    readonly url: string;
    readonly icon?: string | string[] | Buffer | Buffer[];
  }
  export interface OutputOptions {
    readonly images?: boolean;
    readonly files?: boolean;
    readonly html?: boolean;
  }
  export interface RawImage {
    data: Buffer;
    info: typeof sharp.OutputInfo;
  }
  export interface FaviconOptions {
    readonly path?: string;
    readonly appName?: string;
    readonly appShortName?: string;
    readonly appDescription?: string;
    readonly developerName?: string;
    readonly developerURL?: string;
    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 | string[] | Buffer | Buffer[];
    readonly preferRelatedApplications?: boolean;
    readonly relatedApplications?: Application[];
    readonly icons?: Record<'android' | 'appleIcon' | 'appleStartup' | 'favicons' | 'windows' | 'yandex', IconOptions | boolean | string[]>;
    readonly files?: Record<string, FileOptions>;
    readonly shortcuts?: ShortcutOptions[];
    readonly output?: OutputOptions;
  }
  export interface FaviconImage {
    readonly name: string;
    readonly contents: Buffer | RawImage;
  }
  export interface FaviconFile {
    readonly name: string;
    readonly contents: string;
  }
  export interface FaviconResponse {
    readonly images: FaviconImage[];
    readonly files: FaviconFile[];
    readonly html: string[];
  }

  export function favicons(source: string | string[] | Buffer | Buffer[], options?: FaviconOptions): Promise<FaviconResponse>;
  export function favicons(source: string | string[] | Buffer | Buffer[], next?: (error: unknown, response: FaviconResponse) => void): void;
  export function favicons(source: string | string[] | Buffer | Buffer[], options?: FaviconOptions, next?: unknown): unknown;

}
andy128k commented 2 years ago

Thanks for this!

Unfortunately, second signature of favicons doesn't work with current code (v7.0.0-beta.x). But you've actually influenced me to review types and to do #391.