@putout/operator-json 1.1.0 → 1.2.1
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 +16 -0
- package/package.json +1 -4
package/README.md
CHANGED
|
@@ -63,6 +63,18 @@ export const traverse = ({push}) => ({
|
|
|
63
63
|
});
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
### `isJSON(source: string)`
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
isJSON(`__putout_processor_json({"hello": "world"});`);
|
|
70
|
+
// returns
|
|
71
|
+
true;
|
|
72
|
+
|
|
73
|
+
isJSON(`hello({"hello": "world"});`);
|
|
74
|
+
// returns
|
|
75
|
+
false;
|
|
76
|
+
```
|
|
77
|
+
|
|
66
78
|
### `toJS(source: string, name?: string)`;
|
|
67
79
|
|
|
68
80
|
```js
|
package/lib/json.js
CHANGED
|
@@ -12,6 +12,13 @@ const __yaml = '__putout_processor_yaml(__object)';
|
|
|
12
12
|
const __filesystem = '__putout_processor_filesystem(__object)';
|
|
13
13
|
const __ignore = '__putout_processor_ignore(__array)';
|
|
14
14
|
|
|
15
|
+
const TYPES = [
|
|
16
|
+
__json,
|
|
17
|
+
__yaml,
|
|
18
|
+
__filesystem,
|
|
19
|
+
__ignore,
|
|
20
|
+
].map(cut);
|
|
21
|
+
|
|
15
22
|
module.exports.__json = __json;
|
|
16
23
|
module.exports.__yaml = __yaml;
|
|
17
24
|
module.exports.__filesystem = __filesystem;
|
|
@@ -32,3 +39,12 @@ module.exports.fromJS = (source, name = __json) => {
|
|
|
32
39
|
|
|
33
40
|
return maybeNewline(removeBlankLines(sliced));
|
|
34
41
|
};
|
|
42
|
+
|
|
43
|
+
module.exports.isJSON = (source) => {
|
|
44
|
+
for (const type of TYPES) {
|
|
45
|
+
if (!source.indexOf(type))
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return false;
|
|
50
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/operator-json",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
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",
|
|
@@ -42,9 +42,6 @@
|
|
|
42
42
|
"supertape": "^8.0.0",
|
|
43
43
|
"try-catch": "^3.0.0"
|
|
44
44
|
},
|
|
45
|
-
"peerDependencies": {
|
|
46
|
-
"putout": ">=33"
|
|
47
|
-
},
|
|
48
45
|
"license": "MIT",
|
|
49
46
|
"engines": {
|
|
50
47
|
"node": ">=16"
|