-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (31 loc) · 881 Bytes
/
Copy pathindex.js
File metadata and controls
39 lines (31 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*!
* lstat | MIT (c) Shinnosuke Watanabe
* https://github.com/shinnn/lstat
*/
'use strict';
const fsLstat = require('fs').lstat;
const {inspect} = require('util');
module.exports = function lstat(...args) {
const argLen = args.length;
return new Promise((resolve, reject) => {
if (argLen !== 1) {
throw new TypeError(`Expected 1 argument (string), but got ${
argLen === 0 ? 'no' : argLen
} arguments instead.`);
}
const [path] = args;
if (typeof path !== 'string') {
throw new TypeError(`Expected a file path (string), but got a non-string value ${inspect(path)}.`);
}
if (path.length === 0) {
throw new Error('Expected a file path, but got \'\' (empty string).');
}
fsLstat(path, (err, result) => {
if (err) {
reject(err);
return;
}
resolve(result);
});
});
};