@putout/operator-json 1.1.0 → 1.2.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 +12 -0
  2. package/lib/json.js +11 -0
  3. package/package.json +1 -1
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,8 @@ 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 = [__json, __yaml, __filesystem, __ignore].map(cut);
16
+
15
17
  module.exports.__json = __json;
16
18
  module.exports.__yaml = __yaml;
17
19
  module.exports.__filesystem = __filesystem;
@@ -32,3 +34,12 @@ module.exports.fromJS = (source, name = __json) => {
32
34
 
33
35
  return maybeNewline(removeBlankLines(sliced));
34
36
  };
37
+
38
+ module.exports.isJSON = (source) => {
39
+ for (const type of TYPES) {
40
+ if (!source.indexOf(type))
41
+ return true;
42
+ }
43
+
44
+ return false;
45
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/operator-json",
3
- "version": "1.1.0",
3
+ "version": "1.2.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",