@beenotung/tslib
Version:
utils library in Typescript
47 lines (46 loc) • 2.13 kB
TypeScript
/**
* For DOM
* */
/**
* @ref https://www.iana.org/assignments/media-types/media-types.xhtml
* */
export type BlobType = 'image/png' | 'image/*' | 'video/*' | 'audio/*' | 'text/plain' | 'text/html' | 'text/css' | 'text/javascript' | 'text/csv' | 'application/json' | 'application/xml' | string;
export declare function fileToBase64String(file: File): Promise<string>;
export declare function fileToText(file: File): Promise<string>;
export declare function filesForEach(files: FileList | File[], f: (file: File, i: number, files: FileList | File[]) => void): void;
export declare function filesMap<A>(files: FileList | File[], f: (file: File, i: number, files: FileList | File[]) => A): A[];
export declare function filesToBase64Strings(files: FileList | File[]): Promise<string[]>;
export declare function fileToBinaryString(file: File): Promise<string>;
export declare function fileToArray(file: File): Promise<number[]>;
export declare function fileToArrayBuffer(file: File): Promise<ArrayBuffer>;
export declare function downloadFile(url: string, filename?: string): Promise<true>;
/**
* true: must from camera
*
* false: must from album
*
* undefined: both camera and album are allowed
* */
export type CaptureOption = true | false | undefined;
export interface SelectFileOptions {
multiple?: boolean;
accept?: BlobType;
pattern?: string;
capture?: CaptureOption;
}
export declare function selectFile(options?: SelectFileOptions): Promise<File[]>;
/**
* must from album:
* `<input type="file" accept="image/*">`
*
* must from camera:
* `<input type="file" accept="image/*" capture="">`
*
* both album and camera:
* `<input type="file" accept="image/*;capture=camera">`
* */
export declare function selectImage(options?: SelectFileOptions): Promise<File[]>;
export declare function selectVideo(options?: SelectFileOptions): Promise<File[]>;
export declare function selectAudio(options?: SelectFileOptions): Promise<File[]>;
export declare function saveBlobToFile(blob: Blob, filename?: string): void;
export declare function saveStringToFile(s: string, type?: BlobType, filename?: string): void;