RSA.helper.js 523 B

1234567891011121314151617
  1. const path = require('path');
  2. const fs = require('fs');
  3. module.exports = function* parse(file) {
  4. const cache = {};
  5. const data = fs.readFileSync(path.resolve(__dirname, file), 'utf8');
  6. for (const line of data.split('\r\n')) {
  7. const groups = line.match(/^(?<key>\w+) = (?<value>\w+)(?<extra>.*)$/)?.groups;
  8. if (groups) {
  9. const { key, value, extra } = groups;
  10. cache[key] = value;
  11. if (groups.key === 'Result') {
  12. yield Object.assign({ extra: extra.trim() }, cache);
  13. }
  14. }
  15. }
  16. };