Acme.BookStore.HttpApi.Host/node_modules/detect-file/index.js
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/*!
* detect-file <https://github.com/doowb/detect-file>
*
* Copyright (c) 2016-2017, Brian Woodward.
* Released under the MIT License.
*/
'use strict';
var fs = require('fs');
var path = require('path');
/**
* Detect the given `filepath` if it exists.
*
* ```js
* var res = detect('package.json');
* console.log(res);
* //=> "package.json"
*
* var res = detect('fake-file.json');
* console.log(res)
* //=> null
* ```
*
* @param {String} `filepath` filepath to detect.
* @param {Object} `options` Additional options.
* @param {Boolean} `options.nocase` Set this to `true` to force case-insensitive filename checks. This is useful on case sensitive file systems.
* @return {String} Returns the detected filepath if it exists, otherwise returns `null`.
* @api public
*/
module.exports = function detect(filepath, options) {
if (!filepath || (typeof filepath !== 'string')) {
return null;
}
if (fs.existsSync(filepath)) {
return path.resolve(filepath);
}
options = options || {};
if (options.nocase === true) {
return nocase(filepath);
}
return null;
};
/**
* Check if the filepath exists by falling back to reading in the entire directory.
* Returns the real filepath (for case sensitive file systems) if found.
*
* @param {String} `filepath` filepath to check.
* @return {String} Returns found filepath if exists, otherwise null.
*/
function nocase(filepath) {
filepath = path.resolve(filepath);
var res = tryReaddir(filepath);
if (res === null) {
return null;
后面还有 49 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
