All files / src/lib local.ts

100% Statements 30/30
100% Branches 0/0
100% Functions 13/13
100% Lines 30/30

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88          13x     2x     2x 2x       2x 4x     4x   2x       2x 2x 2x       2x 4x 4x   2x       2x 2x       2x 4x   2x       6x       6x             4x       1x     1x       1x 1x       1x 1x       3x      
import { BlobFileSource, LocalFileSource } from './types/args';
import { LocalFileBuilderType, LocalFileListBuilderType } from './types/builder';
import { buildFile, buildFileList, localFileSourceConverter } from './types/helper';
 
export class LocalFileListBuilder implements LocalFileListBuilderType {
  private files: File[] = [];
 
  addBlob(blob: BlobFileSource): this {
    const object = new File([blob.blob], blob.name, {
      type: blob.mimeType,
    });
    this.files.push(object);
    return this;
  }
 
  addBlobs(blobs: BlobFileSource[]): this {
    for (const blob of blobs) {
      const object = new File([blob.blob], blob.name, {
        type: blob.mimeType,
      });
      this.files.push(object);
    }
    return this;
  }
 
  addFile(file: LocalFileSource): this {
    const object = localFileSourceConverter(file);
    this.files.push(object);
    return this;
  }
 
  addFiles(files: LocalFileSource[]): this {
    for (const file of files) {
      const object = localFileSourceConverter(file);
      this.files.push(object);
    }
    return this;
  }
 
  addFileObject(file: File): this {
    this.files.push(file);
    return this;
  }
 
  addFileObjects(files: Iterable<File>): this {
    for (const file of files) {
      this.files.push(file);
    }
    return this;
  }
 
  build(): FileList {
    return buildFileList(this.files);
  }
 
  buildFileArray(): File[] {
    return this.files;
  }
}
 
export class LocalFileBuilder implements LocalFileBuilderType {
  private file: File | undefined;
  constructor() {
    this.file = undefined;
  }
 
  addBlob(blob: BlobFileSource): this {
    this.file = new File([blob.blob], blob.name, {
      type: blob.mimeType,
    });
    return this;
  }
 
  addFile(file: LocalFileSource): this {
    this.file = localFileSourceConverter(file);
    return this;
  }
 
  addFileObject(file: File): this {
    this.file = file;
    return this;
  }
 
  build(): File {
    return buildFile(this.file);
  }
}