{"size": 664, "ext": "js", "max_stars_repo_path": "src/cmd/config/set.js", "max_stars_repo_name": "hazmatzo/js-filecoin-api-client", "max_stars_repo_stars_event_min_datetime": "2019-03-01T18:26:36.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-11T20:15:07.000Z", "max_issues_repo_path": "src/cmd/config/set.js", "max_issues_repo_name": "hazmatzo/js-filecoin-api-client", "max_issues_repo_issues_event_min_datetime": "2019-03-02T14:40:38.000Z", "max_issues_repo_issues_event_max_datetime": "2019-08-12T18:50:08.000Z", "max_forks_repo_path": "src/cmd/config/set.js", "max_forks_repo_name": "hazmatzo/js-filecoin-api-client", "max_forks_repo_forks_event_min_datetime": "2019-08-30T18:35:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T18:09:39.000Z"}
{"max_stars_count": 26, "max_issues_count": 55, "max_forks_count": 11, "avg_line_length": 27.6666666667, "max_line_length": 64, "alphanum_fraction": 0.6084337349}
const toUri = require('../../lib/multiaddr-to-uri')
const explain = require('explain-error')
const { ok } = require('../../lib/fetch')

module.exports = (fetch, config) => {
  return async (key, value, options) => {
    options = options || {}

    try {
      value = JSON.stringify(value)
    } catch (err) {
      throw explain(err, 'failed to stringify config value')
    }

    const qs = new URLSearchParams(options.qs)
    ;[key, value].forEach(arg => qs.append('arg', arg))

    const url = `${toUri(config.apiAddr)}/api/config?${qs}`
    const res = await ok(fetch(url, { signal: options.signal }))
    const data = await res.json()
    return data
  }
}
