dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
18 lines (17 loc) • 600 B
JavaScript
const JSONSerializer = (value) => JSON.stringify(value, (_, val) => (typeof val === 'bigint' ? val.toString() : val));
export class Deduper {
constructor({ serializer = JSONSerializer } = {}) {
this.values = [];
this.serializedValues = new Set();
this.serializer = serializer;
}
push(value) {
const serializedValue = this.serializer(value);
const hit = this.serializedValues.has(serializedValue);
if (!hit) {
this.values.push(value);
this.serializedValues.add(serializedValue);
}
return hit;
}
}