src/io.js
// This is just a JSON read and parse except it supports '#' as a line-based comment.
This is just a JSON read and parse except it supports '#' as a line-based comment.
This is just a JSON read and parse except it supports ' # ' as a line - based comment .
async function jsonGet(pn, fn) {
  let jsonLines = [];
  try {
    if (pn === '') pn = '.';
    let text = await fileGet(pn, fn);
    let lines = text.replace(/\r\n/g,'\n').split('\n');
    for (let line of lines) {
      let x = findComment(line);
      line = (x < 0) ? line : line.substring(0, x);
      line = line.trim();
      if (line.length > 0)
        jsonLines.push(line);
    }
  } catch (err) {
    if (err.code === 'ENOENT') {
      return null;
    }
    log.error(`${fn}: ${err.message} for ${pn}`);
    process.exit(1);
  }
  try {
    let json = jsonLines.join('');
    let cfg = JSON.parse(json);
    return cfg;
  } catch (err) {
    log.error(`${fn}: ${err.message} for ${pn}`);
    process.exit(2);
  }
  return null;
}
async function jsonGet ( pn , fn ) { let jsonLines = [ ] ; try { if ( pn === '' ) pn = '.' ; let text = await fileGet ( pn , fn ) ; let lines = text . replace ( / \r\n / g , '\n' ) . split ( '\n' ) ; for ( let line of lines ) { let x = findComment ( line ) ; line = ( x < 0 ) ? line : line . substring ( 0 , x ) ; line = line . trim ( ) ; if ( line . length > 0 ) jsonLines . push ( line ) ; } } catch ( err ) { if ( err . code === 'ENOENT' ) { return null ; } log . error ( ` ${ fn } ${ err . message } ${ pn } ` ) ; process . exit ( 1 ) ; } try { let json = jsonLines . join ( '' ) ; let cfg = JSON . parse ( json ) ; return cfg ; } catch ( err ) { log . error ( ` ${ fn } ${ err . message } ${ pn } ` ) ; process . exit ( 2 ) ; } return null ; }
This is just a JSON read and parse except it supports '#' as a line-based comment.
This is just a JSON read and parse except it supports ' # ' as a line - based comment .