locate-path
获取多个路径中磁盘上存在的第一个路径
安装
npm install locate-path
用法
在这里,我们按照数组顺序找到磁盘上存在的第一个文件。
import {locatePath} from 'locate-path';
const files = [
'unicorn.png',
'rainbow.png', // Only this one actually exists on disk
'pony.png'
];
console.log(await locatePath(files));
//=> 'rainbow.png'
API
locatePath(路径,选择?)
返回一个 Promise<string> 对于存在的第一个路径或 undefined 如果不存在。
路径
类型: Iterable<string>
检查路径。
选项
类型: object
并发性
类型: number
默认值: Infinity
最低: 1
并发等待的承诺的数量。
preserveOrder
类型: boolean
默认值: true
保存 paths 搜索时要有次序。
如果您不关心顺序,请禁用此选项以提高性能。
慢性消耗病
类型: URL | string
默认值: process.cwd()
当前工作目录。
类型
类型: string
默认值: 'file'
价值观: 'file' | 'directory' | 'both'
要匹配的路径类型。
'file'-只匹配文件'directory'-只匹配目录'both'—匹配文件和目录
allowSymlinks
类型: boolean
默认值: true
如果符号链接指向所选的路径类型,则允许它们匹配。
locatePathSync(路径,选择?)
返回存在的第一个路径 undefined 如果不存在。
路径
类型: Iterable<string>
检查路径。
选项
类型: object
慢性消耗病
同上。
类型
同上。
allowSymlinks
同上。
相关
- 路径 —检查是否存在路径