Skip to content

@longmo-utils/node / readFileOrDefault

Function: readFileOrDefault()

ts
function readFileOrDefault<T>(filePath, defaultValue): Promise<T>;

如果文件存在则读取,否则返回默认值

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
filePathstring文件路径
defaultValueT默认值

Returns

Promise<T>

文件内容或默认值

Example

ts
const config = await readFileOrDefault('./config.json', { theme: 'light' })

Released under the MIT License.