This simple plugin sends highlighted text to JavaScript eval()
function.
And returns result of that eval or serialized error.
Warning!!
It does not do any filtering so it might do things that it shouldn't do
This simple plugin sends highlighted text to JavaScript eval()
function.
And returns result of that eval or serialized error.
Warning!!
It does not do any filtering so it might do things that it shouldn't do
Unfortunately, the description on github is as short as the one here above. Is there any chance you could explain a bit more in detail what it does, and give an example what to are actually using it for ?
This plugin gets highlighted text in editor pane and calls JavaScript function eval()
with it.
eval()
is built in function in JavaScript that takes string (highlighted text) and executes it. (more about it here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval ).
You can use this plugin to run any JS code and automatically get output directly to editor.
For example highlighting text:
var a =1;
var b=2;
a+b;
Will paste sum 3
into editor.
So at simplest use case it can be a handy calculator.
Now I see, and now I understand the warning on git. Thanks!
I made small but substantial modification: await
before eval.
This allows to have results from Promises.
Like, how to get data from joplin
package, for example:
joplin.data.get(['search'], { query:"test",fields: ['id', 'title','body'] }).then(res => JSON.stringify(res, null,2))
Executing this inside a note with Eval plugin will return JSON with notes that normally would be returned by search for query test
.
{
"items": [
{
"id": "02400acada214e099bb8124e28d337f1",
"title": "test js",
"type_": 1
},
{
"id": "938624431fb44b9e92fdef50dd5cc40e",
"title": "test",
"type_": 1
}
{
"id": "749cbde2bcc441f08de95ef2103c81a1",
"title": "22/12/2020 14:29",
"type_": 1
},
{
"id": "f6662116a8704c9cb47fb903b4a4e2fd",
"title": "Auto related notes next under this note",
"type_": 1
},
],
"has_more": false
}
(i omitted body in this json for brevity )