Add util function docstring
This commit is contained in:
parent
b2f84b51c8
commit
5b7bb5d878
1 changed files with 13 additions and 0 deletions
|
@ -5,6 +5,12 @@ import { APL, AuthData } from "./apl";
|
||||||
|
|
||||||
const debug = debugPkg.debug("FileAPL");
|
const debug = debugPkg.debug("FileAPL");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load auth data from a file and return it as AuthData format.
|
||||||
|
* In case of incomplete or invalid data, return `undefined`.
|
||||||
|
*
|
||||||
|
* @param {string} fileName
|
||||||
|
*/
|
||||||
export const loadDataFromFile = async (fileName: string): Promise<AuthData | undefined> => {
|
export const loadDataFromFile = async (fileName: string): Promise<AuthData | undefined> => {
|
||||||
debug(`Load auth data from the ${fileName} file`);
|
debug(`Load auth data from the ${fileName} file`);
|
||||||
let parsedData: Record<string, string> = {};
|
let parsedData: Record<string, string> = {};
|
||||||
|
@ -22,6 +28,13 @@ export const loadDataFromFile = async (fileName: string): Promise<AuthData | und
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save auth data to file.
|
||||||
|
* When `authData` argument is empty, will overwrite file with empty values.
|
||||||
|
*
|
||||||
|
* @param {string} fileName
|
||||||
|
* @param {AuthData} [authData]
|
||||||
|
*/
|
||||||
export const saveDataToFile = async (fileName: string, authData?: AuthData) => {
|
export const saveDataToFile = async (fileName: string, authData?: AuthData) => {
|
||||||
debug(`Save auth data to the ${fileName} file`);
|
debug(`Save auth data to the ${fileName} file`);
|
||||||
const newData = authData ? JSON.stringify(authData) : "{}";
|
const newData = authData ? JSON.stringify(authData) : "{}";
|
||||||
|
|
Loading…
Reference in a new issue