@sepiariver/unique-set 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # @sepiariver/unique-set
2
- Extends the add method on the native JavaScript Set object to compare using fast-deep-equal
2
+
3
+ Extends the `add` method on the native JavaScript Set object to compare using [fast-deep-equal](https://www.npmjs.com/package/fast-deep-equal)
4
+
5
+ The extended method iterates through the elements of the Set until equality is found. If no elements match, the entire Set would have been iterated to determine so. For a very large Set, there is probably a better way to achieve what you're trying to do, otherwise UniqueSet can be very convenient.
3
6
 
4
7
  ## Installation
5
8
 
@@ -33,14 +36,9 @@ const data = [
33
36
  [1, 2, 3],
34
37
  ];
35
38
 
36
- let common = new Set();
37
- data.forEach((el) => {
38
- common.add(el);
39
- });
40
- console.log(common);
41
-
42
39
  let unique = new UniqueSet();
43
40
  data.forEach((el) => {
44
41
  unique.add(el);
45
42
  });
43
+ console.log(unique.size); // 6 instead of 8 with Set
46
44
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sepiariver/unique-set",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Extends the add method on the native JavaScript Set object to compare using fast-deep-equal",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,71 +0,0 @@
1
- import UniqueSet from "../dist";
2
-
3
- describe("UniqueSet", () => {
4
- it("adds unique objects", () => {
5
- const data = [
6
- "string",
7
- "another string",
8
- "string",
9
- 1,
10
- 2,
11
- 1,
12
- {
13
- foo: "bar",
14
- bar: "baz",
15
- baz: "lurman",
16
- },
17
- {
18
- bar: "baz",
19
- baz: "lurman",
20
- foo: "bar",
21
- },
22
- [1, 2, 3],
23
- [1, 2, 3],
24
- ];
25
-
26
- const expected = [
27
- "string",
28
- "another string",
29
- 1,
30
- 2,
31
- {
32
- foo: "bar",
33
- bar: "baz",
34
- baz: "lurman",
35
- },
36
- [1, 2, 3],
37
- ];
38
-
39
- let unique = new UniqueSet();
40
- data.forEach((el) => {
41
- unique.add(el);
42
- });
43
- expect(expected).toEqual(Array.from(unique));
44
- expect(unique.size).toBe(6);
45
- });
46
-
47
- it("complies with MDN reference", () => {
48
- const mySet1 = new UniqueSet();
49
-
50
- mySet1.add(1); // Set [ 1 ]
51
- mySet1.add(5); // Set [ 1, 5 ]
52
- mySet1.add(5); // Set [ 1, 5 ]
53
- mySet1.add("some text"); // Set [ 1, 5, 'some text' ]
54
- const o = { a: 1, b: 2 };
55
- mySet1.add(o);
56
-
57
- mySet1.add({ a: 1, b: 2 }); // o is referencing a different object, we treat this differently
58
-
59
- expect(mySet1.has(1)).toBeTruthy();
60
- expect(mySet1.has(3)).toBeFalsy();
61
- expect(mySet1.has(5)).toBeTruthy();
62
- expect(mySet1.has(Math.sqrt(25))).toBeTruthy();
63
- expect(mySet1.has("Some Text".toLowerCase())).toBeTruthy();
64
- expect(mySet1.has(o)).toBeTruthy();
65
- expect(mySet1.size).toBe(4); // unique
66
-
67
- mySet1.delete(5); // removes 5 from the set
68
- expect(mySet1.has(5)).toBeFalsy();
69
- expect(mySet1.size).toBe(3);
70
- });
71
- });