IvanMathy / Boop

A scriptable scratchpad for developers. In slow yet steady progress.
https://boop.okat.best
MIT License
3.82k stars 353 forks source link

Join lines (3 scripts) #128

Open hspagnolo opened 4 years ago

hspagnolo commented 4 years ago

Hello,

First, thank you for Boop, great software.

I do not know what I may do wrong, but the scrips "join lines", "join lines with space" and "join lines with comma" only joins the first 2 lines, not the other ones?

Thanks and regards Henri

IvanMathy commented 4 years ago

Hey there! Looks like a bug indeed, I'll try to figure out what's wrong and update the scripts. In the meantime, you can use the Collapse script from the standard library, which joins lines with commas.

lybc commented 4 years ago

I modified the script and now it can run normally

/**
    {
        "api":1,
        "name":"Join Lines With Comma",
        "description":"Joins all lines with a comma.",
        "author":"lybc",
        "icon":"collapse",
        "tags":"join, comma",
        "bias": -0.1
    }
**/

function main(state) {
    state.fullText = state.fullText.split("\n").join(', ')
}
hspagnolo commented 4 years ago

Thanks to both for your reply, I will test this ASAP. The 3 Trim scripts have also a bug I think, but I don't know how to solve them.

Nice day and regards Henri

lybc commented 4 years ago

I found a new problem, this string can not be json resolved.

[
{
"c": 125,
"day": "2020-07-22"
},
{
"c": 546,
"day": "2020-07-20"
},
{
"c": 652,
"day": "2020-07-14"
},
{
"c": 503,
"day": "2020-07-19"
},
{
"c": 552,
"day": "2020-07-17"
},
{
"c": 569,
"day": "2020-07-16"
},
{
"c": 540,
"day": "2020-07-15"
},
{
"c": 557,
"day": "2020-07-21"
},
{
"c": 678,
"day": "2020-07-13"
},
{
"c": 602,
"day": "2020-07-12"
},
{
"c": 540,
"day": "2020-07-18"
}
]

image

But it can be parsed elsewhere

IvanMathy commented 4 years ago

Hey there!

Your json is made of non-breaking spaces as whitespaces, which is an invalid character in the JSON spec. You can see that by running url encode. Boop uses Javascriptcore's JSON tools and therefore we have no control over how the parsing gets done.

If you run the JSON minifier script first, it'll clean it up and get rid of those characters so you'll be able to format it properly!

lybc commented 4 years ago

Hey there!

Your json is made of non-breaking spaces as whitespaces, which is an invalid character in the JSON spec. You can see that by running url encode. Boop uses Javascriptcore's JSON tools and therefore we have no control over how the parsing gets done.

If you run the JSON minifier script first, it'll clean it up and get rid of those characters so you'll be able to format it properly!

OK, thank you for reply

ievazer-zz commented 3 years ago

Unfortunately, using JSON minifier first still did not resolve the same issue for me.