cborg 4.1.3 → 4.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/CHANGELOG.md +14 -0
  2. package/lib/bin.js +26 -9
  3. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [4.2.0](https://github.com/rvagg/cborg/compare/v4.1.4...v4.2.0) (2024-04-05)
2
+
3
+
4
+ ### Features
5
+
6
+ * cli argument to set width of diagnostic output ([#118](https://github.com/rvagg/cborg/issues/118)) ([4891cb8](https://github.com/rvagg/cborg/commit/4891cb8e262ece06d79ce380945cc3666a32aa45))
7
+
8
+ ## [4.1.4](https://github.com/rvagg/cborg/compare/v4.1.3...v4.1.4) (2024-03-26)
9
+
10
+
11
+ ### Trivial Changes
12
+
13
+ * **deps-dev:** bump @semantic-release/release-notes-generator ([0d61874](https://github.com/rvagg/cborg/commit/0d6187404475ec3be8dc0c628e9acf073dcc6927))
14
+
1
15
  ## [4.1.3](https://github.com/rvagg/cborg/compare/v4.1.2...v4.1.3) (2024-03-18)
2
16
 
3
17
 
package/lib/bin.js CHANGED
@@ -11,17 +11,17 @@ import { fromHex as _fromHex, toHex } from './byte-utils.js'
11
11
  function usage (code) {
12
12
  console.error('Usage: cborg <command> <args>')
13
13
  console.error('Valid commands:')
14
- console.error('\tbin2diag [binary input]')
14
+ console.error('\tbin2diag [--width <width>] [binary input]')
15
15
  console.error('\tbin2hex [binary input]')
16
16
  console.error('\tbin2json [--pretty] [binary input]')
17
17
  console.error('\tdiag2bin [diagnostic input]')
18
18
  console.error('\tdiag2hex [diagnostic input]')
19
19
  console.error('\tdiag2json [--pretty] [diagnostic input]')
20
20
  console.error('\thex2bin [hex input]')
21
- console.error('\thex2diag [hex input]')
21
+ console.error('\thex2diag [--width <width>] [hex input]')
22
22
  console.error('\thex2json [--pretty] [hex input]')
23
23
  console.error('\tjson2bin \'[json input]\'')
24
- console.error('\tjson2diag \'[json input]\'')
24
+ console.error('\tjson2diag [--width <width>] \'[json input]\'')
25
25
  console.error('\tjson2hex \'[json input]\'')
26
26
  console.error('Input may either be supplied as an argument or piped via stdin')
27
27
  process.exit(code || 0)
@@ -54,6 +54,20 @@ function argvPretty () {
54
54
  return { argv, pretty }
55
55
  }
56
56
 
57
+ function argvWidth () {
58
+ const widthIndex = process.argv.findIndex((s) => s === '--width')
59
+ if (widthIndex <= 0 || widthIndex + 1 >= process.argv.length) {
60
+ return { argv: process.argv.filter((s) => s !== '--width'), width: undefined }
61
+ }
62
+ const width = parseInt(process.argv[widthIndex + 1], 10)
63
+ if (!width || width < 20) {
64
+ return { argv: process.argv.filter((s) => s !== '--width'), width: undefined }
65
+ }
66
+ const argv = process.argv
67
+ argv.splice(widthIndex, 2)
68
+ return { argv, width }
69
+ }
70
+
57
71
  async function run () {
58
72
  const cmd = process.argv[2]
59
73
 
@@ -64,8 +78,9 @@ async function run () {
64
78
 
65
79
  case 'bin2diag': {
66
80
  /* c8 ignore next 1 */
67
- const bin = process.argv.length < 4 ? (await fromStdin()) : new TextEncoder().encode(process.argv[3])
68
- for (const line of tokensToDiagnostic(bin)) {
81
+ const { argv, width } = argvWidth()
82
+ const bin = argv.length < 4 ? (await fromStdin()) : new TextEncoder().encode(argv[3])
83
+ for (const line of tokensToDiagnostic(bin, width)) {
69
84
  console.log(line)
70
85
  }
71
86
  return
@@ -114,8 +129,9 @@ async function run () {
114
129
  }
115
130
 
116
131
  case 'hex2diag': {
117
- const bin = fromHex(process.argv.length < 4 ? (await fromStdin()).toString() : process.argv[3])
118
- for (const line of tokensToDiagnostic(bin)) {
132
+ const { argv, width } = argvWidth()
133
+ const bin = fromHex(argv.length < 4 ? (await fromStdin()).toString() : argv[3])
134
+ for (const line of tokensToDiagnostic(bin, width)) {
119
135
  console.log(line)
120
136
  }
121
137
  return
@@ -134,9 +150,10 @@ async function run () {
134
150
  }
135
151
 
136
152
  case 'json2diag': {
137
- const inp = process.argv.length < 4 ? (await fromStdin()).toString() : process.argv[3]
153
+ const { argv, width } = argvWidth()
154
+ const inp = argv.length < 4 ? (await fromStdin()).toString() : argv[3]
138
155
  const obj = JSON.parse(inp)
139
- for (const line of tokensToDiagnostic(encode(obj))) {
156
+ for (const line of tokensToDiagnostic(encode(obj), width)) {
140
157
  console.log(line)
141
158
  }
142
159
  return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cborg",
3
- "version": "4.1.3",
3
+ "version": "4.2.0",
4
4
  "description": "Fast CBOR with a focus on strictness",
5
5
  "main": "cborg.js",
6
6
  "type": "module",
@@ -33,7 +33,7 @@
33
33
  "@semantic-release/git": "^10.0.1",
34
34
  "@semantic-release/github": "^10.0.0",
35
35
  "@semantic-release/npm": "^12.0.0",
36
- "@semantic-release/release-notes-generator": "^12.1.0",
36
+ "@semantic-release/release-notes-generator": "^13.0.0",
37
37
  "@types/chai": "^4.3.11",
38
38
  "@types/mocha": "^10.0.6",
39
39
  "@types/node": "^20.10.8",