Last active
November 11, 2020 10:38
-
-
Save daverickdunn/b7fa2d0c373b081ce812a253c4269fe7 to your computer and use it in GitHub Desktop.
Replace ECMA Sets with DocumentClient Sets
This file contains hidden or 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 { DocumentClient } from 'aws-sdk/clients/dynamodb'; | |
function ReplaceSets(item: any) { | |
const keys = Object.keys(item); | |
for (let index = 0; index < keys.length; index++) { | |
const element = item[keys[index]]; | |
if (typeof element === 'object' && element instanceof Set) { | |
if (element.size === 0){ | |
item[keys[index]] = null; | |
} else { | |
item[keys[index]] = DocumentClient.prototype.createSet([...element]); | |
} | |
continue; | |
} | |
if (element.constructor == Object || Array.isArray(element)) { | |
item[keys[index]] = ReplaceSets(element); | |
continue; | |
} | |
} | |
return item; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment