tslint and fix build issues

This commit is contained in:
Ibby 2017-03-01 21:28:05 -05:00
parent af4d5e8968
commit 7f368b61be
3 changed files with 36 additions and 40 deletions

View File

@ -481,9 +481,9 @@ export class File {
* *
* @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
* @param {string} dir Name of directory to check * @param {string} dir Name of directory to check
* @returns {Promise<boolean|FileError>} Returns a Promise that resolves to true if the directory exists or rejects with an error. * @returns {Promise<boolean> | Promise<FileError>} Returns a Promise that resolves to true if the directory exists or rejects with an error.
*/ */
static checkDir(path: string, dir: string): Promise<boolean|FileError> { static checkDir(path: string, dir: string): Promise<boolean> | Promise<FileError> {
if ((/^\//.test(dir))) { if ((/^\//.test(dir))) {
let err = new FileError(5); let err = new FileError(5);
err.message = 'directory cannot start with \/'; err.message = 'directory cannot start with \/';
@ -505,9 +505,9 @@ export class File {
* @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
* @param {string} dirName Name of directory to create * @param {string} dirName Name of directory to create
* @param {boolean} replace If true, replaces file with same name. If false returns error * @param {boolean} replace If true, replaces file with same name. If false returns error
* @returns {Promise<DirectoryEntry|FileError>} Returns a Promise that resolves with a DirectoryEntry or rejects with an error. * @returns {Promise<DirectoryEntry> | Promise<FileError>} Returns a Promise that resolves with a DirectoryEntry or rejects with an error.
*/ */
static createDir(path: string, dirName: string, replace: boolean): Promise<DirectoryEntry|FileError> { static createDir(path: string, dirName: string, replace: boolean): Promise<DirectoryEntry> | Promise<FileError> {
if ((/^\//.test(dirName))) { if ((/^\//.test(dirName))) {
let err = new FileError(5); let err = new FileError(5);
err.message = 'directory cannot start with \/'; err.message = 'directory cannot start with \/';
@ -533,9 +533,9 @@ export class File {
* *
* @param {string} path The path to the directory * @param {string} path The path to the directory
* @param {string} dirName The directory name * @param {string} dirName The directory name
* @returns {Promise<RemoveResult|FileError>} Returns a Promise that resolves to a RemoveResult or rejects with an error. * @returns {Promise<RemoveResult> | Promise<FileError>} Returns a Promise that resolves to a RemoveResult or rejects with an error.
*/ */
static removeDir(path: string, dirName: string): Promise<RemoveResult|FileError> { static removeDir(path: string, dirName: string): Promise<RemoveResult> | Promise<FileError> {
if ((/^\//.test(dirName))) { if ((/^\//.test(dirName))) {
let err = new FileError(5); let err = new FileError(5);
err.message = 'directory cannot start with \/'; err.message = 'directory cannot start with \/';
@ -558,9 +558,9 @@ export class File {
* @param {string} dirName The source directory name * @param {string} dirName The source directory name
* @param {string} newPath The destionation path to the directory * @param {string} newPath The destionation path to the directory
* @param {string} newDirName The destination directory name * @param {string} newDirName The destination directory name
* @returns {Promise<DirectoryEntry|Entry|FileError>} Returns a Promise that resolves to the new DirectoryEntry object or rejects with an error. * @returns {Promise<DirectoryEntry|Entry> | Promise<FileError>} Returns a Promise that resolves to the new DirectoryEntry object or rejects with an error.
*/ */
static moveDir(path: string, dirName: string, newPath: string, newDirName: string): Promise<DirectoryEntry|Entry|FileError> { static moveDir(path: string, dirName: string, newPath: string, newDirName: string): Promise<DirectoryEntry|Entry> | Promise<FileError> {
newDirName = newDirName || dirName; newDirName = newDirName || dirName;
if ((/^\//.test(newDirName))) { if ((/^\//.test(newDirName))) {
@ -588,9 +588,9 @@ export class File {
* @param {string} dirName Name of directory to copy * @param {string} dirName Name of directory to copy
* @param {string} newPath Base FileSystem of new location * @param {string} newPath Base FileSystem of new location
* @param {string} newDirName New name of directory to copy to (leave blank to remain the same) * @param {string} newDirName New name of directory to copy to (leave blank to remain the same)
* @returns {Promise<Entry|FileError>} Returns a Promise that resolves to the new Entry object or rejects with an error. * @returns {Promise<Entry> | Promise<FileError>} Returns a Promise that resolves to the new Entry object or rejects with an error.
*/ */
static copyDir(path: string, dirName: string, newPath: string, newDirName: string): Promise<Entry|FileError> { static copyDir(path: string, dirName: string, newPath: string, newDirName: string): Promise<Entry> | Promise<FileError> {
if ((/^\//.test(newDirName))) { if ((/^\//.test(newDirName))) {
let err = new FileError(5); let err = new FileError(5);
err.message = 'directory cannot start with \/'; err.message = 'directory cannot start with \/';
@ -661,9 +661,9 @@ export class File {
* *
* @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
* @param {string} file Name of file to check * @param {string} file Name of file to check
* @returns {Promise<boolean|FileError>} Returns a Promise that resolves with a boolean or rejects with an error. * @returns {Promise<boolean> | Promise<FileError>} Returns a Promise that resolves with a boolean or rejects with an error.
*/ */
static checkFile(path: string, file: string): Promise<boolean|FileError> { static checkFile(path: string, file: string): Promise<boolean> | Promise<FileError> {
if ((/^\//.test(file))) { if ((/^\//.test(file))) {
let err = new FileError(5); let err = new FileError(5);
err.message = 'file cannot start with \/'; err.message = 'file cannot start with \/';
@ -690,9 +690,9 @@ export class File {
* @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
* @param {string} fileName Name of file to create * @param {string} fileName Name of file to create
* @param {boolean} replace If true, replaces file with same name. If false returns error * @param {boolean} replace If true, replaces file with same name. If false returns error
* @returns {Promise<FileEntry|FileError>} Returns a Promise that resolves to a FileEntry or rejects with an error. * @returns {Promise<FileEntry> | Promise<FileError>} Returns a Promise that resolves to a FileEntry or rejects with an error.
*/ */
static createFile(path: string, fileName: string, replace: boolean): Promise<FileEntry|FileError> { static createFile(path: string, fileName: string, replace: boolean): Promise<FileEntry> | Promise<FileError> {
if ((/^\//.test(fileName))) { if ((/^\//.test(fileName))) {
let err = new FileError(5); let err = new FileError(5);
err.message = 'file-name cannot start with \/'; err.message = 'file-name cannot start with \/';
@ -718,9 +718,9 @@ export class File {
* *
* @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
* @param {string} fileName Name of file to remove * @param {string} fileName Name of file to remove
* @returns {Promise<RemoveResult|FileError>} Returns a Promise that resolves to a RemoveResult or rejects with an error. * @returns {Promise<RemoveResult> | Promise<FileError>} Returns a Promise that resolves to a RemoveResult or rejects with an error.
*/ */
static removeFile(path: string, fileName: string): Promise<RemoveResult|FileError> { static removeFile(path: string, fileName: string): Promise<RemoveResult> | Promise<FileError> {
if ((/^\//.test(fileName))) { if ((/^\//.test(fileName))) {
let err = new FileError(5); let err = new FileError(5);
err.message = 'file-name cannot start with \/'; err.message = 'file-name cannot start with \/';
@ -807,9 +807,9 @@ export class File {
* *
* @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
* @param {string} file Name of file, relative to path. * @param {string} file Name of file, relative to path.
* @returns {Promise<string|FileError>} Returns a Promise that resolves with the contents of the file as string or rejects with an error. * @returns {Promise<string> | Promise<FileError>} Returns a Promise that resolves with the contents of the file as string or rejects with an error.
*/ */
static readAsText(path: string, file: string): Promise<string|FileError> { static readAsText(path: string, file: string): Promise<string> | Promise<FileError> {
if ((/^\//.test(file))) { if ((/^\//.test(file))) {
let err = new FileError(5); let err = new FileError(5);
err.message = 'file-name cannot start with \/'; err.message = 'file-name cannot start with \/';
@ -848,9 +848,9 @@ export class File {
* @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
* @param {string} file Name of file, relative to path. * @param {string} file Name of file, relative to path.
* @returns {Promise<string|FileError>} Returns a Promise that resolves with the contents of the file as data URL or rejects with an error. * @returns {Promise<string> | Promise<FileError>} Returns a Promise that resolves with the contents of the file as data URL or rejects with an error.
*/ */
static readAsDataURL(path: string, file: string): Promise<string|FileError> { static readAsDataURL(path: string, file: string): Promise<string> | Promise<FileError> {
if ((/^\//.test(file))) { if ((/^\//.test(file))) {
let err = new FileError(5); let err = new FileError(5);
err.message = 'file-name cannot start with \/'; err.message = 'file-name cannot start with \/';
@ -890,9 +890,9 @@ export class File {
* @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
* @param {string} file Name of file, relative to path. * @param {string} file Name of file, relative to path.
* @returns {Promise<string|FileError>} Returns a Promise that resolves with the contents of the file as string rejects with an error. * @returns {Promise<string> | Promise<FileError>} Returns a Promise that resolves with the contents of the file as string rejects with an error.
*/ */
static readAsBinaryString(path: string, file: string): Promise<string|FileError> { static readAsBinaryString(path: string, file: string): Promise<string> | Promise<FileError> {
if ((/^\//.test(file))) { if ((/^\//.test(file))) {
let err = new FileError(5); let err = new FileError(5);
err.message = 'file-name cannot start with \/'; err.message = 'file-name cannot start with \/';
@ -931,9 +931,9 @@ export class File {
* @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above
* @param {string} file Name of file, relative to path. * @param {string} file Name of file, relative to path.
* @returns {Promise<ArrayBuffer|FileError>} Returns a Promise that resolves with the contents of the file as ArrayBuffer or rejects with an error. * @returns {Promise<ArrayBuffer> | Promise<FileError>} Returns a Promise that resolves with the contents of the file as ArrayBuffer or rejects with an error.
*/ */
static readAsArrayBuffer(path: string, file: string): Promise<ArrayBuffer|FileError> { static readAsArrayBuffer(path: string, file: string): Promise<ArrayBuffer> | Promise<FileError> {
if ((/^\//.test(file))) { if ((/^\//.test(file))) {
let err = new FileError(5); let err = new FileError(5);
err.message = 'file-name cannot start with \/'; err.message = 'file-name cannot start with \/';
@ -974,9 +974,9 @@ export class File {
* @param {string} fileName Name of file to move * @param {string} fileName Name of file to move
* @param {string} newPath Base FileSystem of new location * @param {string} newPath Base FileSystem of new location
* @param {string} newFileName New name of file to move to (leave blank to remain the same) * @param {string} newFileName New name of file to move to (leave blank to remain the same)
* @returns {Promise<Entry|FileError>} Returns a Promise that resolves to the new Entry or rejects with an error. * @returns {Promise<Entry> | Promise<FileError>} Returns a Promise that resolves to the new Entry or rejects with an error.
*/ */
static moveFile(path: string, fileName: string, newPath: string, newFileName: string): Promise<Entry|FileError> { static moveFile(path: string, fileName: string, newPath: string, newFileName: string): Promise<Entry> | Promise<FileError> {
newFileName = newFileName || fileName; newFileName = newFileName || fileName;
if ((/^\//.test(newFileName))) { if ((/^\//.test(newFileName))) {
@ -1004,9 +1004,9 @@ export class File {
* @param {string} fileName Name of file to copy * @param {string} fileName Name of file to copy
* @param {string} newPath Base FileSystem of new location * @param {string} newPath Base FileSystem of new location
* @param {string} newFileName New name of file to copy to (leave blank to remain the same) * @param {string} newFileName New name of file to copy to (leave blank to remain the same)
* @returns {Promise<Entry|FileError>} Returns a Promise that resolves to an Entry or rejects with an error. * @returns {Promise<Entry> | Promise<FileError>} Returns a Promise that resolves to an Entry or rejects with an error.
*/ */
static copyFile(path: string, fileName: string, newPath: string, newFileName: string): Promise<Entry|FileError> { static copyFile(path: string, fileName: string, newPath: string, newFileName: string): Promise<Entry> | Promise<FileError> {
newFileName = newFileName || fileName; newFileName = newFileName || fileName;
if ((/^\//.test(newFileName))) { if ((/^\//.test(newFileName))) {
@ -1027,17 +1027,13 @@ export class File {
}); });
} }
// these private methods help avoid cascading error handling
// in the public ones, primarily simply wrapping callback
// operations to return Promises that can then be chained.
/** /**
* @private * @private
*/ */
private static fillErrorMessage(err: FileError): void { private static fillErrorMessage(err: FileError): void {
if (typeof err === "DOMException") { try {
return; err.message = File.cordovaFileError[err.code];
} } catch (e) {}
err.message = File.cordovaFileError[err.code];
} }
/** /**