Add 'page-icon' package (#11918)

This commit is contained in:
Linda_pp
2016-10-12 22:22:55 +09:00
committed by Masahiro Wakame
parent 7ab26a7f1e
commit 815ad66282
2 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
/// <reference path="./page-icon.d.ts" />
import * as pageIcon from "page-icon";
const siteUrl = "https://www.facebook.com/";
pageIcon(siteUrl)
.then(function(icon) {
// do things with icon object
console.log(icon);
})
.catch(error => {
console.error(error);
});
const twUrl = "https://twitter.com";
pageIcon(twUrl, {ext: ".png"})
.then(icon => {
if (!icon) {
return;
}
console.log(icon.source, icon.name, icon.data, icon.size, icon.ext, icon.mime);
})
.catch(err => {
console.error(err);
});

25
page-icon/page-icon.d.ts vendored Normal file
View File

@@ -0,0 +1,25 @@
// Type definitions for page-icon 0.3.0
// Project: https://github.com/jiahaog/page-icon
// Definitions by: rhysd <https://rhysd.github.io>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare namespace PageIcon {
interface Icon {
source: string;
name: string;
data: Buffer;
size: number;
ext: string;
mime: string;
}
interface FetchOptions {
ext?: string;
}
}
declare module "page-icon" {
const mod: (url: string, opts?: PageIcon.FetchOptions) => Promise<PageIcon.Icon>;
export = mod;
}