[@wordpress/blob] add new definitions (#36223)

This commit is contained in:
Derek Sifford
2019-06-17 16:49:10 -04:00
committed by Daniel Rosenwasser
parent 3356f6955e
commit 95f3d2cc44
4 changed files with 74 additions and 0 deletions

41
types/wordpress__blob/index.d.ts vendored Normal file
View File

@@ -0,0 +1,41 @@
// Type definitions for @wordpress/blob 2.4
// Project: https://github.com/WordPress/gutenberg/tree/master/packages/blob/README.md
// Definitions by: Derek Sifford <https://github.com/dsifford>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.5
/**
* Create a blob URL from a file.
*
* @param file - The file to create a blob URL for.
*
* @returns The blob URL.
*/
export function createBlobURL(file: File): string;
/**
* Retrieve a file based on a blob URL. The file must have been created by
* `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return
* `undefined`.
*
* @param url - The blob URL.
*
* @returns The file for the blob URL.
*/
export function getBlobByURL(url: string): File | undefined;
/**
* Check whether a url is a blob url.
*
* @param url - The URL.
*
* @returns Is the url a blob url?
*/
export function isBlobURL(url: string): boolean;
/**
* Remove the resource and file cache from memory.
*
* @param url - The blob URL.
*/
export function revokeBlobURL(url: string): void;

View File

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

View File

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

View File

@@ -0,0 +1,13 @@
import * as B from '@wordpress/blob';
B.createBlobURL(
new File(['foo'], 'foo.txt', {
type: 'text/plain',
})
);
B.getBlobByURL('blob:thisbitdoesnotmatter');
B.isBlobURL('blob:thisbitdoesnotmatter'); // true
B.revokeBlobURL('blob:thisbitdoesnotmatter');