@putout/operator-json 2.2.0 → 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 +12 -0
- package/lib/json.js +14 -24
- package/package.json +11 -13
package/README.md
CHANGED
|
@@ -37,6 +37,18 @@ export const traverse = ({push}) => ({
|
|
|
37
37
|
});
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
### `__yaml`
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
import {operator} from 'putout';
|
|
44
|
+
|
|
45
|
+
const {__toml} = operator;
|
|
46
|
+
|
|
47
|
+
export const traverse = ({push}) => ({
|
|
48
|
+
[__toml]: push,
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
40
52
|
### `__ignore`
|
|
41
53
|
|
|
42
54
|
```js
|
package/lib/json.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const removeBlankLines = require('remove-blank-lines');
|
|
1
|
+
import removeBlankLines from 'remove-blank-lines';
|
|
4
2
|
|
|
5
3
|
const cut = (a) => a.slice(0, a.indexOf('('));
|
|
6
4
|
const createPrefix = (name) => {
|
|
@@ -13,15 +11,17 @@ const createPrefix = (name) => {
|
|
|
13
11
|
const createSuffix = () => ');\n';
|
|
14
12
|
const maybeNewline = (a) => a.at(-1) === '\n' ? a : `${a}\n`;
|
|
15
13
|
|
|
16
|
-
const __json_name = '__putout_processor_json';
|
|
17
|
-
const __yaml_name = '__putout_processor_yaml';
|
|
18
|
-
const
|
|
19
|
-
const
|
|
14
|
+
export const __json_name = '__putout_processor_json';
|
|
15
|
+
export const __yaml_name = '__putout_processor_yaml';
|
|
16
|
+
export const __toml_name = '__putout_processor_toml';
|
|
17
|
+
export const __filesystem_name = '__putout_processor_filesystem';
|
|
18
|
+
export const __ignore_name = '__putout_processor_ignore';
|
|
20
19
|
|
|
21
|
-
const __json = `${__json_name}(__object)`;
|
|
22
|
-
const __yaml = `${__yaml_name}(__object)`;
|
|
23
|
-
const
|
|
24
|
-
const
|
|
20
|
+
export const __json = `${__json_name}(__object)`;
|
|
21
|
+
export const __yaml = `${__yaml_name}(__object)`;
|
|
22
|
+
export const __toml = `${__toml_name}(__object)`;
|
|
23
|
+
export const __filesystem = `${__filesystem_name}(__object)`;
|
|
24
|
+
export const __ignore = `${__ignore_name}(__array)`;
|
|
25
25
|
|
|
26
26
|
const TYPES = [
|
|
27
27
|
__json_name,
|
|
@@ -30,24 +30,14 @@ const TYPES = [
|
|
|
30
30
|
__ignore_name,
|
|
31
31
|
];
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
module.exports.__yaml = __yaml;
|
|
35
|
-
module.exports.__filesystem = __filesystem;
|
|
36
|
-
module.exports.__ignore = __ignore;
|
|
37
|
-
|
|
38
|
-
module.exports.__json_name = __json_name;
|
|
39
|
-
module.exports.__yaml_name = __yaml_name;
|
|
40
|
-
module.exports.__filesystem_name = __filesystem_name;
|
|
41
|
-
module.exports.__ignore_name = __ignore_name;
|
|
42
|
-
|
|
43
|
-
module.exports.toJS = (source, name = __json) => {
|
|
33
|
+
export const toJS = (source, name = __json) => {
|
|
44
34
|
const prefix = createPrefix(name);
|
|
45
35
|
const suffix = createSuffix();
|
|
46
36
|
|
|
47
37
|
return `${prefix}${source}${suffix}`;
|
|
48
38
|
};
|
|
49
39
|
|
|
50
|
-
|
|
40
|
+
export const fromJS = (source, name = __json) => {
|
|
51
41
|
source = maybeNewline(source);
|
|
52
42
|
const shortName = cut(name);
|
|
53
43
|
|
|
@@ -61,7 +51,7 @@ module.exports.fromJS = (source, name = __json) => {
|
|
|
61
51
|
return maybeNewline(removeBlankLines(sliced));
|
|
62
52
|
};
|
|
63
53
|
|
|
64
|
-
|
|
54
|
+
export const isJSON = (source) => {
|
|
65
55
|
for (const type of TYPES) {
|
|
66
56
|
if (!source.indexOf(type))
|
|
67
57
|
return true;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-json",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
|
-
"description": "🐊Putout operator adds ability to
|
|
6
|
+
"description": "🐊Putout operator adds ability to work with json",
|
|
7
7
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/operator-json#readme",
|
|
8
8
|
"main": "lib/json.js",
|
|
9
9
|
"release": false,
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"changelog": false,
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git://github.com/coderaiser/putout.git"
|
|
14
|
+
"url": "git+https://github.com/coderaiser/putout.git"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"test": "madrun test",
|
|
@@ -30,21 +30,19 @@
|
|
|
30
30
|
"json"
|
|
31
31
|
],
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@putout/test": "^
|
|
34
|
-
"c8": "^
|
|
35
|
-
"eslint": "^
|
|
33
|
+
"@putout/test": "^15.0.0",
|
|
34
|
+
"c8": "^10.0.0",
|
|
35
|
+
"eslint": "^10.0.0-alpha.0",
|
|
36
36
|
"eslint-plugin-n": "^17.0.0",
|
|
37
|
-
"eslint-plugin-putout": "^
|
|
38
|
-
"
|
|
39
|
-
"madrun": "^10.0.0",
|
|
37
|
+
"eslint-plugin-putout": "^29.0.0",
|
|
38
|
+
"madrun": "^12.0.0",
|
|
40
39
|
"montag": "^1.2.1",
|
|
41
40
|
"nodemon": "^3.0.1",
|
|
42
|
-
"supertape": "^
|
|
43
|
-
"try-catch": "^3.0.0"
|
|
41
|
+
"supertape": "^12.0.0"
|
|
44
42
|
},
|
|
45
43
|
"license": "MIT",
|
|
46
44
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
45
|
+
"node": ">=22"
|
|
48
46
|
},
|
|
49
47
|
"publishConfig": {
|
|
50
48
|
"access": "public"
|