@nova-odm/auto-marshaller
Version:
A data marshaller that converts JavaScript types into Amazon DynamoDB AttributeValues
106 lines (105 loc) • 3.47 kB
JavaScript
;
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectSet = void 0;
var tslib_1 = require("tslib");
var ObjectSet = /** @class */ (function () {
/**
* Creates a new ObjectSet and optionally seeds it with values.
*
* @param iterable An optional iterable of values to add to the set.
*/
function ObjectSet(iterable) {
var e_1, _b;
/**
* Returns the string literal 'Set' for use by Object.prototype.toString.
* This allows for identifying Sets without checking constructor identity.
*/
this[_a] = 'Set';
this._values = [];
if (iterable) {
try {
for (var iterable_1 = tslib_1.__values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
var item = iterable_1_1.value;
this.add(item);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (iterable_1_1 && !iterable_1_1.done && (_b = iterable_1.return)) _b.call(iterable_1);
}
finally { if (e_1) throw e_1.error; }
}
}
}
/**
* Add a value to the set. If the value is already contained in the set, it
* will not be added a second time.
*
* @param value The value to add
*/
ObjectSet.prototype.add = function (value) {
if (!this.has(value)) {
this._values.push(value);
}
return this;
};
/**
* Remove all values from the set.
*/
ObjectSet.prototype.clear = function () {
this._values = [];
};
/**
* Returns an iterable two-member tuples for each item in the set, where
* the item is provided twice.
*
* Part of the ES2015 Set specification for compatibility with Map objects.
*/
ObjectSet.prototype.entries = function () {
return this._values.map(function (value) { return [value, value]; })[Symbol.iterator]();
};
/**
* Invokes a callback once for each member of the set.
*
* @param callback The function to invoke with each set member
* @param thisArg The `this` context on which to invoke the callback
*/
ObjectSet.prototype.forEach = function (callback, thisArg) {
var _this = this;
this._values.forEach(function (value, index, array) {
callback.call(thisArg, value, value, _this);
}, thisArg);
};
/**
* Returns an IterableIterator of each member of the set.
*/
ObjectSet.prototype.keys = function () {
return this[Symbol.iterator]();
};
Object.defineProperty(ObjectSet.prototype, "size", {
/**
* Returns the number of members in the set.
*/
get: function () {
return this._values.length;
},
enumerable: false,
configurable: true
});
/**
* Returns an IterableIterator of each member of the set.
*/
ObjectSet.prototype.values = function () {
return this[Symbol.iterator]();
};
/**
* Returns an IterableIterator of each member of the set.
*/
ObjectSet.prototype[(_a = Symbol.toStringTag, Symbol.iterator)] = function () {
return this._values[Symbol.iterator]();
};
return ObjectSet;
}());
exports.ObjectSet = ObjectSet;