jwalker 2.0.0 → 3.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.
package/bin/index.js CHANGED
@@ -1,50 +1,38 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- 'use strict';
4
-
5
- const
6
- fs = require('fs');
7
-
8
- const
9
- minimist = require('minimist');
10
-
11
- const
12
- JWalker = require('../lib');
13
-
14
- const
15
- args = minimist(process.argv.slice(2), {
16
- alias: {
17
- 'h': 'help',
18
- 's': 'spaces',
19
- 'p': 'passthrough',
20
- 'i': 'input',
21
- 'o': 'output'
22
- },
23
- '--': false
24
- });
25
-
26
- const help = () => {
27
-
28
- console.info('Usage: jwalker [options]');
29
- console.info();
30
- console.info(' Use -- (or omit) for stdin or stdout.');
31
- console.info();
32
- console.info(' Options:');
33
- console.info(' -i=[file], --input=[file] Input file (-- for stdin) (default=stdin).');
34
- console.info(' -o=[file], --output=[file] Output file (-- for stdout) (default=stdout).');
35
- console.info(' -p, --passthrough Passthrough non-JSON.');
36
- console.info(' -s=[spaces], --spaces=[spaces] Number of spaces per indentation (default=4).');
37
- console.info();
38
-
39
- process.exit(0);
40
-
41
- };
42
-
43
- if (args.help === true) return help();
44
-
45
- args.input = args.input || '--';
46
- args.output = args.output || '--';
47
-
48
- (args.input === '--' ? process.stdin : fs.createReadStream(args.input))
49
- .pipe(new JWalker({ passthroughNonJSON: args.passthrough, spaces: args.spaces }))
50
- .pipe((args.output === '--' ? process.stdout : fs.createWriteStream(args.output)));
3
+ import fs from 'fs';
4
+
5
+ import argumentsParser from '@trenskow/arguments-parser';
6
+
7
+ import JWalker from '../lib/index.js';
8
+
9
+ const {
10
+ input,
11
+ output,
12
+ spaces = '\t',
13
+ passthrough
14
+ } = await argumentsParser().options({
15
+ 'input': {
16
+ type: String,
17
+ default: '--',
18
+ description: 'Input file (-- for stdin).'
19
+ },
20
+ 'output': {
21
+ type: String,
22
+ default: '--',
23
+ description: 'Output file (-- for stdout).'
24
+ },
25
+ 'spaces': {
26
+ type: Number,
27
+ description: 'Use number of spaces for indentation (default is tab).'
28
+ },
29
+ 'passthrough': {
30
+ type: Boolean,
31
+ default: false,
32
+ description: 'Passthrough non-JSON lines.'
33
+ }
34
+ });
35
+
36
+ (input === '--' ? process.stdin : fs.createReadStream(input))
37
+ .pipe(new JWalker({ passthroughNonJSON: passthrough, spaces: spaces }))
38
+ .pipe((output === '--' ? process.stdout : fs.createWriteStream(output)));
@@ -0,0 +1,63 @@
1
+ import globals from 'globals';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import js from '@eslint/js';
5
+ import { FlatCompat } from '@eslint/eslintrc';
6
+ import { includeIgnoreFile } from '@eslint/compat';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+ const compat = new FlatCompat({
11
+ baseDirectory: __dirname,
12
+ recommendedConfig: js.configs.recommended,
13
+ allConfig: js.configs.all
14
+ });
15
+ const gitIgnorePath = path.resolve(__dirname, '.gitignore');
16
+
17
+ export default [...compat.extends('eslint:recommended'),
18
+ includeIgnoreFile(gitIgnorePath), {
19
+ languageOptions: {
20
+ globals: {
21
+ ...globals.node,
22
+ ...globals.mocha,
23
+ Router: true,
24
+ Endpoint: true,
25
+ app: true
26
+ },
27
+
28
+ ecmaVersion: 'latest',
29
+ sourceType: 'module'
30
+ },
31
+
32
+ rules: {
33
+ indent: ['error', 'tab', {
34
+ SwitchCase: 1
35
+ }],
36
+
37
+ 'linebreak-style': ['error', 'unix'],
38
+ quotes: ['error', 'single'],
39
+ semi: ['error', 'always'],
40
+
41
+ 'no-console': ['error', {
42
+ allow: ['warn', 'error', 'info']
43
+ }],
44
+
45
+ 'no-unused-vars': ['warn', {
46
+ argsIgnorePattern: '^_',
47
+ caughtErrors: 'none'
48
+ }],
49
+
50
+ 'no-empty': ['error', {
51
+ allowEmptyCatch: true
52
+ }],
53
+
54
+ 'no-trailing-spaces': ['error', {
55
+ ignoreComments: true
56
+ }],
57
+
58
+ 'require-atomic-updates': 'off',
59
+ 'no-implicit-globals': ['error'],
60
+ 'eol-last': ['error', 'always'],
61
+ 'comma-dangle': ['error', 'never']
62
+ }
63
+ }];
package/lib/index.js CHANGED
@@ -1,9 +1,7 @@
1
- 'use strict';
2
1
 
