@putout/operator-filesystem 6.2.0 → 6.3.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 CHANGED
@@ -61,9 +61,10 @@ const {operator} = require('putout');
61
61
  const {
62
62
  createDirectory,
63
63
  findFile,
64
+ createNestedDirectory,
64
65
  } = operator;
65
66
 
66
- const newDirectoryPath = createDirectory(ast, '/hello/world');
67
+ const newDirectoryPath = createNestedDirectory(ast, '/hello/world');
67
68
  ```
68
69
 
69
70
  ### `readDirectory(directoryPath: DirectoryPath): (FilePath | DirectoryPath)[]`
@@ -139,6 +140,20 @@ dirPath === getParentDirectory(newDirectoryPath);
139
140
  true;
140
141
  ```
141
142
 
143
+ ### `getRootDirectory(path: FilePath | DirectoryPath): DrectoryPath`
144
+
145
+ ```js
146
+ const {operator} = require('putout');
147
+ const {
148
+ findFile,
149
+ getRootDirectory,
150
+ } = operator;
151
+
152
+ const [filePath] = findFile(ast, 'hello');
153
+
154
+ getRootDirectory(dirPath);
155
+ ```
156
+
142
157
  ### `getFilename(path: FilePath | DirectoryPath): string`
143
158
 
144
159
  ```js
package/lib/filesystem.js CHANGED
@@ -399,22 +399,21 @@ module.exports.createNestedDirectory = (path, name) => {
399
399
  return lastDirectoryPath;
400
400
  };
401
401
 
402
+ module.exports.getRootDirectory = getRootDirectory;
402
403
  function getRootDirectory(path) {
403
404
  let currentDirPath = getParentDirectory(path);
404
405
 
405
406
  if (!currentDirPath)
406
407
  return path;
407
408
 
408
- let prevPath = path;
409
+ let prevPath = currentDirPath;
409
410
 
410
411
  while (currentDirPath = getParentDirectory(currentDirPath)) {
411
412
  prevPath = currentDirPath;
412
413
  }
413
414
 
414
415
  return prevPath;
415
- }
416
-
417
- module.exports.init = maybeFS.init;
416
+ }module.exports.init = maybeFS.init;
418
417
  module.exports.deinit = maybeFS.deinit;
419
418
 
420
419
  module.exports.pause = maybeFS.pause;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/operator-filesystem",
3
- "version": "6.2.0",
3
+ "version": "6.3.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",