scripts/generate-documentation.js
function buildReturnTables(res, name) {
  let tables = []

  if (Array.isArray(res)) {
    if (res.length && res[0]) {
      tables = buildReturnTables(res[0], `${name}[i]`)
    }
  } else {
    const keys = Object.keys(res).map(k => ({
      name: k,
      type: res[k].constructor.name
    })).sort((a, b) => a.name.localeCompare(b.name))

    tables.push({ name, keys })

    keys.filter(key => Array.isArray(res[key.name])).forEach((key) => {
      if (res[key.name].length) {
        tables = [...tables, ...buildReturnTables(
          res[key.name][0],
          `${name}.${key.name}[i]`
        )]
      }
    })
  }

  return tables
}
function buildReturnTables(res, name) {
  let tables = []

  if (Array.isArray(res)) {
    if (res.length && res[0]) {
      tables = buildReturnTables(res[0], `${name}[i]`)
    }
  } else {
    const keys = Object.keys(res).map(k => ({
      name: k,
      type: res[k].constructor.name
    })).sort((a, b) => a.name.localeCompare(b.name))

    tables.push({ name, keys })

    keys.filter(key => Array.isArray(res[key.name])).forEach((key) => {
      if (res[key.name].length) {
        tables = [...tables, ...buildReturnTables(
          res[key.name][0],
          `${name}.${key.name}[i]`
        )]
      }
    })
  }

  return tables
}
function buildReturnTables ( res , name ) { let tables = [ ] if ( Array . isArray ( res ) ) { if ( res . length && res [ 0 ] ) { tables = buildReturnTables ( res [ 0 ] , ` ${ name } ` ) } } else { const keys = Object . keys ( res ) . map ( k => ( { name : k , type : res [ k ] . constructor . name } ) ) . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) tables . push ( { name , keys } ) keys . filter ( key => Array . isArray ( res [ key . name ] ) ) . forEach ( ( key ) => { if ( res [ key . name ] . length ) { tables = [ ... tables , ... buildReturnTables ( res [ key . name ] [ 0 ] , ` ${ name } ${ key . name } ` ) ] } } ) } return tables }
Recursive function which builds an array of data about the endpoint return value.
The information is then used to build Markdown tables.

@param {Object|Array} res The value returned from the API endpoint.
@param {String} name The name/header of the table to be built.
@return {Array} An array of information about the endpoint return value.
Recursive function which builds an array of data about the endpoint return value . The information is then used to build Markdown tables .