-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfs.js
More file actions
61 lines (54 loc) · 1.2 KB
/
Copy pathfs.js
File metadata and controls
61 lines (54 loc) · 1.2 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* fs.js
* Version 0.1.0
* December 30th, 2016
*
* Copyright (c) 2016 Baptiste Augrain
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
**/
var constants = require('constants');
var fs = require('fs');
var path = require('path');
module.exports = {
exists: function(file) { // {{{
try {
fs.accessSync(file);
return true;
}
catch(error) {
try {
fs.lstatSync(file);
return true;
}
catch(error) {
return false;
}
}
}, // }}}
isFile: function(file) { // {{{
file = path.resolve(this.resolve(file));
if(!this.exists(file)) {
return false;
}
try {
var stats = fs.statSync(file);
var type = stats.mode & constants.S_IFMT;
return type == constants.S_IFREG;
}
catch(error) {
return false;
}
}, // }}}
readFile: function(file) { // {{{
return fs.readFileSync(file, {
encoding: 'utf8'
});
}, // }}}
resolve: function(file) { // {{{
if(!((process.platform === 'win32' && /^[a-zA-Z]:/.test(file)) || (process.platform !== 'win32' && file[0] === '/'))) {
Array.prototype.unshift.call(arguments, process.cwd());
}
return path.normalize(path.join.apply(null, arguments));
} // }}}
};