diff --git a/package.json b/package.json index 0d4c7bd..5d85bfa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/utils", - "version": "0.22.3", + "version": "0.22.4", "description": "Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/files.ts b/src/files.ts index af5adff..3713be5 100644 --- a/src/files.ts +++ b/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} File contents + */ +export function fileText(file: any): Promise { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = () => resolve(reader.result); + reader.onerror = () => reject(reader.error); + reader.readAsText(file); + }); +} + /** * Create timestamp intended for filenames from a date *