diff --git a/types/wordpress__blob/index.d.ts b/types/wordpress__blob/index.d.ts new file mode 100644 index 0000000000..98a0e0d0f0 --- /dev/null +++ b/types/wordpress__blob/index.d.ts @@ -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 +// 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; diff --git a/types/wordpress__blob/tsconfig.json b/types/wordpress__blob/tsconfig.json new file mode 100644 index 0000000000..0d07ab9675 --- /dev/null +++ b/types/wordpress__blob/tsconfig.json @@ -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"] +} diff --git a/types/wordpress__blob/tslint.json b/types/wordpress__blob/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/wordpress__blob/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/wordpress__blob/wordpress__blob-tests.ts b/types/wordpress__blob/wordpress__blob-tests.ts new file mode 100644 index 0000000000..b7b51f19e5 --- /dev/null +++ b/types/wordpress__blob/wordpress__blob-tests.ts @@ -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');