Parses content of a json file.
@param {Function} callback - Callback that expects a possible error
and the result.
@param {*} err - Possible error passed by caller.
@param {String} data - Content of the file.
432789
function _jsonLoaded(callback, err, data) {
  if (err) return callback(err);
  var parsed;
  try {
    parsed = JSON.parse(data);
  } catch(jerr) {
    return callback(jerr);
  }
  callback(null, parsed);
}
532912
function (err, params) {
                if (!err) {
                  callback && callback(null, params);
                }
                else {
                  callback && callback(err.message || err);
                }
              }
533866
function sendErrorResponse(err, callback = undefined, returnData = undefined) {
  let error;
  if (err instanceof Error) {
    error = err;
  } else {
    error = new Error(err);
  }

  if (callback) {
    callback(error, returnData);
  } else {
    throw error;
  }
}
1215059
function handler ( err, data ){
      if ( callback != null ){
        callback.apply( b9, arguments );
      }
      // only emit events when there is no error
      if ( err == null ){
        b9.emit.call( b9, method, data );
      }
    }
714098
function onFileReady(err, data) {
    if (err) {
      if (onDone) onDone(err)
      else console.error('>>>' + err);
      return;
    }

    var fileContent = data.toString();

    var msg = {
      text:    fileContent,
      mode:    flavor,
      context: context
    };

    var jsonMsg = JSON.stringify(msg);

    var options = {
      method: 'POST',
      preambleCRLF: true,
      postambleCRLF: true,
      uri: 'https://api.github.com/markdown',
      'content-type': 'application/json',
      headers: {
        'User-Agent' : userName
      },
      body: jsonMsg
    };

    //=======================================================
    // Call the Github Markdown API to parse the file content
    //=======================================================
    request(options, handleResponse.bind(this));

    //======================================================
    // Enhance the output of the Github Markdown API with
    // optional header or trailer.
    //======================================================
    function handleResponse(err, response, body) {
      if (this.debug) console.error('>>>handling response...');
      if (err) {
        if (onDone) onDone(err)
        else console.error('>>>upload to github failed: ', err);
        return;
      }

      if (stylesheet || title) {
        if (titleText == null) titleText = fileName;
        this.cat('<!DOCTYPE html>\n' +
                 '<html>\n' +
                 '<head>\n' +
                 '  <title>' + titleText + '</title>\n' +
                 '  <link rel="stylesheet" href="' + stylesheet + '">\n' +
                 '</head>\n' +
                 '<body>\n' );
      }

      this.cat(body);
      this.cat('\n');

      if (stylesheet || title) {
        this.cat( '</body>\n</html>\n' );
      }

      if (this.debug) console.error('>>>finished getting code');
      this.done = true;
      if (onDone) onDone();
    } // end handleResponse
  }
1125597
function ParseError(message, start, end, next) {
	this.message = message;
	this.start = start;
	this.end = end;
	this.next = next;
}
440282
function(err, result) {
      if (err && !util.isError(err)) {
        err = new Error(err);
      }
      if (callback) callback(err, result);
    }
1035081
function(pages, callback) {
      var t = this,
          didError = false,
          numLeft = pages.length;

      // Callback early if no pages to read
      if (pages.length === 0) {
        return callback();
      }

      // Read and parse each file for the title/description
      pages.forEach(function(page, index) {

        // Read the file
        var fullPath = Path.join(t.dirPath, page.id + '.json');
        FS.readFile(fullPath, 'utf8', function(error, file) {

          // Process a stat error
          if (error) {
            didError = true;
            return callback(error);
          }

          // Parse the JSON
          var parsed = null;
          try {
            parsed = JSON.parse(file);
          }
          catch (e) {
            didError = true;
            console.error('JSON error parsing page: ' + fullPath, e);
            return callback(e);
          }

          // Do nothing if a prior error callback happened
          if (didError) {
            return;
          }

          // Set the page title and description
          if (parsed.title) {
            page.label = parsed.title;
          }
          if (parsed.description) {
            page.description = parsed.description;
          }

          // Add a file watcher if not already watching
          if (!t.fileWatchers[page.id]) {
            t.fileWatchers[page.id] = new FS.watch(fullPath, {persistent:false}, function(type){
              t.sync();
            });
          }

          // Callback if all page reads are complete
          if (--numLeft === 0) {
            callback(null);
          }
        });
      });
    }
