@iter-tools/set
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@iter-tools/set

Build Status codecov

A simple Set which is almost identical to the es6 Set builtin. In fact it is a transparent facade over an internal Set builtin instance. To understand why this is useful see rationale.

Package includes Typescript libdefs. Suitable for node or browser environments. Supports native es imports in node > 13.2.

Usage

const Set = require('@iter-tools/set'); // OR
import Set from '@iter-tools/set';

Until Typescript supports package exports you must enable esModuleInterop to use this module.

Rationale

@iter-tools/set adds two key pieces of functionality to the Set builtin:

First, the iter-tools Set class can be safely extended. While es6 permits the extending of builtin classes, such a practice tends to choke transpilers. This occurs because it is not legal for the Set builtin to be invoked as Set.call({}, values), as it would be in transpiled code.

Second, the builtin Set has a shortcoming: it lacks a Set.isSet() comparable to Array.isArray. While it is possible to detect an instance with instanceof, that operator has shortcomings surrounding realms. For more reading on realms and instanceof, I recommend this Stack Overflow question.

API

The basic API is that of the Set builtin.

In addition the following is supported:

Set.isSet(inst): returns true if inst was constructed by this library and false otherwise. Note that it will return true even if the version of the library is different. It will return false for instances constructed with the Set builtin.

Package Sidebar

Install

npm i @iter-tools/set

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

7.4 kB

Total Files

7

Last publish

Collaborators

  • conartist6