@putout/operator-json 1.0.1 → 1.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 +38 -0
- package/lib/json.js +9 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,14 +16,46 @@ npm i putout @putout/operator-json
|
|
|
16
16
|
### `__json`
|
|
17
17
|
|
|
18
18
|
```js
|
|
19
|
+
import {operator} from 'putout';
|
|
20
|
+
|
|
21
|
+
const {__json} = operator;
|
|
22
|
+
|
|
19
23
|
export const traverse = ({push}) => ({
|
|
20
24
|
[__json]: push,
|
|
21
25
|
});
|
|
22
26
|
```
|
|
23
27
|
|
|
28
|
+
### `__yaml`
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import {operator} from 'putout';
|
|
32
|
+
|
|
33
|
+
const {__yaml} = operator;
|
|
34
|
+
|
|
35
|
+
export const traverse = ({push}) => ({
|
|
36
|
+
[__yaml]: push,
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### `__ignore`
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
import {operator} from 'putout';
|
|
44
|
+
|
|
45
|
+
const {__ignore} = operator;
|
|
46
|
+
|
|
47
|
+
export const traverse = ({push}) => ({
|
|
48
|
+
[__ignore]: push,
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
24
52
|
### `__filesystem`
|
|
25
53
|
|
|
26
54
|
```js
|
|
55
|
+
import {operator} from 'putout';
|
|
56
|
+
|
|
57
|
+
const {__filesystem} = operator;
|
|
58
|
+
|
|
27
59
|
export const traverse = ({push}) => ({
|
|
28
60
|
[__filesystem]: (path) => {
|
|
29
61
|
push(path);
|
|
@@ -34,6 +66,9 @@ export const traverse = ({push}) => ({
|
|
|
34
66
|
### `toJS(source: string, name?: string)`;
|
|
35
67
|
|
|
36
68
|
```js
|
|
69
|
+
import {operator} from 'putout';
|
|
70
|
+
|
|
71
|
+
const {__filesystem, toJS} = operator;
|
|
37
72
|
toJS('{"hello": "world"}');
|
|
38
73
|
// returns
|
|
39
74
|
`__putout_processor_json('{"hello": "world"});`;
|
|
@@ -46,6 +81,9 @@ toJS('{"hello": "world"}', __filesystem);
|
|
|
46
81
|
### `fromJS(source: string, name?: string)`;
|
|
47
82
|
|
|
48
83
|
```js
|
|
84
|
+
import {operator} from 'putout';
|
|
85
|
+
|
|
86
|
+
const {fromJS} = operator;
|
|
49
87
|
fromJS(`__putout_processor_json('{"hello": "world"}'`);
|
|
50
88
|
// returns
|
|
51
89
|
`{"hello": "world"}`;
|
package/lib/json.js
CHANGED
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
const removeBlankLines = require('remove-blank-lines');
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const createPrefix = (name) => `${name}(`;
|
|
5
|
+
const cut = (a) => a.slice(0, a.indexOf('('));
|
|
6
|
+
const createPrefix = (name) => `${cut(name)}(`;
|
|
7
7
|
const createSuffix = () => ');\n';
|
|
8
|
+
const maybeNewline = (a) => a.at(-1) === '\n' ? a : `${a}\n`;
|
|
8
9
|
|
|
9
|
-
const __json = '__putout_processor_json';
|
|
10
|
-
const
|
|
10
|
+
const __json = '__putout_processor_json(__object)';
|
|
11
|
+
const __yaml = '__putout_processor_yaml(__object)';
|
|
12
|
+
const __filesystem = '__putout_processor_filesystem(__object)';
|
|
13
|
+
const __ignore = '__putout_processor_ignore(__array)';
|
|
11
14
|
|
|
12
15
|
module.exports.__json = __json;
|
|
16
|
+
module.exports.__yaml = __yaml;
|
|
13
17
|
module.exports.__filesystem = __filesystem;
|
|
18
|
+
module.exports.__ignore = __ignore;
|
|
14
19
|
|
|
15
20
|
module.exports.toJS = (source, name = __json) => {
|
|
16
21
|
const prefix = createPrefix(name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-json",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.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 json referenced variables that was not defined",
|