Skip to content

Instantly share code, notes, and snippets.

@lgandecki
Created December 30, 2020 07:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lgandecki/e7806462ce7c3d0d47ce65d44c5aa43d to your computer and use it in GitHub Desktop.
Dynamo SDK to CDK definition
import _ from "lodash";
function deCapitalizeFirstLetter(string: string) {
return string.charAt(0).toLowerCase() + string.slice(1);
}
function replaceKeysDeep(obj: object | unknown[]) {
// @ts-ignore
return _.transform(obj, function (
result: { [key: string]: unknown },
value: string | object,
key: string
) {
const currentKey = deCapitalizeFirstLetter(key);
if (_.isArray(value)) {
result[currentKey] = (value as any[]).map((v: any[]) =>
replaceKeysDeep(v)
);
} else if (_.isObject(value)) {
result[currentKey] = replaceKeysDeep(value as object);
} else if (currentKey !== "streamEnabled") {
result[currentKey] = value;
}
});
}
export const dynamoSdkToCdk = (sdkVersion: object) =>
replaceKeysDeep(sdkVersion);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment