Re-write typedefs for file-saver

This commit is contained in:
Chris Barr
2017-11-02 10:57:07 -04:00
parent b67c928904
commit 8c29a73096
4 changed files with 47 additions and 137 deletions

View File

@@ -1,30 +1,40 @@
import { saveAs as importedSaveAs } from "file-saver";
function testImportedSaveAs() {
var data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
var filename: string = 'hello world.txt';
var disableAutoBOM = true;
importedSaveAs(data, filename, disableAutoBOM);
}
import "file-saver";
/**
* @summary Test for "saveAs" function.
*/
function testSaveAs() {
var data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
var filename: string = 'hello world.txt';
var disableAutoBOM = true;
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.
* @summary Test for "saveAs" function on the window object.
*/
function testSaveAsFile() {
const data = new File(["Hello, world!"], "hello world.txt" ,{type: "text/plain;charset=utf-8"});
function testWindowSaveAs() {
const data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
const filename = 'hello world.txt';
const disableAutoBOM = true;
window.saveAs(data, filename, disableAutoBOM);
}
/**
* @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);
}

View File

@@ -1,46 +1,22 @@
// Type definitions for FileSaver.js
// Type definitions for FileSaver.js 1.3
// Project: https://github.com/eligrey/FileSaver.js/
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher>, Daniel Roth <https://github.com/DaIgeb>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher>
// Daniel Roth <https://github.com/DaIgeb>
// Chris Barr <https://github.com/chrismbarr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/file-saver
/**
* @summary Interface for "saveAs" function.
* @author Cyril Schumacher
* @version 1.0
*/
interface FileSaver {
(
/**
* @summary Data.
* @type {Blob}
*/
data: Blob,
/**
* @summary File name.
* @type {DOMString}
*/
filename: string,
/**
* @summary Disable Unicode text encoding hints or not.
* @type {boolean}
*/
disableAutoBOM?: boolean
): void
(
/**
* @summary File.
* @type {File}
*/
data: File
): void
declare namespace FileSaver {
/**
* FileSaver.js implements the saveAs() FileSaver interface in browsers that do not natively support it.
* @param {Blob} data - The actual file data blob.
* @param {string} 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 {boolean} disableAutoBOM - Optional & defaults to `false`. Set to `true` if you don't want FileSaver.js to automatically provide Unicode text encoding hints
*/
type saveAs = (data: Blob, filename?: string, disableAutoBOM?: boolean) => void;
}
declare var saveAs: FileSaver;
declare module "file-saver" {
var fileSaver: { saveAs: typeof saveAs };
export = fileSaver
interface Window {
saveAs: FileSaver.saveAs;
}
declare const saveAs: FileSaver.saveAs;

View File

@@ -7,7 +7,7 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
@@ -21,4 +21,4 @@
"index.d.ts",
"file-saver-tests.ts"
]
}
}

View File

@@ -1,79 +1,3 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
"extends": "dtslint/dt.json"
}