Deprecate disableAutoBOM as per file-saver 2.0 (#35617)

* Deprecate `disableAutoBOM` as per FileSaver 2.0

* Lint rules
This commit is contained in:
Hitko Development 2019-05-21 21:53:24 +02:00 committed by Ryan Cavanaugh
parent 6bad2d5410
commit 283d30a07a
2 changed files with 41 additions and 5 deletions

View File

@ -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);
}
/**

View File

@ -3,15 +3,34 @@
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher>
// Daniel Roth <https://github.com/DaIgeb>
// Chris Barr <https://github.com/chrismbarr>
// HitkoDev <https://github.com/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;
}