@putout/operator-filesystem 3.0.1 → 3.1.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 +1 -1
- package/lib/filesystem.js +8 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ const [dirPath] = findFile(ast, 'hello');
|
|
|
53
53
|
const newDirectoryPath = createDirectory(dirPath, 'world');
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
### `findFile(
|
|
56
|
+
### `findFile(filePath: Path|FilePath, name: string | string[]): FilePath[]`
|
|
57
57
|
|
|
58
58
|
```js
|
|
59
59
|
const {operator} = require('putout');
|
package/lib/filesystem.js
CHANGED
|
@@ -11,6 +11,7 @@ const {
|
|
|
11
11
|
} = require('@putout/operate');
|
|
12
12
|
|
|
13
13
|
const maybeFS = require('./maybe-fs');
|
|
14
|
+
const isString = (a) => typeof a === 'string';
|
|
14
15
|
const {isArray} = Array;
|
|
15
16
|
const maybeArray = (a) => isArray(a) ? a : [a];
|
|
16
17
|
|
|
@@ -43,6 +44,8 @@ module.exports.getParentDirectory = (filePath) => {
|
|
|
43
44
|
module.exports.findFile = findFile;
|
|
44
45
|
|
|
45
46
|
function findFile(node, name) {
|
|
47
|
+
checkName(name);
|
|
48
|
+
|
|
46
49
|
const filePaths = [];
|
|
47
50
|
const names = maybeArray(name);
|
|
48
51
|
|
|
@@ -58,6 +61,11 @@ function findFile(node, name) {
|
|
|
58
61
|
return filePaths;
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
function checkName(name) {
|
|
65
|
+
if (!isString(name) && !isArray(name))
|
|
66
|
+
throw Error(`☝️ Looks like you forget to pass the 'name' of a file to 'findFile(filePath: Path|FilePath, name: string | string[]): FilePath'`);
|
|
67
|
+
}
|
|
68
|
+
|
|
61
69
|
function getFilenamePath(filePath) {
|
|
62
70
|
const filenamePath = getProperty(filePath, 'filename');
|
|
63
71
|
return filenamePath.get('value');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-filesystem",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.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",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@putout/babel": "^2.0.0",
|
|
28
|
-
"@putout/operate": "^
|
|
28
|
+
"@putout/operate": "^12.0.0",
|
|
29
29
|
"fullstore": "^3.0.0",
|
|
30
30
|
"try-catch": "^3.0.1"
|
|
31
31
|
},
|