Added typing for url-metadata 2.1 (#21035)

This commit is contained in:
Kevin
2017-10-26 14:23:16 -04:00
committed by Sheetal Nandi
parent d92b971c92
commit a5cc1d82d9
4 changed files with 96 additions and 0 deletions

57
types/url-metadata/index.d.ts vendored Normal file
View File

@@ -0,0 +1,57 @@
// Type definitions for url-metadata 2.1
// Project: https://github.com/LevelNewsOrg/url-metadata
// Definitions by: Kevin Gravier <https://github.com/mrkmg>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = urlMetadata;
declare function urlMetadata(url: string, options?: urlMetadata.Options): Promise<urlMetadata.Result>;
declare namespace urlMetadata {
interface Options {
userAgent?: string;
fromEmail?: string;
maxRedirects?: number;
timeout?: number;
descriptionLength?: number;
ensureSecureImageRequest?: boolean;
sourceMap?: { [key: string]: string };
encode?: () => void;
}
interface Result {
"url": string;
"canonical": string;
"title": string;
"image": string;
"author": string;
"description": string;
"keywords": string;
"source": string;
"og:url": string;
"og:locale": string;
"og:locale:alternate": string;
"og:title": string;
"og:type": string;
"og:description": string;
"og:determiner": string;
"og:site_name": string;
"og:image": string;
"og:image:secure_url": string;
"og:image:type": string;
"og:image:width": string;
"og:image:height": string;
"article:published_time"?: string;
"article:modified_time"?: string;
"article:expiration_time"?: string;
"article:author"?: string;
"article:section"?: string;
"article:tag"?: string;
"og:article:published_time"?: string;
"og:article:modified_time"?: string;
"og:article:expiration_time"?: string;
"og:article:author"?: string;
"og:article:section"?: string;
"og:article:tag"?: string;
}
}

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"url-metadata-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

View File

@@ -0,0 +1,15 @@
import * as urlMetadata from "url-metadata";
const opts: urlMetadata.Options = {
userAgent: "url-metadata-test",
fromEmail: "testing@url-metadata.com",
maxRedirects: 3,
timeout: 10000,
descriptionLength: 10000,
ensureSecureImageRequest: true
};
const url = "https://google.com";
urlMetadata(url, opts).then((result: urlMetadata.Result) => {
result; // $ExpectType Result
});