init: initial commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
function camelName(key) { return key.replace(/_([a-z0-9])/g, function(_, c) { return c.toUpperCase(); }); }
|
||||
function snakeName(key) { return key.replace(/[A-Z]/g, function(c) { return '_' + c.toLowerCase(); }); }
|
||||
function mapKeys(value, name) {
|
||||
if (Array.isArray(value)) return value.map(function(v) { return mapKeys(v, name); });
|
||||
if (value && typeof value === 'object') { var out = {}; Object.keys(value).forEach(function(key) { out[name(key)] = mapKeys(value[key], name); }); return out; }
|
||||
return value;
|
||||
}
|
||||
module.exports = { camelName, toWire: function(v) { return mapKeys(v, camelName); }, fromWire: function(v) { return mapKeys(v, snakeName); } };
|
||||
Reference in New Issue
Block a user