@putout/operator-filesystem 10.2.0 → 10.4.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 -14
- package/lib/filesystem.js +9 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -135,7 +135,7 @@ const {findFile} = operator;
|
|
|
135
135
|
const coupleFiles = findFile(ast, ['/home/coderaiser', '/home/coderaiser/putout']);
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
### `getFile(directoryPath: DirectoryPath, name: string, options?: Options): FilePath`
|
|
138
|
+
### `getFile(directoryPath: DirectoryPath, name: string, options?: Options): FilePath | null`
|
|
139
139
|
|
|
140
140
|
```ts
|
|
141
141
|
type Options = {
|
|
@@ -205,19 +205,6 @@ getFileType(filePath);
|
|
|
205
205
|
'file';
|
|
206
206
|
```
|
|
207
207
|
|
|
208
|
-
### `getFileContent(path: FilePath): [is: boolean, content: string]`
|
|
209
|
-
|
|
210
|
-
Get `content` property if it exists, use [`readFileContent`](#read-file-content) to read file from **Filesystem**.
|
|
211
|
-
|
|
212
|
-
```js
|
|
213
|
-
const {operator} = require('putout');
|
|
214
|
-
const {getFileContent} = operator;
|
|
215
|
-
|
|
216
|
-
getFileContent(filePath);
|
|
217
|
-
// returns
|
|
218
|
-
[true, 'hello world'];
|
|
219
|
-
```
|
|
220
|
-
|
|
221
208
|
### `removeFile(filePath: Path)`
|
|
222
209
|
|
|
223
210
|
```js
|
package/lib/filesystem.js
CHANGED
|
@@ -27,6 +27,9 @@ const isString = (a) => typeof a === 'string';
|
|
|
27
27
|
const {isArray} = Array;
|
|
28
28
|
const maybeArray = (a) => isArray(a) ? a : [a];
|
|
29
29
|
|
|
30
|
+
const escape = (a) => encodeURIComponent(a).replaceAll('%', '+');
|
|
31
|
+
const unescape = (a) => decodeURIComponent(a.replaceAll('+', '%'));
|
|
32
|
+
|
|
30
33
|
const toBase64 = (content) => {
|
|
31
34
|
const [e, result] = tryCatch(btoa, content);
|
|
32
35
|
|
|
@@ -42,8 +45,12 @@ const fromBase64 = (content) => {
|
|
|
42
45
|
|
|
43
46
|
const [e, decoded] = tryCatch(atob, content);
|
|
44
47
|
|
|
45
|
-
if (!e)
|
|
46
|
-
|
|
48
|
+
if (!e) {
|
|
49
|
+
if (!decoded.includes(' ') && decoded.includes('+'))
|
|
50
|
+
return unescape(decoded);
|
|
51
|
+
|
|
52
|
+
return decoded;
|
|
53
|
+
}
|
|
47
54
|
|
|
48
55
|
return content;
|
|
49
56
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-filesystem",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.4.0",
|
|
4
4
|
"type": "module",
|
|
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",
|