Created
January 17, 2018 09:46
-
-
Save jhsuZerion/8c120491830ff01c549f542f5de3ed2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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