All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dependencies.halbrowser.js.hal.js Maven / Gradle / Ivy

The newest version!
(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);
    },
    isFollowableHeader: function(headerName) {
      return headerName === 'Location' || headerName === 'Content-Location';
    },
    truncateIfUrl: function(str) {
      var replaceRegex = /(http|https):\/\/([^\/]*)\//;
        return str.replace(replaceRegex, '.../');
    },
    normalizeUrl: function(rel) {
       var cur = location.hash.slice(1);
       var uri = new URI(rel)
       var norm = uri.absoluteTo(cur);

       return norm
	},
    buildUrl: function(rel) {
      if (!HAL.currentDocument._links) {
        return 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 1) {
          var name = parts.shift().trim();
          var value = parts.join(':').trim();
          headers[name] = value;
        }
      });
      return headers;
    },
    customPostForm: undefined
  };

  window.HAL = HAL;
})();




© 2015 - 2024 Weber Informatics LLC | Privacy Policy