Skip to content

Instantly share code, notes, and snippets.

@jhsuZerion
Created January 17, 2018 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhsuZerion/8c120491830ff01c549f542f5de3ed2a to your computer and use it in GitHub Desktop.
Save jhsuZerion/8c120491830ff01c549f542f5de3ed2a to your computer and use it in GitHub Desktop.
/**
* Parse the data from a Location Element and return the requested value
* @param {string} l stored string value from a Location Element
* @param {string} k name of the requested value
* @return {string} parsed value from the Location Element or empty string
*/
function parseLocation(l,k) {
if(typeof k === "undefined" || k.trim().length === 0) return "";
var location = {};
var arr = l.split("\n");
for(var i=0; i<arr.length; i++) {
var line = arr[i].split(":");
var key = line[0].toLowerCase();
if(key === "time") {
var value = line[1] + ":" + line[2] + ":" + line[3];
} else {
var value = line[1];
}
location[key] = value;
}
if(location.hasOwnProperty(k.toLowerCase())) {
return location[k.toLowerCase()];
} else {
return "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment