UNPKG

tastypie

Version:

Tastypie is a webservice API framework for Node.js based on Django's Tastypie Framework. It provides a convenient, yet powerful and highly customizable, abstraction for creating REST-style interfaces

30 lines (24 loc) 687 B
var UNDEF; /** * Parses string and convert it into a native value. */ function typecast(val) { var r; if ( val === null || val === 'null' ) { r = null; } else if ( val === 'true' ) { r = true; } else if ( val === 'false' ) { r = false; } else if ( val === UNDEF || val === 'undefined' ) { r = UNDEF; } else if ( val === '' || isNaN(val) ) { //isNaN('') returns false r = val; } else { //parseFloat(null || '') returns NaN r = parseFloat(val); } return r; } module.exports = typecast;