Created
December 30, 2020 07:56
-
-
Save lgandecki/e7806462ce7c3d0d47ce65d44c5aa43d to your computer and use it in GitHub Desktop.
Dynamo SDK to CDK definition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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