Skip to content

Instantly share code, notes, and snippets.

@daverickdunn
Last active November 11, 2020 10:38
Show Gist options
  • Save daverickdunn/b7fa2d0c373b081ce812a253c4269fe7 to your computer and use it in GitHub Desktop.
Save daverickdunn/b7fa2d0c373b081ce812a253c4269fe7 to your computer and use it in GitHub Desktop.
Replace ECMA Sets with DocumentClient Sets
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