@shgysk8zer0/polyfills 0.3.13 → 0.4.0

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/weakMap.js CHANGED
@@ -1,28 +1,24 @@
1
- (function() {
2
- 'use strict';
1
+ if (! (WeakMap.prototype.emplace instanceof Function)) {
2
+ WeakMap.prototype.emplace = function emplace(key, { insert, update } = {}) {
3
+ const has = this.has(key);
3
4
 
4
- if (! (WeakMap.prototype.emplace instanceof Function)) {
5
- WeakMap.prototype.emplace = function emplace(key, { insert, update } = {}) {
6
- const has = this.has(key);
5
+ if (has && update instanceof Function) {
6
+ const existing = this.get(key);
7
+ const value = update.call(this, existing, key, this);
7
8
 
8
- if (has && update instanceof Function) {
9
- const existing = this.get(key);
10
- const value = update.call(this, existing, key, this);
11
-
12
- if (value !== existing) {
13
- this.set(key, existing);
14
- }
15
-
16
- return value;
17
- } else if (has) {
18
- return this.get(key);
19
- } else if (insert instanceof Function) {
20
- const value = insert.call(this, key, this);
21
- this.set(key, value);
22
- return value;
23
- } else {
24
- throw new Error('Key is not found and no `insert()` given');
9
+ if (value !== existing) {
10
+ this.set(key, existing);
25
11
  }
26
- };
27
- }
28
- })();
12
+
13
+ return value;
14
+ } else if (has) {
15
+ return this.get(key);
16
+ } else if (insert instanceof Function) {
17
+ const value = insert.call(this, key, this);
18
+ this.set(key, value);
19
+ return value;
20
+ } else {
21
+ throw new Error('Key is not found and no `insert()` given');
22
+ }
23
+ };
24
+ }