Add blob-util typings (#16844)

* Add blob-util typings

Library author is not interested in maintaining Typescript typings. See nolanlawson/blob-util#26

* In blob-util typings, move Typescript version tag

Move the Typescript version tag to the bottom of the headers.
This commit is contained in:
Max Battcher 2017-05-31 23:01:02 -04:00 committed by Mohamed Hegazy
parent d8d708d24f
commit 1c845dbe2e
4 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,17 @@
import * as blobUtil from 'blob-util';
const testBlob = new Blob(['abcd']);
blobUtil.base64StringToBlob('abcd'); // $ExpectType Promise<Blob>
blobUtil.createObjectURL(testBlob); // $ExpectType string
blobUtil.imgSrcToBlob('test.jpg'); // $ExpectType Promise<Blob>
blobUtil.createBlob(['abcd']); // $ExpectType Blob
blobUtil.arrayBufferToBlob(new ArrayBuffer(0)); // $ExpectType Promise<Blob>
blobUtil.binaryStringToBlob('0101'); // $ExpectType Promise<Blob>
blobUtil.blobToArrayBuffer(testBlob); // $ExpectType Promise<ArrayBuffer>
blobUtil.blobToBase64String(testBlob); // $ExpectType Promise<string>
blobUtil.blobToBinaryString(testBlob); // $ExpectType Promise<string>
blobUtil.canvasToBlob(new HTMLCanvasElement()); // $ExpectType Promise<Blob>
blobUtil.dataURLToBlob('data:abcd'); // $ExpectType Promise<Blob>
blobUtil.imgSrcToDataURL('test.jpg'); // $ExpectType Promise<string>
blobUtil.revokeObjectURL('blob:example'); // $ExpectType void

19
types/blob-util/index.d.ts vendored Normal file
View File

@ -0,0 +1,19 @@
// Type definitions for blob-util 1.2
// Project: https://github.com/nolanlawson/blob-util#readme
// Definitions by: Max Battcher <https://github.com/WorldMaker>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
export function createBlob(parts: any[], options?: { type: string }): Blob;
export function createObjectURL(blob: Blob): string;
export function revokeObjectURL(url: string): void;
export function blobToBinaryString(blob: Blob): Promise<string>;
export function binaryStringToBlob(binary: string, type?: string): Promise<Blob>;
export function blobToBase64String(blob: Blob): Promise<string>;
export function base64StringToBlob(base64: string, type?: string): Promise<Blob>;
export function dataURLToBlob(dataURL: string): Promise<Blob>;
export function imgSrcToDataURL(src: string, type?: string, crossOrigin?: string): Promise<string>;
export function canvasToBlob(canvas: HTMLCanvasElement, type?: string): Promise<Blob>;
export function imgSrcToBlob(src: string, type?: string, crossOrigin?: string): Promise<Blob>;
export function arrayBufferToBlob(arrayBuff: ArrayBuffer, type?: string): Promise<Blob>;
export function blobToArrayBuffer(blob: Blob): Promise<ArrayBuffer>;

View File

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

View File

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