const git = require('git-rev');

let gitRevision;

exports.init = function () {
  return new Promise((resolve, reject) => {
    git.long((rev) => {
      gitRevision = rev;
      resolve(rev);
    });
  });
};

exports.setGitRevision = function (rev) {
  gitRevision = rev;
};

exports.getGitRevision = function () {
  return gitRevision;
};

exports.staticLink = function (resource) {
  if (resource.charAt(0) != "/") {
    resource = "/" + resource;
  }
  if (resource.startsWith("/static")) {
    throw new Error("staticLink URL should not start with /static: " + resource);
  }
  return "/static" + resource + "?rev=" + gitRevision;
};

exports.staticLinkWithHost = function (req, resource) {
  return req.protocol + "://" + req.headers.host + exports.staticLink(resource);
};

exports.imageLink = function (urlBase, resource) {
  if (resource.charAt(0) != "/") {
    resource = "/" + resource;
  }
  if (resource.startsWith("/images")) {
    throw new Error("imageLink URL should not start with /images: " + resource);
  }
  return urlBase + "/images" + resource;
}

@@ -377,32 +377,34 @@
 source) %7B%0A  if (
+! 
 resource.charAt(
@@ -396,33 +396,32 @@
 esource.
-charAt(0) != 
+startsWith(
 %22/%22)
+)
  %7B%0A    r
@@ -829,24 +829,26 @@
 ce) %7B%0A  if (
+! 
 resource.cha
@@ -848,25 +848,24 @@
 rce.
-charAt(0) != 
+startsWith(
 %22/%22)
+)
  %7B%0A 

Use startsWith