If i have this code
ArbFileProvider.js
const fs = require("fs");
class ArbFile {
constructor(arbFile) {
this.arbFile = arbFile;
}
async read() {
const arbFileContents = await fs.promises.readFile(this.arbFile);
this._arbFileObject = JSON.parse(arbFileContents.toString());
console.log(this._arbFileObject);
this._getRessources();
console.log(JSON.stringify(this.ressources));
console.log(JSON.stringify(this.properites));
}
_getRessources() {
const ressourcesKeys = Object.keys(this._arbFileObject).filter(
key => key.match(/^@{1,2}/g) == undefined
);
console.log("ressourcesKeys", ressourcesKeys);
this.ressources = new Map();
ressourcesKeys.forEach(key => {
this.ressources.set(key, {
value: this._arbFileObject[key],
...(this._arbFileObject[
Object.keys(this._arbFileObject).find(val => val == `@${key}`)
] || {})
});
});
console.log("ressources", JSON.stringify(this.ressources));
const propertiesKeys = Object.keys(this._arbFileObject).filter(
key => key.match(/^@@/g) != undefined
);
this.properites = new Map();
propertiesKeys.forEach(key => {
this.properites.set(key.replace(/^@@/g, ""), this._arbFileObject[key]);
});
}
}
module.exports = ArbFile;
at that point
console.log(JSON.stringify(this.ressources));
this.ressources is an empty map. I don't know why. In the debugger I can clearly see, that is has 55 entries. I have already tried to log for example the Object.keys() of it, but it is an empty Array too.
The arbFile parameter at the constructor is an path to an json-like ARB file.
To call that class, I create an new instance of ArbFile and then call read() on it.