Last change
on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
624 bytes
|
Line | |
---|
1 | /*
|
---|
2 | * MIT License http://opensource.org/licenses/MIT
|
---|
3 | * Author: Ben Holloway @bholloway
|
---|
4 | */
|
---|
5 | 'use strict';
|
---|
6 |
|
---|
7 | const fsUtils = (fs) => {
|
---|
8 | // fs from enhanced-resolver doesn't include fs.existsSync so we need to use fs.statsSync instead
|
---|
9 | const withStats = (fn) => (absolutePath) => {
|
---|
10 | try {
|
---|
11 | return fn(fs.statSync(absolutePath));
|
---|
12 | } catch (e) {
|
---|
13 | return false;
|
---|
14 | }
|
---|
15 | };
|
---|
16 |
|
---|
17 | return {
|
---|
18 | isFileSync: withStats((stats) => stats.isFile()),
|
---|
19 | isDirectorySync: withStats((stats) => stats.isDirectory()),
|
---|
20 | existsSync: withStats((stats) => stats.isFile() || stats.isDirectory())
|
---|
21 | };
|
---|
22 | };
|
---|
23 |
|
---|
24 | module.exports = fsUtils; |
---|
Note:
See
TracBrowser
for help on using the repository browser.