kubo-rpc-client
Version:
A client library for the Kubo RPC API
28 lines • 723 B
JavaScript
/**
* Convert object properties to camel case.
* NOT recursive!
* e.g.
* AgentVersion => agentVersion
* ID => id
*/
export function objectToCamel(obj) {
if (obj == null) {
return obj;
}
const caps = /^[A-Z]+$/;
const output = {};
// @ts-expect-error type may be unrelated
return Object.keys(obj).reduce((camelObj, k) => {
if (caps.test(k)) { // all caps
camelObj[k.toLowerCase()] = obj[k];
}
else if (caps.test(k[0])) { // pascal
camelObj[k[0].toLowerCase() + k.slice(1)] = obj[k];
}
else {
camelObj[k] = obj[k];
}
return camelObj;
}, output);
}
//# sourceMappingURL=object-to-camel.js.map