519403
function _fireReadFileCallbacks(filename, data, error=false) {
  const callbacks = readFileCallbacks.get(filename);
  if (callbacks) {
    if (callbacks.size) callbacks.forEach(callback=>error?callback(data, null):callback(null, data));
    callbacks.clear();
    readFileCallbacks.delete(filename);
  }
}
1162829
function parseError (err) {
    var filePath, lineNum, splitLines
    var result = {}

    // For root files that syntax-error doesn't pick up:
    var parseFilePrefix = 'Parsing file '
    if (err.indexOf(parseFilePrefix) === 0) {
      var pathWithErr = err.substring(parseFilePrefix.length)
      filePath = getFilePath(pathWithErr)
      if (!filePath) return result
      result.path = filePath
      var messageAndLine = pathWithErr.substring(filePath.length)
      lineNum = /\((\d+):(\d+)\)/.exec(messageAndLine)
      if (!lineNum) return result
      result.message = messageAndLine.substring(1, lineNum.index).trim()
      result.line = parseInt(lineNum[1], 10)
      result.column = parseInt(lineNum[2], 10)
      result.format = true
      return result
    }

    // if module not found
    var cannotFindModule = /^Cannot find module '(.+)' from '(.+)'(?:$| while parsing file: (.*)$)/.exec(err.trim())
    if (cannotFindModule) {
      result.missingModule = cannotFindModule[1]
      result.path = cannotFindModule[3] || cannotFindModule[2]
      result.message = "Cannot find module '" + result.missingModule + "'"
      result.format = true
      return result
    }

    // syntax-error returns the path and line number, also a \n at start
    err = err.trim()
    filePath = getFilePath(err)
    if (!filePath) return result
    result.path = filePath

    var restOfMessage = err.substring(filePath.length)
    var parsedSyntaxError = /^:(\d+)/.exec(restOfMessage)
    if (parsedSyntaxError) { // this is a syntax-error
      lineNum = parseInt(parsedSyntaxError[1], 10)
      if (isFinite(lineNum)) result.line = lineNum
      splitLines = restOfMessage.split('\n')
      var code = splitLines.slice(1, splitLines.length - 1).join('\n')
      result.code = code
      result.message = splitLines[splitLines.length - 1]
      result.format = true
      return result
    }

    // remove colon
    restOfMessage = restOfMessage.substring(1).trim()
    var whileParsing = 'while parsing file: '
    var whileParsingIdx = restOfMessage.indexOf(whileParsing)
    if (whileParsingIdx >= 0) {
      var beforeWhile = restOfMessage.substring(0, whileParsingIdx)
      lineNum = /\((\d+):(\d+)\)/.exec(beforeWhile.split('\n')[0])
      var messageStr = beforeWhile
      if (lineNum) {
        var line = parseInt(lineNum[1], 10)
        var col = parseInt(lineNum[2], 10)
        if (isFinite(line)) result.line = line
        if (isFinite(col)) result.column = col
        messageStr = messageStr.substring(0, lineNum.index)
      }
      result.message = messageStr.trim()
      splitLines = restOfMessage.split('\n')
      result.code = splitLines.slice(2).join('\n')
      result.format = true
    }

    return result
  }
1346889
function readFailureCallback(e) {
    if (this._readyState === FileReader.DONE) {
        return;
    }

    this._readyState = FileReader.DONE;
    this._result = null;
    this._error = new FileError(e);

    if (typeof this.onerror === "function") {
        this.onerror(new ProgressEvent("error", {target:this}));
    }

    if (typeof this.onloadend === "function") {
        this.onloadend(new ProgressEvent("loadend", {target:this}));
    }
}
1204552
function(err, data, response) {

				// call the 'response' callback, if provided using 'node' style callback pattern
				if (options.complete) {
					options.complete.call(model, err, data, response, options);
				}

				// trigger any event listeners for "complete"
				model.trigger('complete', err, data, response, options);
			}
25094
function tryParse(data) {
  var json;
  try {
    json = JSON.parse(data);
  } catch (ex) { debug('tryParse exception %s for data %s', ex, data); }

  return json || data;
}
557056
function haveResults(err, response, body) {
    var jsn;
    if (err) {
      callback(err);
      return;
    }
    //fs.writeFileSync('response.txt', JSON.stringify(response, null, '  '), 'utf8');
    if (response && response.statusCode !== 200) {
      callback('Resp Status: ' + response.statusCode);
      return;
    }
    try {
      jsn = JSON.parse(body);
    } catch(e) {
      callback('JSON Parse error:\n' + body);
      return;
    }
    if (!jsn.status || jsn.status !== 200) {
      callback('Status: ' + (jsn.status ? String(jsn.status) : '555') + ' ' + (jsn.message ? jsn.message : ''));
      return;
    }
    jsn.resultSetFiltered = jsn.resultSet.filter(function(itm) {
      return filter.indexOf(itm.tID) === -1;
    });
    callback(null, jsn, fname); // DONE - return results to caller
  }
628459
function _parse(content, options, callback) {

	if(typeof options == 'function') {

		callback     = options;
		options.test = false;

	}


	var on = outcome.error(callback),
	warnings,
	window;

	step(

		/**
		 * load it.
		 */

		function() {

			jsdom.env({
				html: content,
				scripts: [
			  		__dirname + "/jquery-1.5.js"
				],
				done: this
			});

		},


		/**
		 * set it.
		 */

		on.success(function(win) {


			window = win;
			_copyStyles(window);
			this();

		}),

		/**
		 * test it.
		 */

		on.success(function() {

			if(!options.test) {

				return this();

			}

			test(window, {}, this);

		}),

		/**
		 * clean it.
		 */

		on.success(function(warn) {

			warnings = warn;

			//strip stuff that cannot be processed
			window.$('script, link, style').remove();

            if (!options.comments) {
                //strip comments - sometimes gets rendered
                window.$('*').contents().each(function(node) {
                    if(this.nodeType == 8) {
                        window.$(this).remove();
                    }
                });
            }

			this();

		}),


		/**
		 * finish it.
		 */

		function() {

			callback(null, window.document.documentElement.innerHTML, warnings || []);

		}
	);


}
435541
function callback(err,other) {
			// check if the 'err' is boolean, if so then this is a 'exists' callback special case
			if (err && (typeof err !== 'boolean')) return reject(err);
			// convert arguments to proper array, ignoring error argument
			let args = Array.prototype.slice.call(arguments, 1);
			// if arguments length is one or more resolve arguments as array,
			// otherwise resolve the argument as is.
			return resolve(args.length < 2 ? args[0] : args);
		}
632879
function _handleErr (err, callback) {
  if (callback) {
    return callback(err);
  } else if (promisesExist) {
    return Promise.reject(err);
  } else {
    throw new Error(err);
  }
}