mild-set 1.1.0 → 1.1.1

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/dist/index.js CHANGED
@@ -1,5 +1,9 @@
1
1
  /* IMPORT */
2
- import { isWeakReferrable } from './utils.js';
2
+ import { isWeakReferable } from 'is';
3
+ /* HELPERS */
4
+ const isWeakable = (value) => {
5
+ return isWeakReferable(value);
6
+ };
3
7
  /* MAIN */
4
8
  class MildSet {
5
9
  /* VARIABLES */
@@ -32,7 +36,7 @@ class MildSet {
32
36
  if (!hasValue) {
33
37
  this.#size += 1;
34
38
  }
35
- if (isWeakReferrable(value)) {
39
+ if (isWeakable(value)) {
36
40
  this.#weak.add(value);
37
41
  if (!hasValue) {
38
42
  const token = {};
@@ -50,7 +54,7 @@ class MildSet {
50
54
  if (!hasValue)
51
55
  return false;
52
56
  this.#size -= 1;
53
- if (isWeakReferrable(value)) {
57
+ if (isWeakable(value)) {
54
58
  const token = this.#finalizationTokens.get(value);
55
59
  if (token) {
56
60
  this.#finalizationRegistry.unregister(token);
@@ -63,7 +67,7 @@ class MildSet {
63
67
  }
64
68
  }
65
69
  has(value) {
66
- if (isWeakReferrable(value)) {
70
+ if (isWeakable(value)) {
67
71
  return this.#weak.has(value);
68
72
  }
69
73
  else {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mild-set",
3
3
  "repository": "github:fabiospampinato/mild-set",
4
4
  "description": "A WeakSet that supports any value, it holds strong references to primitives, and weak references to objects.",
5
- "version": "1.1.0",
5
+ "version": "1.1.1",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "exports": "./dist/index.js",
@@ -19,9 +19,12 @@
19
19
  "strong",
20
20
  "set"
21
21
  ],
22
+ "dependencies": {
23
+ "is": "npm:@fabiospampinato/is@^2.5.0"
24
+ },
22
25
  "devDependencies": {
23
- "fava": "^0.1.2",
24
- "tsex": "^2.1.0",
26
+ "fava": "^0.2.0",
27
+ "tsex": "^2.2.0",
25
28
  "typescript": "^4.9.5"
26
29
  }
27
30
  }
package/src/index.ts CHANGED
@@ -1,7 +1,13 @@
1
1
 
2
2
  /* IMPORT */
3
3
 
4
- import {isWeakReferrable} from './utils';
4
+ import {isWeakReferable} from 'is';
5
+
6
+ /* HELPERS */
7
+
8
+ const isWeakable = ( value: unknown ): value is object => { //FIXME: Overridden type guard for convenience, delete this once TS updates its types
9
+ return isWeakReferable ( value );
10
+ };
5
11
 
6
12
  /* MAIN */
7
13
 
@@ -52,7 +58,7 @@ class MildSet<V> {
52
58
 
53
59
  }
54
60
 
55
- if ( isWeakReferrable ( value ) ) {
61
+ if ( isWeakable ( value ) ) {
56
62
 
57
63
  this.#weak.add ( value );
58
64
 
@@ -83,7 +89,7 @@ class MildSet<V> {
83
89
 
84
90
  this.#size -= 1;
85
91
 
86
- if ( isWeakReferrable ( value ) ) {
92
+ if ( isWeakable ( value ) ) {
87
93
 
88
94
  const token = this.#finalizationTokens.get ( value );
89
95
 
@@ -106,7 +112,7 @@ class MildSet<V> {
106
112
 
107
113
  has ( value: V ): boolean {
108
114
 
109
- if ( isWeakReferrable ( value ) ) {
115
+ if ( isWeakable ( value ) ) {
110
116
 
111
117
  return this.#weak.has ( value );
112
118
 
@@ -1,2 +0,0 @@
1
- declare const SUPPORTS_SYMBOLS_AS_WEAKSET_KEYS: boolean;
2
- export { SUPPORTS_SYMBOLS_AS_WEAKSET_KEYS };
package/dist/constants.js DELETED
@@ -1,12 +0,0 @@
1
- /* MAIN */
2
- const SUPPORTS_SYMBOLS_AS_WEAKSET_KEYS = (() => {
3
- try {
4
- new WeakSet().add(Symbol());
5
- return true;
6
- }
7
- catch {
8
- return false;
9
- }
10
- })();
11
- /* EXPORT */
12
- export { SUPPORTS_SYMBOLS_AS_WEAKSET_KEYS };
package/dist/utils.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const isWeakReferrable: (value: unknown) => value is object;
2
- export { isWeakReferrable };
package/dist/utils.js DELETED
@@ -1,11 +0,0 @@
1
- /* IMPORT */
2
- import { SUPPORTS_SYMBOLS_AS_WEAKSET_KEYS } from './constants.js';
3
- /* IMPORT */
4
- const isWeakReferrable = (value) => {
5
- if (value === null)
6
- return false;
7
- const type = typeof value;
8
- return type === 'object' || type === 'function' || (SUPPORTS_SYMBOLS_AS_WEAKSET_KEYS && type === 'symbol');
9
- };
10
- /* EXPORT */
11
- export { isWeakReferrable };
package/src/constants.ts DELETED
@@ -1,22 +0,0 @@
1
-
2
- /* MAIN */
3
-
4
- const SUPPORTS_SYMBOLS_AS_WEAKSET_KEYS = ((): boolean => {
5
-
6
- try {
7
-
8
- new WeakSet ().add ( Symbol () );
9
-
10
- return true;
11
-
12
- } catch {
13
-
14
- return false;
15
-
16
- }
17
-
18
- })();
19
-
20
- /* EXPORT */
21
-
22
- export {SUPPORTS_SYMBOLS_AS_WEAKSET_KEYS};
package/src/utils.ts DELETED
@@ -1,20 +0,0 @@
1
-
2
- /* IMPORT */
3
-
4
- import {SUPPORTS_SYMBOLS_AS_WEAKSET_KEYS} from './constants';
5
-
6
- /* IMPORT */
7
-
8
- const isWeakReferrable = ( value: unknown ): value is object => {
9
-
10
- if ( value === null ) return false;
11
-
12
- const type = typeof value;
13
-
14
- return type === 'object' || type === 'function' || ( SUPPORTS_SYMBOLS_AS_WEAKSET_KEYS && type === 'symbol' );
15
-
16
- };
17
-
18
- /* EXPORT */
19
-
20
- export {isWeakReferrable};