fx 30.0.2 → 30.1.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/index.js +45 -30
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -18,6 +18,7 @@ void async function main() {
|
|
|
18
18
|
}
|
|
19
19
|
if (flagHelp || (args.length === 0 && process.stdin.isTTY))
|
|
20
20
|
return printUsage()
|
|
21
|
+
const theme = themes(process.stdout.isTTY ? (process.env.FX_THEME || '1') : '0')
|
|
21
22
|
await importFxrc(process.cwd())
|
|
22
23
|
await importFxrc(os.homedir())
|
|
23
24
|
let fd = 0 // stdin
|
|
@@ -35,17 +36,17 @@ void async function main() {
|
|
|
35
36
|
for (const json of input) {
|
|
36
37
|
array.push(json)
|
|
37
38
|
}
|
|
38
|
-
await runTransforms(array, args)
|
|
39
|
+
await runTransforms(array, args, theme)
|
|
39
40
|
} else {
|
|
40
41
|
for (const json of input) {
|
|
41
|
-
await runTransforms(json, args)
|
|
42
|
+
await runTransforms(json, args, theme)
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
}()
|
|
45
46
|
|
|
46
47
|
const skip = Symbol('skip')
|
|
47
48
|
|
|
48
|
-
async function runTransforms(json, args) {
|
|
49
|
+
async function runTransforms(json, args, theme) {
|
|
49
50
|
const process = await import('node:process')
|
|
50
51
|
let i, code, output = json
|
|
51
52
|
for ([i, code] of args.entries()) try {
|
|
@@ -62,7 +63,7 @@ async function runTransforms(json, args) {
|
|
|
62
63
|
else if (output === skip)
|
|
63
64
|
return
|
|
64
65
|
else
|
|
65
|
-
console.log(stringify(output,
|
|
66
|
+
console.log(stringify(output, theme))
|
|
66
67
|
|
|
67
68
|
function printErr(err) {
|
|
68
69
|
let pre = args.slice(0, i).join(' ')
|
|
@@ -127,6 +128,10 @@ async function transform(json, code) {
|
|
|
127
128
|
return `x => Object.values(${obj}).flatMap(${fold(s)})`
|
|
128
129
|
}
|
|
129
130
|
|
|
131
|
+
function len(array) {
|
|
132
|
+
return array.length
|
|
133
|
+
}
|
|
134
|
+
|
|
130
135
|
function uniq(array) {
|
|
131
136
|
return [...new Set(array)]
|
|
132
137
|
}
|
|
@@ -520,14 +525,10 @@ function* parseJson(gen) {
|
|
|
520
525
|
}
|
|
521
526
|
}
|
|
522
527
|
|
|
523
|
-
function stringify(value,
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
number: isPretty ? '\x1b[36m' : '',
|
|
528
|
-
boolean: isPretty ? '\x1b[35m' : '',
|
|
529
|
-
null: isPretty ? '\x1b[38;5;243m' : '',
|
|
530
|
-
reset: isPretty ? '\x1b[0m' : '',
|
|
528
|
+
function stringify(value, theme) {
|
|
529
|
+
function color(id, str) {
|
|
530
|
+
if (theme[id] === '') return str
|
|
531
|
+
return `\x1b[${theme[id]}m${str}\x1b[0m`
|
|
531
532
|
}
|
|
532
533
|
|
|
533
534
|
function getIndent(level) {
|
|
@@ -536,38 +537,35 @@ function stringify(value, isPretty = false) {
|
|
|
536
537
|
|
|
537
538
|
function stringifyValue(value, level = 0) {
|
|
538
539
|
if (typeof value === 'string') {
|
|
539
|
-
return
|
|
540
|
+
return color(2, JSON.stringify(value))
|
|
540
541
|
} else if (typeof value === 'number') {
|
|
541
|
-
return `${
|
|
542
|
+
return color(3, `${value}`)
|
|
542
543
|
} else if (typeof value === 'bigint') {
|
|
543
|
-
return `${
|
|
544
|
+
return color(3, `${value}`)
|
|
544
545
|
} else if (typeof value === 'boolean') {
|
|
545
|
-
return `${
|
|
546
|
+
return color(4, `${value}`)
|
|
546
547
|
} else if (value === null || typeof value === 'undefined') {
|
|
547
|
-
return
|
|
548
|
+
return color(5, `null`)
|
|
548
549
|
} else if (Array.isArray(value)) {
|
|
549
550
|
if (value.length === 0) {
|
|
550
|
-
return `[]`
|
|
551
|
+
return color(0, `[]`)
|
|
551
552
|
}
|
|
552
553
|
const items = value
|
|
553
|
-
.map((v) =>
|
|
554
|
-
.join('
|
|
555
|
-
return
|
|
554
|
+
.map((v) => getIndent(level + 1) + stringifyValue(v, level + 1))
|
|
555
|
+
.join(color(0, ',') + '\n')
|
|
556
|
+
return color(0, '[') + '\n' + items + '\n' + getIndent(level) + color(0, ']')
|
|
556
557
|
} else if (typeof value === 'object') {
|
|
557
558
|
const keys = Object.keys(value)
|
|
558
559
|
if (keys.length === 0) {
|
|
559
|
-
return
|
|
560
|
+
return color(0, '{}')
|
|
560
561
|
}
|
|
561
562
|
const entries = keys
|
|
562
|
-
.map(
|
|
563
|
-
(key)
|
|
564
|
-
|
|
565
|
-
value[key],
|
|
566
|
-
level + 1,
|
|
567
|
-
)}`,
|
|
563
|
+
.map((key) =>
|
|
564
|
+
getIndent(level + 1) + color(1, `"${key}"`) + color(0, ': ') +
|
|
565
|
+
stringifyValue(value[key], level + 1),
|
|
568
566
|
)
|
|
569
|
-
.join('
|
|
570
|
-
return
|
|
567
|
+
.join(color(0, ',') + '\n')
|
|
568
|
+
return color(0, '{') + '\n' + entries + '\n' + getIndent(level) + color(0, '}')
|
|
571
569
|
}
|
|
572
570
|
throw new Error(`Unsupported value type: ${typeof value}`)
|
|
573
571
|
}
|
|
@@ -575,6 +573,23 @@ function stringify(value, isPretty = false) {
|
|
|
575
573
|
return stringifyValue(value)
|
|
576
574
|
}
|
|
577
575
|
|
|
576
|
+
function themes(id) {
|
|
577
|
+
const themes = {
|
|
578
|
+
'0': ['', '', '', '', '', ''],
|
|
579
|
+
'1': ['', '1;34', '32', '36', '35', '38;5;243'],
|
|
580
|
+
'2': ['', '32', '34', '36', '35', '38;5;243'],
|
|
581
|
+
'3': ['', '95', '93', '96', '31', '38;5;243'],
|
|
582
|
+
'4': ['', '38;5;50', '38;5;39', '38;5;98', '38;5;205', '38;5;243'],
|
|
583
|
+
'5': ['', '38;5;230', '38;5;221', '38;5;209', '38;5;209', '38;5;243'],
|
|
584
|
+
'6': ['', '38;5;69', '38;5;78', '38;5;221', '38;5;203', '38;5;243'],
|
|
585
|
+
'7': ['', '1;38;5;42', '1;38;5;213', '1;38;5;201', '1;38;5;201', '38;5;243'],
|
|
586
|
+
'8': ['', '1;38;5;51', '38;5;195', '38;5;123', '38;5;50', '38;5;243'],
|
|
587
|
+
'🔵': ['1;38;5;33', '38;5;33', '', '', '', ''],
|
|
588
|
+
'🥝': ['38;5;179', '1;38;5;154', '38;5;82', '38;5;226', '38;5;226', '38;5;230'],
|
|
589
|
+
}
|
|
590
|
+
return themes[id] || themes['1']
|
|
591
|
+
}
|
|
592
|
+
|
|
578
593
|
async function importFxrc(path) {
|
|
579
594
|
const {join} = await import('node:path')
|
|
580
595
|
const {pathToFileURL} = await import('node:url')
|