Sha256: 7d8c3554fd240d10fc1f9097b64e0175d23f42e0869c913888c4873441a81525

Contents?: true

Size: 1.67 KB

Versions: 9

Compression:

Stored size: 1.67 KB

Contents

(function() {
  var urlRegex = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;

  function isCurie(string) {
    return string.split(':').length > 1;
  };

  var HAL = {
    Models: {},
    Views: {},
    Http: {},
    currentDocument: {},
    jsonIndent: 2,
    isUrl: function(str) {
      return str.match(urlRegex) || isCurie(str);
    },
    truncateIfUrl: function(str) {
      var replaceRegex = /(http|https):\/\/([^\/]*)\//;
        return str.replace(replaceRegex, '.../');
    },
    buildUrl: function(rel) {
      if (!rel.match(urlRegex) && isCurie(rel) && HAL.currentDocument._links.curies) {
        var parts = rel.split(':');
        var curies = HAL.currentDocument._links.curies;
        for (var i=0; i<curies.length; i++) {
          if (curies[i].name == parts[0]) {
            var tmpl = uritemplate(curies[i].href);
            return tmpl.expand({ rel: parts[1] });
          }
        }
      }
      else if (!rel.match(urlRegex) && isCurie(rel) && HAL.currentDocument._links.curie) {
        // Backward compatibility with <04 version of spec.
        var tmpl = uritemplate(HAL.currentDocument._links.curie.href);
        return tmpl.expand({ rel: rel.split(':')[1] });
      }
      else {
        return rel;
      }
    },
    parseHeaders: function(string) {
      var header_lines = string.split("\n");
      var headers = {};
      _.each(header_lines, function(line) {
        var parts = line.split(':');
        if (parts.length > 1) {
          var name = parts.shift().trim();
          var value = parts.join(':').trim();
          headers[name] = value;
        }
      });
      return headers;
    },
  };

  window.HAL = HAL;
})();

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pact_broker-1.3.2.rc1 vendor/hal-browser/js/hal.js
pact_broker-1.3.1 vendor/hal-browser/js/hal.js
pact_broker-1.3.0 vendor/hal-browser/js/hal.js
pact_broker-1.2.0 vendor/hal-browser/js/hal.js
pact_broker-1.1.0 vendor/hal-browser/js/hal.js
pact_broker-1.0.0 vendor/hal-browser/js/hal.js
pact_broker-1.0.0.alpha3 vendor/hal-browser/js/hal.js
pact_broker-1.0.0.alpha2 vendor/hal-browser/js/hal.js
pact_broker-1.0.0.alpha1 vendor/hal-browser/js/hal.js