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