import JSZip from 'jszip'; import { InternalArgumentMissingError } from '../errors'; import { Constructor } from '../types'; import { Binary } from '../utils'; export class JsZipHelper { public static toJsZipOutputType(binary: Binary): JSZip.OutputType; public static toJsZipOutputType(binaryType: Constructor): JSZip.OutputType; public static toJsZipOutputType(binaryOrType: Binary | Constructor): JSZip.OutputType { if (!binaryOrType) throw new InternalArgumentMissingError("binaryOrType"); let binaryType: Constructor; if (typeof binaryOrType === 'function') { binaryType = binaryOrType as Constructor; } else { binaryType = binaryOrType.constructor as Constructor; } if (Binary.isBlobConstructor(binaryType)) return 'blob'; if (Binary.isArrayBufferConstructor(binaryType)) return 'arraybuffer'; if (Binary.isBufferConstructor(binaryType)) return 'nodebuffer'; throw new Error(`Binary type '${(binaryType as any).name}' is not supported.`); } }