diff --git a/types/file-saver/file-saver-tests.ts b/types/file-saver/file-saver-tests.ts index cea6d2fff5..8ae4bbc3c4 100644 --- a/types/file-saver/file-saver-tests.ts +++ b/types/file-saver/file-saver-tests.ts @@ -1,9 +1,22 @@ -import "file-saver"; +import { FileSaverOptions } from "file-saver"; /** * @summary Test for "saveAs" function. */ function testSaveAs() { + const data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"}); + const filename = 'hello world.txt'; + const options: FileSaverOptions = { + autoBom: false + }; + + saveAs(data, filename, options); +} + +/** + * @summary Test for deprecated "saveAs" function. + */ +function testDeprecatedSaveAs() { const data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"}); const filename = 'hello world.txt'; const disableAutoBOM = true; @@ -17,9 +30,11 @@ function testSaveAs() { function testWindowSaveAs() { const data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"}); const filename = 'hello world.txt'; - const disableAutoBOM = true; + const options: FileSaverOptions = { + autoBom: false + }; - window.saveAs(data, filename, disableAutoBOM); + window.saveAs(data, filename, options); } /** @@ -28,9 +43,11 @@ function testWindowSaveAs() { function testUrlSaveAs() { const url = 'https://example.com/test.txt'; const filename = 'hello world.txt'; - const disableAutoBOM = true; + const options: FileSaverOptions = { + autoBom: false + }; - window.saveAs(url, filename, disableAutoBOM); + window.saveAs(url, filename, options); } /** diff --git a/types/file-saver/index.d.ts b/types/file-saver/index.d.ts index 524c5964bf..fb291a3f46 100644 --- a/types/file-saver/index.d.ts +++ b/types/file-saver/index.d.ts @@ -3,15 +3,34 @@ // Definitions by: Cyril Schumacher // Daniel Roth // Chris Barr +// HitkoDev // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/file-saver declare namespace FileSaver { + interface FileSaverOptions { + /** + * Automatically provide Unicode text encoding hints + * @default false + */ + autoBom: boolean; + } + + /** + * FileSaver.js implements the saveAs() FileSaver interface in browsers that do not natively support it. + * @param data - The actual file data blob or URL. + * @param filename - The optional name of the file to be downloaded. If omitted, the name used in the file data will be used. If none is provided "download" will be used. + * @param options - Optional FileSaver.js config + */ + function saveAs(data: Blob | string, filename?: string, options?: FileSaverOptions): void; + /** * FileSaver.js implements the saveAs() FileSaver interface in browsers that do not natively support it. * @param data - The actual file data blob or URL. * @param filename - The optional name of the file to be downloaded. If omitted, the name used in the file data will be used. If none is provided "download" will be used. * @param disableAutoBOM - Optional & defaults to `false`. Set to `true` if you want FileSaver.js to automatically provide Unicode text encoding hints + * @deprecated use `{ autoBom: false }` as the third argument */ + // tslint:disable-next-line:unified-signatures function saveAs(data: Blob | string, filename?: string, disableAutoBOM?: boolean): void; }