Skip to content

Instantly share code, notes, and snippets.

@timwis
Last active November 12, 2015 12:26
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 timwis/cb75ab6d780355ed499f to your computer and use it in GitHub Desktop.
Save timwis/cb75ab6d780355ed499f to your computer and use it in GitHub Desktop.
var detectType = function(sample) {
if(moment(sample, moment.ISO_8601, true).isValid()) {
return 'datetime'
} else if(moment(sample, 'YYYY-MM-DD', true).isValid()) {
return 'date'
} else if(moment(sample, 'X', true).isValid()) {
return 'timestamp'
} else if( ! isNaN(sample) && sample.indexOf('.') !== -1) {
return 'float'
} else if( ! isNaN(sample)) {
return 'integer'
} else {
console.log(sample, Number(sample))
return 'string'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment