I want to create a JS Preprocessor, this is just something to display data from js variables, I currently got:
var ____Code = fs.readFileSync(__resources + '/help.txt').toString();
____Code.split('{%').forEach((i,ii) => {
var _Code = i.split('%}')[0];
____Code.split('{%' + _Code + '%}').join(`${_Code}`);
});
The point of this code was basically if I had a js file looking like this:
var obj = {
hello: 'world',
language: 'javascript',
filetype: 'text',
test: {
successfull: 'Yes!'
}
}
var ____Code = fs.readFileSync(__resources + '/help.txt').toString();
____Code.split('{%').forEach((i,ii) => {
var _Code = i.split('%}')[0];
____Code.split('{%' + _Code + '%}').join(`${_Code}`);
});
And the help.txt looks like this:
Is this successfull? {%obj.test.successfull%}
I am a {%obj.filetype%} file, that is has been read by {%obj.language%}.
The default example for {%obj.language%} is: "Hello {%obj.hello%}"
Then I'd want the output to be:
Is this successfull? Yes!
I am a text file, that is has been read by javascript.
The default example for javascript is: "Hello world"
But the actual outcome is the exact same as help.txt, how may i make it replace {%variable%}
to the actual js variable?