# cute-set

> A minimalistic es6 implementation of set

Latest version **2.0.1** (published 2021-05-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install cute-set
pnpm add cute-set
yarn add cute-set
bun add cute-set
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2021-05-23 |
| First published | 2018-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 21 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | KONSTANTIN Y RYBAKOV |
| Maintainers | viocost |
| Keywords | set, cute-set, subset, union, intersection, complement, combinations, permutations, power |

## Links

- npm: https://www.npmjs.com/package/cute-set
- Repository: https://github.com/viocost/SSet
- Homepage: https://github.com/viocost/SSet#readme
- Issues: https://github.com/viocost/SSet/issues
- npm.io page: https://npm.io/package/cute-set

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2021-05-23
- 1.0.2 ([set]) — 2018-08-23
- 2.0.0 — 2021-05-23
- 1.0.11 — 2020-09-23
- 1.0.10 — 2020-09-23
- 1.0.9 — 2020-05-22
- 1.0.8 — 2018-08-31
- 1.0.7 — 2018-08-31
- 1.0.6 — 2018-08-24
- 1.0.5 — 2018-08-24
- 1.0.4 — 2018-08-24
- 1.0.3 — 2018-08-23
- 1.0.1 — 2018-08-23
- 1.0.0 — 2018-08-23

## README

# CuteSet 
![Build badge](https://travis-ci.com/viocost/cute-set.svg?branch=master) [![codecov](https://codecov.io/gh/viocost/cute-set/branch/master/graph/badge.svg?token=SQAJ89EQK9)](https://codecov.io/gh/viocost/cute-set)

This is minimalistic es6 implementation of set and its basic operations, based on native javascript Set.

### Version 1.0.11 changes
- Added filter map reduce functionality, works the same way as array.
- length and size are no longer functions, so instead of doing `mySet.length()`
  do `mySet.length`

### Installation
```
npm i --save cute-set
```

### API

Require CuteSet library in your project:

```
//Node.js
const CuteSet = require("cute-set");

```
___

#### CuteSet is iterable
So this code will be perfectly valid:
```
  let mySet = new CuteSet([1, 2, 3, 4, 5]);
  for (let val of mySet){
    process(val);
  }
```
or

```
  let mySet = new CuteSet([1, 2, 3, 4, 5]);
  mySet.forEach((val, i, arr)=>{
    process(val);
  })
```

In the last example above **val** is the same as **i**, just like in native JS set, arr points to this CuteSet instance. Note, there is no acces by index, so mySet[0] will be undefined.

---


To create new instance of CuteSet you can use **constructor**  or static method **CuteSet.FromString()**
#### constructor(input)
```
  let mySet = new CuteSet(input)
```
V.2 Changes
Input can be anything:
**Single object, number or string** new CuteSet instance with that object returned
**Array** new CuteSet instance with all elements of the array returned (duplicates obviously removed)
**CuteSet instance** copy of CuteSet instance with be returned.


#### *static* fromString(input, delimiter = " ", parseNumbers = false)
Parses passed string and creates CuteSet instance.
Delimiter is optional and by default it is one empty space.
parseNumbers - for each element in string parseFloat will be applied.
See tests for examples

---
#### complement(x) +
Given "universe" *x* returns *self* complement *x*
or basically *x* difference *self*

#### subsetGenerator()
Returns a subset generator. 
Call generator.next() to get next subset.
Generator will deplete once all subsets are yielded.
No length limit.

#### permutationGenerator()
Returns permutation generator.
Call generator.next() to get next permutation.
Generator will deplete once all permutations are yielded.
No length limit.

#### powerSet()
Generates and returns a *set* of all subsets of itself.
Length of self is limited by 21 elements

#### permutations()
Generates and returns a *set* of all permutations of itself
Length of self is limited by 9 elements


#### sort(fn)
Sorts internal order of elements in javascript Array.prototype.sort() fashion. It can be used with function expressions (and closures). For reference see [official MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort).


#### union(x) +
Performs union operation on given set with set *x*

#### join(x) +
Alias of union

#### difference(x) +
Returns difference of given set with set *x*
  ```
    const res = set1.difference(set2)
  ```
#### minus(x)  +
Alias of difference

#### intersection(x)  +
Returns intersection of given set with set *x*

#### symmetricDifference(x) +
Returns symmetric difference of given set with set *x*

#### equal(x)  +
Returns true or false - whether given set is equal to set *x*

#### subsetOf(x)  +
Returns true or false - whether given set is subset of set *x*

#### has(x)   
Returns true or false - whether given set contains element x

#### length()   
returns set length

#### empty()   
returns true or false - whether given set is empty

#### add(x)   
adds given x element to this set

#### remove(x)   
removes element x from this set
returns true if element was deleted, or false if element was not found

#### delete(x)   
alias of remove

#### toString(delimiter = " ")   
**returns** string representation of a given set;
Delimiter is optional. By default it is 1 space;


#### print(delimiter = " ")   
**prints** string representation of a given set;
Delimiter is optional. By default it is 1 space;

#### toArray()   
turns set into native Array and returns it

---

*Methods marked with **+** may take any input as CuteSet constructor. 
Passed input will be implicitly turned into a CuteSet instance before processing.

```
let a = new CuteSet([1, 2, 3]).union([2, 3, 4, 5]); // Results in {1, 2, 3, 4, 5}

let b = a.intersection([3, 4, 8, 9, 12]); // Results in {3, 4}
let b = a.intersection(3); // Results in {3}
let b = a.minus(3); // Results in {1, 2, 4, 5}

b.subsetOf([1, 3, 4, 5, 67]) // true

```

---
_Source: https://npm.io/package/cute-set · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
