@putout/operator-json 1.0.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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -0
  3. package/lib/json.js +28 -0
  4. package/package.json +58 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) coderaiser
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # @putout/operator-json [![NPM version][NPMIMGURL]][NPMURL]
2
+
3
+ [NPMIMGURL]: https://img.shields.io/npm/v/@putout/operator-json.svg?style=flat&longCache=true
4
+ [NPMURL]: https://npmjs.org/package/@putout/operator-json "npm"
5
+
6
+ 🐊[**Putout**](https://github.com/coderaiser/putout) operator adds ability to lint json.
7
+
8
+ ## Install
9
+
10
+ ```
11
+ npm i putout @putout/operator-json
12
+ ```
13
+
14
+ ## API
15
+
16
+ ### `__json`
17
+
18
+ ```
19
+ export const traverse = ({
20
+ [__json]: (path) => {
21
+ },
22
+ });
23
+ ```
24
+
25
+ ### `__filesystem`
26
+
27
+ ```
28
+ export const traverse = ({
29
+ [__filesystem]: (path) => {
30
+ },
31
+ });
32
+ ```
33
+
34
+ ### `toJS(source: string, name?: string)`;
35
+
36
+ ```js
37
+ toJS('{"hello": "world"}');
38
+ // returns
39
+ `__putout_processor_json('{"hello": "world"});`;
40
+
41
+ toJS('{"hello": "world"}', __filesystem);
42
+ // returns
43
+ `__putout_processor_filesystem('{"hello": "world"});`;
44
+ ```
45
+
46
+ ### `fromJS(source: string, name?: string)`;
47
+
48
+ ```js
49
+ fromJS(`__putout_processor_json('{"hello": "world"}');
50
+ // returns
51
+ `{"hello": "world"}`;
52
+ ```
53
+
54
+ ## License
55
+
56
+ MIT
package/lib/json.js ADDED
@@ -0,0 +1,28 @@
1
+ const removeBlankLines = require('remove-blank-lines');
2
+
3
+ const maybeNewline = (a) => a.at(-1) === '\n' ? a : `${a}\n`;
4
+ const createPrefix = (name) => `${name}(`;
5
+ const createSuffix = () => ');\n';
6
+
7
+ const __json = '__putout_processor_json';
8
+ const __filesystem = '__putout_processor_filesystem';
9
+
10
+ module.exports.__json = __json;
11
+ module.exports.__filesystem = __filesystem;
12
+
13
+ module.exports.toJS = (source, name = __json) => {
14
+ const prefix = createPrefix(name);
15
+ const suffix = createSuffix();
16
+
17
+ return `${prefix}${source}${suffix}`;
18
+ };
19
+
20
+ module.exports.fromJS = (source, name = __json) => {
21
+ const prefix = createPrefix(name);
22
+ const suffix = createSuffix();
23
+ const length = source.length - suffix.length;
24
+ const sliced = source.slice(prefix.length, length);
25
+
26
+ return maybeNewline(removeBlankLines(sliced));
27
+ };
28
+
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@putout/operator-json",
3
+ "version": "1.0.0",
4
+ "type": "commonjs",
5
+ "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
+ "description": "🐊Putout operator adds ability to json referenced variables that was not defined",
7
+ "homepage": "https://github.com/coderaiser/putout/tree/master/packages/operator-json#readme",
8
+ "main": "lib/json.js",
9
+ "release": false,
10
+ "tag": false,
11
+ "changelog": false,
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git://github.com/coderaiser/putout.git"
15
+ },
16
+ "scripts": {
17
+ "test": "madrun test",
18
+ "watch:test": "madrun watch:test",
19
+ "lint": "madrun lint",
20
+ "fresh:lint": "madrun fresh:lint",
21
+ "lint:fresh": "madrun lint:fresh",
22
+ "fix:lint": "madrun fix:lint",
23
+ "coverage": "madrun coverage",
24
+ "report": "madrun report"
25
+ },
26
+ "keywords": [
27
+ "putout",
28
+ "putout-operator",
29
+ "operator",
30
+ "json"
31
+ ],
32
+ "devDependencies": {
33
+ "@putout/test": "^7.0.0",
34
+ "c8": "^8.0.0",
35
+ "eslint": "^8.0.1",
36
+ "eslint-plugin-n": "^16.0.0",
37
+ "eslint-plugin-putout": "^21.0.0",
38
+ "lerna": "^6.0.1",
39
+ "madrun": "^9.0.0",
40
+ "montag": "^1.2.1",
41
+ "nodemon": "^3.0.1",
42
+ "supertape": "^8.0.0",
43
+ "try-catch": "^3.0.0"
44
+ },
45
+ "peerDependencies": {
46
+ "putout": ">=33"
47
+ },
48
+ "license": "MIT",
49
+ "engines": {
50
+ "node": ">=16"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "dependencies": {
56
+ "remove-blank-lines": "^1.4.1"
57
+ }
58
+ }