fx 25.0.0 → 26.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 (3) hide show
  1. package/README.md +11 -3
  2. package/index.js +21 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -9,19 +9,19 @@ npm i -g fx
9
9
  Or use **npx**:
10
10
 
11
11
  ```sh
12
- cat file.json | npx fx .param
12
+ cat file.json | npx fx .field
13
13
  ```
14
14
 
15
15
  Or use **node**:
16
16
 
17
17
  ```sh
18
- cat file.json | node <(curl -s https://fx.wtf) .param
18
+ cat file.json | node <(curl -s https://fx.wtf) .field
19
19
  ```
20
20
 
21
21
  Or use **deno**:
22
22
 
23
23
  ```sh
24
- cat file.json | deno run https://fx.wtf .param
24
+ cat file.json | deno run https://fx.wtf .field
25
25
  ```
26
26
 
27
27
  ## Usage
@@ -73,6 +73,14 @@ Fx works with promises.
73
73
  echo '"https://medv.io/*"' | fx 'fetch' '.text()'
74
74
  ```
75
75
 
76
+ When using the **-r** or **--raw** flag, the input will be treated as a raw string
77
+ instead of JSON. This can be useful when working with non-JSON input data, such as
78
+ plain text or CSV data.
79
+
80
+ ```sh
81
+ ls | fx -r '.trim().split("\n")'
82
+ ```
83
+
76
84
  ## License
77
85
 
78
86
  [MIT](../LICENSE)
package/index.js CHANGED
@@ -1,13 +1,23 @@
1
+ #!/usr/bin/env node
1
2
  void async function main() {
2
3
  const process = await import('node:process')
3
4
  const args = process.argv.slice(2)
5
+ if ((args.length === 0 && process.stdin.isTTY)
6
+ || (args.length === 1 && ['-h', '--help'].includes(args[0]))) {
7
+ printUsage()
8
+ return
9
+ }
10
+
4
11
  let input = ''
5
12
  process.stdin.setEncoding('utf8')
6
13
  for await (const chunk of process.stdin)
7
14
  input += chunk
8
15
 
9
16
  let json
10
- try {
17
+ if (['-r', '--raw'].includes(args[0])) {
18
+ args.shift()
19
+ json = input
20
+ } else try {
11
21
  json = JSON.parse(input)
12
22
  } catch (err) {
13
23
  process.stderr.write(`Invalid JSON: ${err.message}\n`)
@@ -114,3 +124,13 @@ function groupBy(keyOrFunction) {
114
124
  return grouped
115
125
  }
116
126
  }
127
+
128
+ function printUsage() {
129
+ const usage = `Usage
130
+ fx [flags] [code...]
131
+
132
+ Flags
133
+ -h, --help Display this help message
134
+ -r, --raw Treat input as raw string`
135
+ console.log(usage)
136
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fx",
3
- "version": "25.0.0",
3
+ "version": "26.0.0",
4
4
  "bin": {
5
5
  "fx": "index.js"
6
6
  },