@putout/operator-filesystem 2.10.0 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/lib/filesystem.js +9 -1
- package/lib/maybe-fs.js +19 -3
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -88,6 +88,17 @@ const {getFilename} = operator;
|
|
|
88
88
|
const name = getFilename(filePath);
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
+
### `getFileType(path: FilePath): string`
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
const {operator} = require('putout');
|
|
95
|
+
const {getFilename} = operator;
|
|
96
|
+
|
|
97
|
+
getFileType(filePath);
|
|
98
|
+
// returns
|
|
99
|
+
'file';
|
|
100
|
+
```
|
|
101
|
+
|
|
91
102
|
### `removeFile(filePath: Path)`
|
|
92
103
|
|
|
93
104
|
```js
|
package/lib/filesystem.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const {join} = require('node:path');
|
|
4
4
|
const tryCatch = require('try-catch');
|
|
5
|
-
const {types} = require('putout');
|
|
5
|
+
const {types} = require('@putout/babel');
|
|
6
6
|
|
|
7
7
|
const {
|
|
8
8
|
setLiteralValue,
|
|
@@ -68,6 +68,11 @@ function getFilename(filePath) {
|
|
|
68
68
|
return value;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
module.exports.getFileType = (filePath) => {
|
|
72
|
+
const typePath = getProperty(filePath, 'type');
|
|
73
|
+
return typePath.node.value.value;
|
|
74
|
+
};
|
|
75
|
+
|
|
71
76
|
function getFileContent(filePath) {
|
|
72
77
|
const content = getProperty(filePath, 'content');
|
|
73
78
|
|
|
@@ -262,3 +267,6 @@ function writeFileContent(filePath, content) {
|
|
|
262
267
|
|
|
263
268
|
module.exports.init = maybeFS.init;
|
|
264
269
|
module.exports.deinit = maybeFS.deinit;
|
|
270
|
+
|
|
271
|
+
module.exports.pause = maybeFS.pause;
|
|
272
|
+
module.exports.start = maybeFS.start;
|
package/lib/maybe-fs.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const fullstore = require('fullstore');
|
|
4
|
+
const driverStore = fullstore();
|
|
5
|
+
|
|
3
6
|
const {assign} = Object;
|
|
4
7
|
const noop = () => {};
|
|
5
8
|
const returns = (a) => () => a;
|
|
@@ -39,10 +42,23 @@ module.exports.writeFileContent = (name) => {
|
|
|
39
42
|
maybeFS.writeFileContent(name);
|
|
40
43
|
};
|
|
41
44
|
|
|
42
|
-
module.exports.init =
|
|
45
|
+
module.exports.init = init;
|
|
46
|
+
|
|
47
|
+
function init(fsDriver) {
|
|
43
48
|
assign(maybeFS, fsDriver);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports.pause = () => {
|
|
52
|
+
driverStore(maybeFS);
|
|
53
|
+
deinit();
|
|
44
54
|
};
|
|
45
55
|
|
|
46
|
-
module.exports.
|
|
47
|
-
|
|
56
|
+
module.exports.start = () => {
|
|
57
|
+
init(driverStore());
|
|
48
58
|
};
|
|
59
|
+
|
|
60
|
+
module.exports.deinit = deinit;
|
|
61
|
+
|
|
62
|
+
function deinit() {
|
|
63
|
+
assign(maybeFS, defaultFS);
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-filesystem",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout operator adds ability to filesystem referenced variables that was not defined",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"report": "madrun report"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"@putout/babel": "^1.5.5",
|
|
27
28
|
"@putout/operate": "^11.0.0",
|
|
29
|
+
"fullstore": "^3.0.0",
|
|
28
30
|
"try-catch": "^3.0.1"
|
|
29
31
|
},
|
|
30
32
|
"keywords": [
|