@appsemble/node-utils
Version:
NodeJS utilities used by Appsemble internally.
20 lines • 537 B
JavaScript
import { readFile } from 'node:fs/promises';
import { isErrno } from './index.js';
/**
* If the string represents an existing path, read the file. Otherwise, return the string itself.
*
* @param string The string to handle.
* @returns The handled string.
*/
export async function readFileOrString(string) {
try {
return await readFile(string);
}
catch (error) {
if (isErrno(error, 'ENOENT')) {
return string;
}
throw error;
}
}
//# sourceMappingURL=readFileOrString.js.map