object-set-type

A Set implementation which supports Objects.

Usage no npm install needed!

<script type="module">
  import objectSetType from 'https://cdn.skypack.dev/object-set-type';
</script>

README

object-set-type

Downloads Version@npm Version@git

A Set implementation which supports Objects and custom conditions.

Usage

'use strict';

const ObjectSet = require('object-set-type');

const set = new ObjectSet();
set.add(1);
set.add('Hello');
set.add({
    a: 1
});
set.add({
    a: 1
});

console.log(set.size); // 3
Array.from(set); // 1, "Hello", {a: 1}

Custom uniqueness logic

The equals(a,b) method of the instance is responsible for comparing two items, and the set logic is based on this. This method can be overwritten to support custom uniqueness logic, e.g. handle objects, but compare only certain properties.