mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
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;
|
|
|
|
saveAs(data, filename, disableAutoBOM);
|
|
}
|
|
|
|
/**
|
|
* @summary Test for "saveAs" function on the window object.
|
|
*/
|
|
function testWindowSaveAs() {
|
|
const data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
|
|
const filename = 'hello world.txt';
|
|
const options: FileSaverOptions = {
|
|
autoBom: false
|
|
};
|
|
|
|
window.saveAs(data, filename, options);
|
|
}
|
|
|
|
/**
|
|
* @summary Test for "saveAs" function with URL as first argument.
|
|
*/
|
|
function testUrlSaveAs() {
|
|
const url = 'https://example.com/test.txt';
|
|
const filename = 'hello world.txt';
|
|
const options: FileSaverOptions = {
|
|
autoBom: false
|
|
};
|
|
|
|
window.saveAs(url, filename, options);
|
|
}
|
|
|
|
/**
|
|
* @summary Test for "saveAs" function with the 3rd parameter omitted
|
|
*/
|
|
function testOptionalOneParamSaveAs() {
|
|
const data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
|
|
const filename = 'hello world.txt';
|
|
saveAs(data, filename);
|
|
}
|
|
|
|
/**
|
|
* @summary Test for "saveAs" function with the 2nd and 3rd parameters omitted
|
|
*/
|
|
function testOptionalTwoParamsSaveAs() {
|
|
const data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
|
|
saveAs(data);
|
|
}
|