I know this sound likes an already answered question but I looked at a link and tried the solution to no avail. Object.getOwnPropertyNames(this)
returns []
and Object.getOwnPropertyNames(global)
does show a lot of variables but any variables I declared in the program that is running the console interface isn't a part of this global
variable. I made a repl to my console interface and to explain what I mean, running it then entering values
will return an array, but I would like some list THAT HAS THESE VARIABLES
If you don't want to/can't run the repl, the code is below, save it as something and node filename
to see what I mean.
The problem, again, is that I want some list that includes all the variables declared in the program(global
doesn't have what I want and the variables are very accessible because when you run the program and enter values
it appears but if you can find some list that has values
I would be grateful)
var readline=require('readline');
const values = ['lorem ipsum', 'dolor sit amet']; //I want some list that has these variables
String.prototype.l=String.prototype.toLowerCase //shorter version of toLowerCase is now l
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: true,
historySize: 50,
tabSize: 2,
completer: function(line) {var hits=[]; var hitlist=[]
const completions = Object.getOwnPropertyNames(global)
function search1(c,l){return c.startsWith(l)}
function search2(c,l){return c.includes(l)&&c.startsWith(l)}
//ordering suggestions
hitlist.push( completions.filter(c=>search1(c,line)).sort() )
hitlist.push( completions.filter(c=>search1(c.l(),line.l())).sort() )
hitlist.push( completions.filter(c=>search2(c,line)).sort() )
hitlist.push( completions.filter(c=>search2(c.l(),line.l())).sort() )
hitlist.push( rl.history.filter(c=>search1(c,line)).sort() )
hitlist.push( rl.history.filter(c=>search1(c.l(),line.l())).sort() )
hitlist.push( rl.history.filter(c=>search2(c,line)).sort() )
hitlist.push( rl.history.filter(c=>search2(c.l(),line.l())).sort() )
//placing suggestions in one list
hitlist.forEach(a=>a.forEach(b=>{ if(hits.indexOf(b)==-1){hits.push(b)} }))
return [hits.length?hits:[],line]
}
});
rl.on('line',(line)=>{try{console.log(eval(line))} catch(e){console.error(e)}})
I'm not depending on the answer being from readline
im just showing WHY I want to get the in-file declared variables(for tab suggestions)