added fileText method
This commit is contained in:
parent
2f59a9d02e
commit
0eab2630ad
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.22.3",
|
"version": "0.22.4",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
15
src/files.ts
15
src/files.ts
@ -52,6 +52,21 @@ export function fileBrowser(options: {accept?: string, multiple?: boolean} = {})
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract text from a file
|
||||||
|
*
|
||||||
|
* @param file File to extract text from
|
||||||
|
* @return {Promise<string | null>} File contents
|
||||||
|
*/
|
||||||
|
export function fileText(file: any): Promise<string | null> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = () => resolve(<string>reader.result);
|
||||||
|
reader.onerror = () => reject(reader.error);
|
||||||
|
reader.readAsText(file);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create timestamp intended for filenames from a date
|
* Create timestamp intended for filenames from a date
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user