How to use the urijs.encodeQuery function in urijs

To help you get started, we’ve selected a few urijs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github APIs-guru / openapi-directory / scripts / deploy_badges.js View on Github external
function saveShield(subject, status, color, icon) {
  function escape(obj) {
    return obj.toString().replace(/_/g, '__').replace(/-/g, '--').replace(/ /g, '_');
  }

  subject = escape(subject);
  status = escape(status);

  var url = new URI(`https://img.shields.io/badge/${subject}-${status}-${color}.svg`);
  if (icon) {
    var base64 = URI.encodeQuery(icon.toString('base64'));
    url.addQuery('logo', 'data:image/png;base64,' + base64);
  }

  return makeRequest.getRaw(url.href(), { retries: 10 })
    .then(data => {
      util.saveFile(`deploy/badges/${subject.toLowerCase()}.svg`, data);
    });
}