Skip to content

Instantly share code, notes, and snippets.

@musubu
Created March 23, 2012 08:50
Show Gist options
  • Save musubu/2168555 to your computer and use it in GitHub Desktop.
Save musubu/2168555 to your computer and use it in GitHub Desktop.
normalize null value to 0 space for object's attribute
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