3
- const
4
- { Transform } = require('stream');
2
+ import { Transform } from 'stream';
5
3
 
6
- exports = module.exports = class JWalker extends Transform {
4
+ export default class JWalker extends Transform {
7
5
 
8
6
  constructor(options = {}) {
9
7
 
package/package.json CHANGED
@@ -1,39 +1,44 @@
1
1
  {
2
- "name": "jwalker",
3
- "version": "2.0.0",
4
- "description": "A JSON pretty-printer for each line in a stream. Useful for JSON logs.",
5
- "main": "index.js",
6
- "bin": {
7
- "jwalker": "./bin/index.js"
8
- },
9
- "scripts": {
10
- "test": "./node_modules/mocha/bin/mocha test/index.js"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/trenskow/jwalker.git"
15
- },
16
- "keywords": [
17
- "JSON",
18
- "lint",
19
- "pretty",
20
- "print",
21
- "line",
22
- "readline",
23
- "log",
24
- "logs",
25
- "stream"
26
- ],
27
- "author": "Kristian Trenskow <trenskow@me.com>",
28
- "license": "BSD-3-Clause",
29
- "bugs": {
30
- "url": "https://github.com/trenskow/jwalker/issues"
31
- },
32
- "homepage": "https://github.com/trenskow/jwalker#readme",
33
- "devDependencies": {
34
- "eslint": "^7.5.0"
35
- },
36
- "dependencies": {
37
- "minimist": "^1.2.5"
38
- }
2
+ "name": "jwalker",
3
+ "version": "3.0.0",
4
+ "description": "A JSON pretty-printer for each line in a stream. Useful for JSON logs.",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "bin": {
8
+ "jwalker": "./bin/index.js"
9
+ },
10
+ "scripts": {
11
+ "test": "./node_modules/mocha/bin/mocha test/index.js"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/trenskow/jwalker.git"
16
+ },
17
+ "keywords": [
18
+ "JSON",
19
+ "lint",
20
+ "pretty",
21
+ "print",
22
+ "line",
23
+ "readline",
24
+ "log",
25
+ "logs",
26
+ "stream"
27
+ ],
28
+ "author": "Kristian Trenskow <trenskow@me.com>",
29
+ "license": "BSD-3-Clause",
30
+ "bugs": {
31
+ "url": "https://github.com/trenskow/jwalker/issues"
32
+ },
33
+ "homepage": "https://github.com/trenskow/jwalker#readme",
34
+ "devDependencies": {
35
+ "@eslint/compat": "^2.0.0",
36
+ "@eslint/eslintrc": "^3.3.3",
37
+ "@eslint/js": "^9.39.2",
38
+ "eslint": "^9.39.2",
39
+ "globals": "^17.0.0"
40
+ },
41
+ "dependencies": {
42
+ "@trenskow/arguments-parser": "^0.3.54"
43
+ }
39
44
  }