assign-gingerly 0.0.19 → 0.0.21

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/assignGingerly.js CHANGED
@@ -1,21 +1,22 @@
1
1
  // Polyfill for Map.prototype.getOrInsert and WeakMap.prototype.getOrInsert
2
- if (typeof Map.prototype.getOrInsert !== 'function') {
3
- Map.prototype.getOrInsert = function(key, insert) {
4
- if (this.has(key)) return this.get(key);
5
- const value = insert();
6
- this.set(key, value);
7
- return value;
8
- };
2
+ if (typeof Map.prototype.getOrInsertComputed !== 'function') {
3
+ Map.prototype.getOrInsertComputed = function (key, insert) {
4
+ if (this.has(key))
5
+ return this.get(key);
6
+ const value = insert();
7
+ this.set(key, value);
8
+ return value;
9
+ };
9
10
  }
10
- if (typeof WeakMap.prototype.getOrInsert !== 'function') {
11
- WeakMap.prototype.getOrInsert = function(key, insert) {
12
- if (this.has(key)) return this.get(key);
13
- const value = insert();
14
- this.set(key, value);
15
- return value;
16
- };
11
+ if (typeof WeakMap.prototype.getOrInsertComputed !== 'function') {
12
+ WeakMap.prototype.getOrInsertComputed = function (key, insert) {
13
+ if (this.has(key))
14
+ return this.get(key);
15
+ const value = insert();
16
+ this.set(key, value);
17
+ return value;
18
+ };
17
19
  }
18
-
19
20
  /**
20
21
  * GUID for global instance map storage to ensure uniqueness across package versions
21
22
  */
@@ -35,20 +36,20 @@ export function getInstanceMap() {
35
36
  * Base registry class for managing enhancement configurations
36
37
  */
37
38
  export class EnhancementRegistry {
38
- items = [];
39
+ #items = [];
39
40
  push(items) {
40
41
  if (Array.isArray(items)) {
41
- this.items.push(...items);
42
+ this.#items.push(...items);
42
43
  }
43
44
  else {
44
- this.items.push(items);
45
+ this.#items.push(items);
45
46
  }
46
47
  }
47
48
  getItems() {
48
- return this.items;
49
+ return this.#items;
49
50
  }
50
51
  findBySymbol(symbol) {
51
- return this.items.find(item => {
52
+ return this.#items.find(item => {
52
53
  const symlinks = item.symlinks;
53
54
  if (!symlinks)
54
55
  return false;
@@ -61,7 +62,7 @@ export class EnhancementRegistry {
61
62
  });
62
63
  }
63
64
  findByEnhKey(enhKey) {
64
- return this.items.find(item => item.enhKey === enhKey);
65
+ return this.#items.find(item => item.enhKey === enhKey);
65
66
  }
66
67
  }
67
68
  /**
@@ -323,7 +324,7 @@ export function assignGingerly(target, source, options) {
323
324
  if (registryItem) {
324
325
  const instanceMap = getInstanceMap();
325
326
  // Get or initialize the instances map for this target
326
- const instances = instanceMap.getOrInsert(target, () => new Map());
327
+ const instances = instanceMap.getOrInsertComputed(target, () => new Map());
327
328
  // Check if instance already exists (keyed by registryItem)
328
329
  let instance = instances.get(registryItem);
329
330
  if (!instance) {
@@ -378,7 +379,7 @@ export function assignGingerly(target, source, options) {
378
379
  const registryItem = registry.findBySymbol(prop);
379
380
  if (registryItem) {
380
381
  const instanceMap = getInstanceMap();
381
- const instances = instanceMap.getOrInsert(target, () => new Map());
382
+ const instances = instanceMap.getOrInsertComputed(target, () => new Map());
382
383
  let instance = instances.get(registryItem);
383
384
  if (!instance) {
384
385
  const SpawnClass = registryItem.spawn;
package/assignGingerly.ts CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  import { EnhancementConfig } from "./types/assign-gingerly/types";
4
4
 
5
+ // Polyfill for Map.prototype.getOrInsert and WeakMap.prototype.getOrInsert
6
+ if (typeof Map.prototype.getOrInsertComputed !== 'function') {
7
+ Map.prototype.getOrInsertComputed = function(key, insert) {
8
+ if (this.has(key)) return this.get(key);
9
+ const value = insert();
10
+ this.set(key, value);
11
+ return value;
12
+ };
13
+ }
14
+ if (typeof WeakMap.prototype.getOrInsertComputed !== 'function') {
15
+ WeakMap.prototype.getOrInsertComputed = function(key, insert) {
16
+ if (this.has(key)) return this.get(key);
17
+ const value = insert();
18
+ this.set(key, value);
19
+ return value;
20
+ };
21
+ }
22
+
5
23
  /**
6
24
  * @deprecated Use EnhancementConfig instead
7
25
  */
@@ -35,22 +53,22 @@ export function getInstanceMap(): WeakMap<object, Map<EnhancementConfig, any>> {
35
53
  * Base registry class for managing enhancement configurations
36
54
  */
37
55
  export class EnhancementRegistry {
38
- private items: EnhancementConfig[] = [];
56
+ #items: EnhancementConfig[] = [];
39
57
 
40
58
  push(items: EnhancementConfig | EnhancementConfig[]): void {
41
59
  if (Array.isArray(items)) {
42
- this.items.push(...items);
60
+ this.#items.push(...items);
43
61
  } else {
44
- this.items.push(items);
62
+ this.#items.push(items);
45
63
  }
46
64
  }
47
65
 
48
66
  getItems(): EnhancementConfig[] {
49
- return this.items;
67
+ return this.#items;
50
68
  }
51
69
 
52
70
  findBySymbol(symbol: symbol | string): EnhancementConfig | undefined {
53
- return this.items.find(item => {
71
+ return this.#items.find(item => {
54
72
  const symlinks = item.symlinks;
55
73
  if (!symlinks) return false;
56
74
  return Object.keys(symlinks).some(key => {
@@ -63,7 +81,7 @@ export class EnhancementRegistry {
63
81
  }
64
82
 
65
83
  findByEnhKey(enhKey: string | symbol): EnhancementConfig | undefined {
66
- return this.items.find(item => item.enhKey === enhKey);
84
+ return this.#items.find(item => item.enhKey === enhKey);
67
85
  }
68
86
  }
69
87
 
@@ -350,7 +368,7 @@ export function assignGingerly(
350
368
  if (registryItem) {
351
369
  const instanceMap = getInstanceMap();
352
370
  // Get or initialize the instances map for this target
353
- const instances = instanceMap.getOrInsert(target, () => new Map());
371
+ const instances = instanceMap.getOrInsertComputed(target, () => new Map());
354
372
 
355
373
  // Check if instance already exists (keyed by registryItem)
356
374
  let instance = instances.get(registryItem);
@@ -415,7 +433,7 @@ export function assignGingerly(
415
433
  const registryItem = registry.findBySymbol(prop);
416
434
  if (registryItem) {
417
435
  const instanceMap = getInstanceMap();
418
- const instances = instanceMap.getOrInsert(target, () => new Map());
436
+ const instances = instanceMap.getOrInsertComputed(target, () => new Map());
419
437
  let instance = instances.get(registryItem);
420
438
 
421
439
  if (!instance) {
@@ -1,21 +1,3 @@
1
- // Polyfill for Map.prototype.getOrInsert and WeakMap.prototype.getOrInsert
2
- if (typeof Map.prototype.getOrInsert !== 'function') {
3
- Map.prototype.getOrInsert = function(key, insert) {
4
- if (this.has(key)) return this.get(key);
5
- const value = insert();
6
- this.set(key, value);
7
- return value;
8
- };
9
- }
10
- if (typeof WeakMap.prototype.getOrInsert !== 'function') {
11
- WeakMap.prototype.getOrInsert = function(key, insert) {
12
- if (this.has(key)) return this.get(key);
13
- const value = insert();
14
- this.set(key, value);
15
- return value;
16
- };
17
- }
18
-
19
1
  import assignGingerly, { EnhancementRegistry, getInstanceMap } from './assignGingerly.js';
20
2
  import { parseWithAttrs } from './parseWithAttrs.js';
21
3
  /**
@@ -84,7 +66,7 @@ class ElementEnhancementContainer {
84
66
  }
85
67
  // Get or create instance using the global instance map
86
68
  const instanceMap = getInstanceMap();
87
- const instances = instanceMap.getOrInsert(element, () => new Map());
69
+ const instances = instanceMap.getOrInsertComputed(element, () => new Map());
88
70
  let instance = instances.get(registryItem);
89
71
  if (!instance) {
90
72
  // Need to spawn
@@ -216,7 +198,7 @@ class ElementEnhancementContainer {
216
198
  const SpawnClass = registryItem.spawn;
217
199
  // Check the global instance map first
218
200
  const instanceMap = getInstanceMap();
219
- const instances = instanceMap.getOrInsert(element, () => new Map());
201
+ const instances = instanceMap.getOrInsertComputed(element, () => new Map());
220
202
  let instance = instances.get(registryItem);
221
203
  if (!instance) {
222
204
  // Need to spawn
@@ -271,7 +253,7 @@ if (typeof Element !== 'undefined') {
271
253
  const enhContainerWeakMap = new WeakMap();
272
254
  Object.defineProperty(Element.prototype, 'enh', {
273
255
  get: function () {
274
- return enhContainerWeakMap.getOrInsert(this, () => new ElementEnhancementContainer(this));
256
+ return enhContainerWeakMap.getOrInsertComputed(this, () => new ElementEnhancementContainer(this));
275
257
  },
276
258
  enumerable: true,
277
259
  configurable: true,
@@ -136,7 +136,7 @@ class ElementEnhancementContainer {
136
136
 
137
137
  // Get or create instance using the global instance map
138
138
  const instanceMap = getInstanceMap();
139
- const instances = instanceMap.getOrInsert(element, () => new Map());
139
+ const instances = instanceMap.getOrInsertComputed(element, () => new Map());
140
140
 
141
141
  let instance = instances.get(registryItem);
142
142
 
@@ -301,7 +301,7 @@ class ElementEnhancementContainer {
301
301
 
302
302
  // Check the global instance map first
303
303
  const instanceMap = getInstanceMap();
304
- const instances = instanceMap.getOrInsert(element, () => new Map());
304
+ const instances = instanceMap.getOrInsertComputed(element, () => new Map());
305
305
 
306
306
  let instance = instances.get(registryItem);
307
307
 
@@ -370,7 +370,7 @@ if (typeof Element !== 'undefined') {
370
370
 
371
371
  Object.defineProperty(Element.prototype, 'enh', {
372
372
  get: function (this: Element) {
373
- return enhContainerWeakMap.getOrInsert(this, () => new ElementEnhancementContainer(this));
373
+ return enhContainerWeakMap.getOrInsertComputed(this, () => new ElementEnhancementContainer(this));
374
374
  },
375
375
  enumerable: true,
376
376
  configurable: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assign-gingerly",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "This package provides a utility function for carefully merging one object into another.",
5
5
  "homepage": "https://github.com/bahrus/assign-gingerly#readme",
6
6
  "bugs": {
package/parseWithAttrs.js CHANGED
@@ -1,21 +1,3 @@
1
- // Polyfill for Map.prototype.getOrInsert and WeakMap.prototype.getOrInsert
2
- if (typeof Map.prototype.getOrInsert !== 'function') {
3
- Map.prototype.getOrInsert = function(key, insert) {
4
- if (this.has(key)) return this.get(key);
5
- const value = insert();
6
- this.set(key, value);
7
- return value;
8
- };
9
- }
10
- if (typeof WeakMap.prototype.getOrInsert !== 'function') {
11
- WeakMap.prototype.getOrInsert = function(key, insert) {
12
- if (this.has(key)) return this.get(key);
13
- const value = insert();
14
- this.set(key, value);
15
- return value;
16
- };
17
- }
18
-
19
1
  import { globalParserRegistry } from './parserRegistry.js';
20
2
  import { resolveTemplate } from './resolveTemplate.js';
21
3
  // Module-level cache for parsed attribute values
@@ -108,7 +90,7 @@ function parseWithCache(attrValue, config, parser) {
108
90
  }
109
91
  // Get or create cache for this config
110
92
  const cacheKey = getCacheKey(config);
111
- const valueCache = parseCache.getOrInsert(cacheKey, () => new Map());
93
+ const valueCache = parseCache.getOrInsertComputed(cacheKey, () => new Map());
112
94
  // Use special key for null values
113
95
  const valueCacheKey = attrValue === null ? '__NULL__' : attrValue;
114
96
  // Check if we have a cached value
package/parseWithAttrs.ts CHANGED
@@ -108,7 +108,7 @@ function parseWithCache(
108
108
 
109
109
  // Get or create cache for this config
110
110
  const cacheKey = getCacheKey(config);
111
- const valueCache = parseCache.getOrInsert(cacheKey, () => new Map());
111
+ const valueCache = parseCache.getOrInsertComputed(cacheKey, () => new Map());
112
112
 
113
113
  // Use special key for null values
114
114
  const valueCacheKey = attrValue === null ? '__NULL__' : attrValue;
@@ -151,20 +151,20 @@ export interface SpawnContext<T = any, TMountContext = any> {
151
151
  /**
152
152
  * @deprecated Use EnhancementConfig instead
153
153
  */
154
- export type IBaseRegistryItem<T = any> = EnhancementConfig<T>;
154
+ export type IEnhancementRegistryItem<T = any> = EnhancementConfig<T>;
155
155
 
156
156
  /**
157
157
  * Interface for the options passed to assignGingerly
158
158
  */
159
159
  export interface IAssignGingerlyOptions {
160
- registry?: typeof BaseRegistry | BaseRegistry;
160
+ registry?: typeof EnhancementRegistry | EnhancementRegistry;
161
161
  bypassChecks?: boolean;
162
162
  }
163
163
 
164
164
  /**
165
165
  * Base registry class for managing enhancement configurations
166
166
  */
167
- export declare class BaseRegistry {
167
+ export declare class EnhancementRegistry {
168
168
  private items;
169
169
  push(items: EnhancementConfig | EnhancementConfig[]): void;
170
170
  getItems(): EnhancementConfig[];
@@ -1,4 +1,4 @@
1
- // Type declarations for Map.prototype.getOrInsert and WeakMap.prototype.getOrInsert
1
+ // Type declarations for Map.prototype.getOrInsertComputed and WeakMap.prototype.getOrInsertComputed
2
2
  // Feature is now supported in all modern browsers (Chrome 146+, Firefox 134+, Safari 18.2+)
3
3
  // See: https://web-platform-dx.github.io/web-features-explorer/features/getorinsert/
4
4
 
@@ -10,7 +10,7 @@ interface Map<K, V> {
10
10
  * @param insert A callback that returns the value to insert if the key doesn't exist
11
11
  * @returns The existing or newly inserted value
12
12
  */
13
- getOrInsert(key: K, insert: () => V): V;
13
+ getOrInsertComputed(key: K, insert: () => V): V;
14
14
  }
15
15
 
16
16
  interface WeakMap<K extends object, V> {
@@ -21,5 +21,5 @@ interface WeakMap<K extends object, V> {
21
21
  * @param insert A callback that returns the value to insert if the key doesn't exist
22
22
  * @returns The existing or newly inserted value
23
23
  */
24
- getOrInsert(key: K, insert: () => V): V;
24
+ getOrInsertComputed(key: K, insert: () => V): V;
25
25
  }