.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @mrmlnc / readdir-enhanced / lib / sync / fs.js
1 'use strict';
2
3 const fs = require('fs');
4 const call = require('../call');
5
6 /**
7  * A facade around {@link fs.readdirSync} that allows it to be called
8  * the same way as {@link fs.readdir}.
9  *
10  * @param {string} dir
11  * @param {function} callback
12  */
13 exports.readdir = function (dir, callback) {
14   // Make sure the callback is only called once
15   callback = call.once(callback);
16
17   try {
18     let items = fs.readdirSync(dir);
19     callback(null, items);
20   }
21   catch (err) {
22     callback(err);
23   }
24 };
25
26 /**
27  * A facade around {@link fs.statSync} that allows it to be called
28  * the same way as {@link fs.stat}.
29  *
30  * @param {string} path
31  * @param {function} callback
32  */
33 exports.stat = function (path, callback) {
34   // Make sure the callback is only called once
35   callback = call.once(callback);
36
37   try {
38     let stats = fs.statSync(path);
39     callback(null, stats);
40   }
41   catch (err) {
42     callback(err);
43   }
44 };
45
46 /**
47  * A facade around {@link fs.lstatSync} that allows it to be called
48  * the same way as {@link fs.lstat}.
49  *
50  * @param {string} path
51  * @param {function} callback
52  */
53 exports.lstat = function (path, callback) {
54   // Make sure the callback is only called once
55   callback = call.once(callback);
56
57   try {
58     let stats = fs.lstatSync(path);
59     callback(null, stats);
60   }
61   catch (err) {
62     callback(err);
63   }
64 };