Codemirror get all lines as array - codemirror

Is there a way in Codemirror to get all the lines in the editor, represented as an array? I know it is possible to iterate over each lines like so..
editor.eachLine(line => {
// do something with line
})
..but I'm looking for a way to just get all the lines, something like editor.allLines() or something..

With editor.getValue(separator) you can get all lines as a sting separated by the given separator - default is "\n".
Then you can turn your previously generated string into an array with string.split(separator)
function getAllLinesAsArray (codeMirror) {
return codeMirror.getValue().split('\n')
}
DEMO: https://codepen.io/quic5/pen/WLzJPx

Related

How can I make NodeJS's console.log always print output within a single line no matter what?

Is there any way to format the JSON logged through console.log in the terminal?
I'm logging a lot of debug data and if the the logged data exceeds a certain length, the terminal logs it prettified in many lines. I'd like to change it to log in one line, no matter the length of the data. Is there any way to do that?
In summary, I want to change this log style:
[12:34:56][DEBUG][CODE] - {
data: {
action: 'action',
url: '/path/to/my/api?variableOne=valueOne&variableTwo=valueTwo'
}
}
To this log style:
[12:34:56][DEBUG][CODE] - { data: { action: 'action', url: '/path/to/my/api?variableOne=valueOne&variableTwo=valueTwo' } }
Is there any way to format the JSON logged through console.log in the terminal?
Yes there is. Create a custom console object. See the docs for how to do that and what options you can specify. In particular, see also the inspectOptions docs.
The particular inspectOptions option you are looking for are breaklength and compact:
breakLength: <integer> The length at which input values are split across multiple lines. Set to Infinity to format the input as a single line (in combination with compact set to true or any number >= 1). Default: 80.
compact: <boolean> | <integer> Setting this to false causes each object key to be displayed on a new line. It will break on new lines in text that is longer than breakLength. If set to a number, the most n inner elements are united on a single line as long as all properties fit into breakLength. Short array elements are also grouped together. For more information, see the example below. Default: 3.
So since you asked
I'd like to change it to log in one line, no matter the length of the data
Then you probably want to do something like this:
const { Console } = require('node:console')
console = new Console({
stdout: process.stdout,
stderr: process.stderr,
// ignoreErrors, colorMode, groupIndentation
inspectOptions: {
// ...
breakLength: Infinity,
compact: true,
// ...
}
});
And then you can test it with console.log({a:1,b:2,c:3,hello:"world!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"});.
You can also just use the util.inspect function on specific objects you want to make a formatted string for, and then do console.log on the default global console object, passing the returned string.

Scala replace one text for another text with special chars included

i need a function to replace one text per another one, currently this is the code i am using, but it's not really working, or at least instead of replacing, removing the text and leave it empty, this is the code:
Thanks for your time, appreciated
def replaceIcons(message: String) = {
message.replaceAll("[|TInterfaceiconsInv_Misc_Tournaments_banner_Human.png:13,8:14:0,9:-2,8|t]:", "[https://cdn.discordapp.com/emojis/511683443231424532.png?v=1]:")
}
This is the message i want to replace i.postimg.cc/zDHwfXHX/ser.png
The expected output is this one: i.postimg.cc/k4mCt5X3/serr.png
Example message to replace:
[global] [Zerobalas]: [|TInterfaceiconsInv_Misc_Tournaments_banner_Human.png:13,8:14:0,9:-2,8|t]: asd
Example output expected:
[global] [Zerobalas]: [https://cdn.discordapp.com/emojis/511683443231424532.png?v=1]: asd
Try this:
def replaceIcons(message: String) = {
message.replace("[|TInterfaceiconsInv_Misc_Tournaments_banner_Human.png:13,8:14:0,9:-2,8|t]:", "[https://cdn.discordapp.com/emojis/511683443231424532.png?v=1]:")
}
println(replaceIcons("[global] [Zerobalas]: [|TInterfaceiconsInv_Misc_Tournaments_banner_Human.png:13,8:14:0,9:-2,8|t]: asd"))

Flutter \n\n not breaking lines unless hard-coded string

I can see that Flutter allows me to use "\n\n" in a string and it causes a line break to appear in a Text item:
final String answer = "This is my text.\n\n"
"Here is the 2nd line.";
This is my text.
Here is the 2nd line.
However, when I try to use content pulled from firebase, and set in a variable, the line break ("\n") is actually printed:
final String answer = faq['answer'];
Shows:
This is my text.\n\nHere is the 2nd line.
How can I get my "\n\n" to actually show up as line breaks?
Firestore doesn't support any escape sequences within string values. If you write "\n" in a string, you're going to get exactly that back when you read it.
So you can try something like this:
final String answer = (faq['answer'] as String).replaceAll("\\n", "\n");

Delete duplicate multiple lines using vscode

i have so many line just like this json code (120000 lines)
{
"name":"V83.9",
"name":"Work",
"name":"V83.9",
"name":"Education",
"name":"V83.9",
"name":"Profession"
}
and i want this convert just like this
{
"name":"V83.9",
"name":"Work",
"name":"Education",
"name":"Profession"
}
and i wrote regex on vscode just like this but this is not working
Find: {\n"name":"$1",\n"name":"$2",\n"name":"$1",\n"name":"$3",\n"name":"$1",\n"name":"$4"\n}
Replace: {\n"name":"$1",\n"name":"$2",\n"name":"$3",\n"name":"$4"\n}
How do i do this?
Please check the Transformer extension, where i have applied it on your example and it works:

FPDF Converting Apostrophes into Weird Characters

I have this string passed from a JavaScript form:
4 H/M’s
Which gets posted to an array, called '$out' and is keyed by "blurb".
I use FPDF to output it, with MultiCell, like so:
$pdf->MultiCell(190,4,$out["blurb"]);
However, FPDF outputs this string:
4 H/M’s
I've tried
html_entity_decode($out["blurb"], ENT_QUOTES, "UTF-8")
but it doesn't seem to be working. Any suggestions?
Use iconv like this :
// put $str your sting to encode for FPDF
// put $myencoding value as you current encoding
function fpdf_encode($str,$myencoding='latin1') {
return iconv($myencoding, 'windows-1252', trim(utf8_decode($str)));
}