change snake_case to camelCase in responses from api.submit and api.getServerInfo and add schema for it

This commit is contained in:
Ivan Tivonenko
2015-07-30 02:24:36 +03:00
parent c6f450842e
commit 03640efef5
9 changed files with 109 additions and 23 deletions

View File

@@ -1,5 +1,6 @@
/* @flow */
'use strict';
const _ = require('lodash');
const BigNumber = require('bignumber.js');
const core = require('../../core');
const errors = require('./errors');
@@ -68,6 +69,22 @@ function convertExceptions<T>(f: () => T): () => T {
};
}
const FINDSNAKE = /([a-zA-Z]_[a-zA-Z])/g;
function convertKeysFromSnakeCaseToCamelCase(obj: any): any {
if (typeof obj === 'object') {
let newKey;
return _.reduce(obj, (result, value, key) => {
newKey = key;
if (FINDSNAKE.test(key)) {
newKey = key.replace(FINDSNAKE, r => r[0] + r[2].toUpperCase());
}
result[newKey] = convertKeysFromSnakeCaseToCamelCase(value);
return result;
}, {});
}
return obj;
}
module.exports = {
core,
dropsToXrp,
@@ -75,5 +92,6 @@ module.exports = {
toRippledAmount,
wrapCatch,
composeAsync,
convertExceptions
convertExceptions,
convertKeysFromSnakeCaseToCamelCase
};