UNPKG

2.7 kBTypeScriptView Raw
1import { ElementRef } from '@angular/core';
2import { Observable } from 'rxjs';
3import { FormGroup } from '@angular/forms';
4export declare type JhiFileLoadErrorType = 'not.image' | 'could.not.extract';
5export interface JhiFileLoadError {
6 message: string;
7 key: JhiFileLoadErrorType;
8 params?: any;
9}
10/**
11 * An utility service for data.
12 */
13export declare class JhiDataUtils {
14 constructor();
15 /**
16 * Method to abbreviate the text given
17 */
18 abbreviate(text: string, append?: string): string;
19 /**
20 * Method to find the byte size of the string provides
21 */
22 byteSize(base64String: string): string;
23 /**
24 * Method to open file
25 */
26 openFile(contentType: string, data: string): void;
27 /**
28 * Method to convert the file to base64
29 */
30 toBase64(file: File, cb: Function): void;
31 /**
32 * Method to clear the input
33 */
34 clearInputImage(entity: any, elementRef: ElementRef, field: string, fieldContentType: string, idInput: string): void;
35 /**
36 * Sets the base 64 data & file type of the 1st file on the event (event.target.files[0]) in the passed entity object
37 * and returns a promise.
38 *
39 * @param event the object containing the file (at event.target.files[0])
40 * @param entity the object to set the file's 'base 64 data' and 'file type' on
41 * @param field the field name to set the file's 'base 64 data' on
42 * @param isImage boolean representing if the file represented by the event is an image
43 * @returns a promise that resolves to the modified entity if operation is successful, otherwise rejects with an error message
44 */
45 setFileData(event: any, entity: any, field: string, isImage: boolean): Promise<any>;
46 /**
47 * Sets the base 64 data & file type of the 1st file on the event (event.target.files[0]) in the passed entity object
48 * and returns an observable.
49 *
50 * @param event the object containing the file (at event.target.files[0])
51 * @param editForm the form group where the input field is located
52 * @param field the field name to set the file's 'base 64 data' on
53 * @param isImage boolean representing if the file represented by the event is an image
54 * @returns an observable that loads file to form field and completes if sussessful
55 * or returns error as JhiFileLoadError on failure
56 */
57 loadFileToForm(event: Event, editForm: FormGroup, field: string, isImage: boolean): Observable<void>;
58 /**
59 * Method to download file
60 */
61 downloadFile(contentType: string, data: string, fileName: string): void;
62 private endsWith;
63 private paddingSize;
64 private size;
65 private formatAsBytes;
66}