Permalink
Cannot retrieve contributors at this time
43 lines (36 sloc)
1.15 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/path-type/index.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const {promisify} = require('util'); | |
const fs = require('fs'); | |
async function isType(fsStatType, statsMethodName, filePath) { | |
if (typeof filePath !== 'string') { | |
throw new TypeError(`Expected a string, got ${typeof filePath}`); | |
} | |
try { | |
const stats = await promisify(fs[fsStatType])(filePath); | |
return stats[statsMethodName](); | |
} catch (error) { | |
if (error.code === 'ENOENT') { | |
return false; | |
} | |
throw error; | |
} | |
} | |
function isTypeSync(fsStatType, statsMethodName, filePath) { | |
if (typeof filePath !== 'string') { | |
throw new TypeError(`Expected a string, got ${typeof filePath}`); | |
} | |
try { | |
return fs[fsStatType](filePath)[statsMethodName](); | |
} catch (error) { | |
if (error.code === 'ENOENT') { | |
return false; | |
} | |
throw error; | |
} | |
} | |
exports.isFile = isType.bind(null, 'stat', 'isFile'); | |
exports.isDirectory = isType.bind(null, 'stat', 'isDirectory'); | |
exports.isSymlink = isType.bind(null, 'lstat', 'isSymbolicLink'); | |
exports.isFileSync = isTypeSync.bind(null, 'statSync', 'isFile'); | |
exports.isDirectorySync = isTypeSync.bind(null, 'statSync', 'isDirectory'); | |
exports.isSymlinkSync = isTypeSync.bind(null, 'lstatSync', 'isSymbolicLink'); |