From 95427c2bb49d3d8b9c63ccbc8d17b18fa13ac6a8 Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Sun, 20 May 2018 16:03:46 -0700 Subject: [PATCH] Add typings for favicons --- types/favicons/favicons-tests.ts | 28 ++++++++++ types/favicons/index.d.ts | 93 ++++++++++++++++++++++++++++++++ types/favicons/tsconfig.json | 16 ++++++ types/favicons/tslint.json | 3 ++ 4 files changed, 140 insertions(+) create mode 100644 types/favicons/favicons-tests.ts create mode 100644 types/favicons/index.d.ts create mode 100644 types/favicons/tsconfig.json create mode 100644 types/favicons/tslint.json diff --git a/types/favicons/favicons-tests.ts b/types/favicons/favicons-tests.ts new file mode 100644 index 0000000000..485ea1d505 --- /dev/null +++ b/types/favicons/favicons-tests.ts @@ -0,0 +1,28 @@ +import favicons, { Configuration } from "favicons"; + +let config: Partial = { + path: "/foo/bar" +}; + +config = { + icons: { + android: true + } +}; + +let html = ""; +favicons("path/to/file.png", config, (err, res) => { + html = res.html.join(""); + + for (const { name, contents } of [...res.files, ...res.images]) { + html = name + contents.toString(); + } +}); + +favicons("file.png", (err, res) => { + html = res.html.join(""); + + for (const { name, contents } of [...res.files, ...res.images]) { + html = name + contents.toString(); + } +}); diff --git a/types/favicons/index.d.ts b/types/favicons/index.d.ts new file mode 100644 index 0000000000..47a9a9d24a --- /dev/null +++ b/types/favicons/index.d.ts @@ -0,0 +1,93 @@ +// Type definitions for favicons 5.1 +// Project: https://github.com/evilebottnawi/favicons/blob/master/package.json +// Definitions by: Mohsen Azimi +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/// + +export interface Configuration { + /** Path for overriding default icons path @default "/" */ + path: string; + /** Your application's name @default null */ + appName: string | null; + /** Your application's description @default null */ + appDescription: string | null; + /** Your (or your developer's) name @default null */ + developerName: string | null; + /** Your (or your developer's) URL @default null */ + developerURL: string | null; + /** Primary text direction for name, short_name, and description @default "auto" */ + dir: string; + /** Primary language for name and short_name @default "en-US */ + lang: string; + /** Background colour for flattened icons @default "#fff" */ + background: string; + /** Theme color user for example in Android's task switcher @default "#fff" */ + theme_color: string; + /** Preferred display mode: "fullscreen", "standalone", "minimal-ui" or "browser" @default "standalone" */ + display: "fullscreen" | "standalone" | "minimal-ui" | "browser"; + /** Default orientation: "any", "natural", "portrait" or "landscape" @default "any" */ + orientation: "any" | "natural" | "portrait" | "landscape"; + /** Start URL when launching the application from a device @default "/?homescreen=1" */ + start_url: string; + /** Your application's version string @default "1.0" */ + version: string; + /** Print logs to console? @default false */ + logging: boolean; + /** + * Platform Options: + * - offset - offset in percentage + * - background: + * * false - use default + * * true - force use default, e.g. set background for Android icons + * * color - set background for the specified icons + */ + icons: Partial<{ + /* Create Android homescreen icon. */ + android: boolean | { offset: string; background: string }; + /* Create Apple touch icons. */ + appleIcon: boolean | { offset: string; background: string }; + /* Create Apple startup images. */ + appleStartup: boolean | { offset: string; background: string }; + /* Create Opera Coast icon. */ + coast: boolean | { offset: string; background: string }; + /* Create regular favicons. */ + favicons: boolean; + /* Create Firefox OS icons. */ + firefox: boolean | { offset: string; background: string }; + /* Create Windows 8 tile icons. */ + windows: boolean | { background: string }; + /* Create Yandex browser icon. */ + yandex: boolean | { background: string }; + }>; +} + +export interface FavIconResponse { + images: Array<{ name: string; contents: Buffer }>; + files: Array<{ name: string; contents: Buffer }>; + html: string[]; +} + +export type Callback = (error: Error | null, response: FavIconResponse) => void; + +/** You can programmatically access Favicons configuration (icon filenames, HTML, manifest files, etc) with this export */ +export const config: Configuration; + +/** + * Generate favicons + * @param source Source image(s) + * @param configuration + * @param callback + */ +declare function favicons( + source: string | Buffer | string[], + callback?: Callback +): void; +declare function favicons( + source: string | Buffer | string[], + configuration?: Partial, + callback?: Callback +): void; + +export default favicons; diff --git a/types/favicons/tsconfig.json b/types/favicons/tsconfig.json new file mode 100644 index 0000000000..03d0b43577 --- /dev/null +++ b/types/favicons/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "favicons-tests.ts"] +} diff --git a/types/favicons/tslint.json b/types/favicons/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/favicons/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}