Created
May 12, 2021 08:54
-
-
Save ilikerobots/bee50a97d320d1138e6c63dea3174378 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const datasetDatatypePostfix = "Datatype"; | |
const convertDatasetToTyped = (dataset) => { | |
const keys = Object.keys(dataset); | |
keys.forEach(function(key){ | |
let datatypeKey = key + datasetDatatypePostfix; | |
if (datatypeKey in dataset) { | |
let datatype = dataset[datatypeKey]; | |
switch (datatype) { | |
case "String": //already string, do nothing | |
break; | |
case "Number": | |
dataset[key] = Number(dataset[key]) | |
break; | |
case "Boolean": | |
dataset[key] = dataset[key] === 'true' | |
break; | |
// TODO: Add additional datatype conversions | |
default: //do nothing | |
} | |
delete dataset[datatypeKey]; | |
} | |
}); | |
return dataset; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment