Add `fs.typeof` method
未关闭
good first issue
help wanted
- 主要语言
- TypeScript
- 星标
- 22
- 派生
- 1
- PR 合并指标
- 30 天内没有已合并 PR
描述
It returns the path type according to its on-disk representation.
Possible results include: `file`, `directory`, `symlink`, `socket`, `fifo`, `characterDevice`, `blockDevice`
```ts
// The path argument may be absolute or relative to the root directory.
fs.typeof('foo')
```
The best use case for this is a `switch` statement.
```ts
switch (fs.typeof(path)) {
case 'file':
// ...
break
case 'directory':
// ...
break
default:
throw new Error('unsupported file type')
}
```
This is better than using `fs.stat` or `fs.lstat`, because `change` events don't need to be watched for like they do with those methods. Just need to use the `existenceWatcher`, I think.
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。