Compare commits

...

3 Commits

Author SHA1 Message Date
Anton Medvedev 21f58332a9
Release 34 2 months ago
Anton Medvedev fe1216f875
Fixes #302 2 months ago
Anton Medvedev bf8fe0a9ef
Add list builtin 2 months ago

@ -53,6 +53,7 @@ var globals = []string{
"keys",
"values",
"skip",
"list",
}
//go:embed prelude.js

@ -91,7 +91,7 @@ func Reduce(args []string) {
for _, fn := range fns {
code.WriteString(Transform(fn))
}
code.WriteString("JSON.stringify(json)")
code.WriteString(`json === skip ? '__skip__' : JSON.stringify(json)`)
vm := goja.New()
vm.Set("println", func(s string) any {
@ -111,6 +111,10 @@ func Reduce(args []string) {
return
}
if output == "__skip__" {
return
}
node, err := jsonx.Parse([]byte(output))
if err != nil {
println(err.Error())

@ -2,7 +2,13 @@ const console = {
log: function (...args) {
const parts = []
for (const arg of args) {
parts.push(typeof arg === 'string' ? arg : JSON.stringify(arg, null, 2))
if (typeof arg === 'undefined') {
parts.push('undefined')
} else if (typeof arg === 'string') {
parts.push(arg)
} else {
parts.push(JSON.stringify(arg, null, 2))
}
}
println(parts.join(' '))
},

@ -1,3 +1,5 @@
const skip = Symbol('skip')
function apply(fn, ...args) {
if (typeof fn === 'function') return fn(...args)
return fn
@ -89,3 +91,11 @@ function values(x) {
if (typeof x === 'object' && x !== null) return Object.values(x)
throw new Error(`Cannot get values of ${typeof x}`)
}
function list(x) {
if (Array.isArray(x)) {
for (const y of x) console.log(y)
return skip
}
throw new Error(`Cannot list ${typeof x}`)
}

@ -97,6 +97,10 @@ func (n *Node) Parent() *Node {
return parent
}
func (n *Node) IsWrap() bool {
return n.Value == nil && n.Chunk != nil
}
func (n *Node) IsCollapsed() bool {
return n.Collapsed != nil
}

@ -1014,6 +1014,9 @@ func (m *model) cursorKey() string {
if at == nil {
return ""
}
if at.IsWrap() {
at = at.Parent()
}
if at.Key != nil {
var v string
_ = json.Unmarshal(at.Key, &v)

@ -233,6 +233,14 @@ async function run(json, code) {
if (typeof x === 'object' && x !== null) return Object.values(x)
throw new Error(`Cannot get values of ${typeof x}`)
}
function list(x) {
if (Array.isArray(x)) {
for (const y of x) console.log(y)
return skip
}
throw new Error(`Cannot list ${typeof x}`)
}
}
async function read(fd = 0) {

@ -1,6 +1,6 @@
{
"name": "fx",
"version": "33.0.0",
"version": "34.0.0",
"bin": {
"fx": "index.js"
},

@ -14,8 +14,12 @@ import (
var src []byte
func reduce(fns []string) {
var deno bool
if _, ok := os.LookupEnv("FX_JS"); ok {
engine.Reduce(fns)
return
}
var deno bool
bin, err := exec.LookPath("node")
if err != nil {
bin, err = exec.LookPath("deno")

@ -1,5 +1,5 @@
name: fx
version: 33.0.0
version: 34.0.0
summary: Terminal JSON viewer
description: Terminal JSON viewer
base: core20

@ -1,3 +1,3 @@
package main
const version = "33.0.0"
const version = "34.0.0"

Loading…
Cancel
Save