added fileText method
All checks were successful
Build / Build NPM Project (push) Successful in 37s
Build / Tag Version (push) Successful in 6s
Build / Publish Documentation (push) Successful in 2m21s

This commit is contained in:
Zakary Timson 2024-11-09 15:35:05 -05:00
parent 2f59a9d02e
commit 0eab2630ad
2 changed files with 16 additions and 1 deletions

View File

@ -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",

View File

@ -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
* *