Created
March 23, 2012 08:50
-
-
Save musubu/2168555 to your computer and use it in GitHub Desktop.
normalize null value to 0 space for object's attribute
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
var async = require('async'); | |
function normalizeParamsAttributesNullValue (params, callback) { | |
async.forEachSeries(Object.keys(params), function(k, cb) { | |
if (params[k] === null) { | |
params[k] = ''; | |
} | |
cb(); | |
}, function() { | |
callback(params); | |
}) | |
} | |
var params = { | |
name: 'name' | |
, email: null | |
, uri: 'http://example.com/' | |
} | |
normalizeParamsAttributesNullValue(params, function(result) { | |
console.log(result); | |
// { name: 'name', email: '', uri: 'http://example.com/' } | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment