assign-gingerly 0.0.61 → 0.0.63

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
@@ -1312,7 +1312,15 @@ obj
1312
1312
  console.log(obj); // { a: 1, b: { c: 2 }, d: 3 }
1313
1313
  ```
1314
1314
 
1315
- **Note**: The `assignTentatively` method on Object.prototype is simply an alias for `assignGingerly` and does **not** provide the reversibility features of the standalone `assignTentatively` function described in Example 8. For reversible assignments, use the standalone function from `assign-gingerly/assignTentatively`.
1315
+ **Note**: The `assignTentatively` method on Object.prototype provides full reversibility it calls the standalone `assignTentatively` function and returns a reversal object. Apply the reversal with `obj.assignGingerly(reversal)` to undo all changes:
1316
+
1317
+ ```TypeScript
1318
+ const obj = { name: 'Alice', age: 30 };
1319
+ const reversal = obj.assignTentatively({ name: 'Bob', score: 100 });
1320
+ // obj = { name: 'Bob', age: 30, score: 100 }
1321
+ obj.assignGingerly(reversal);
1322
+ // obj = { name: 'Alice', age: 30 } — restored
1323
+ ```
1316
1324
 
1317
1325
  The prototype extensions are non-enumerable and won't appear in `Object.keys()` or `for...in` loops.
1318
1326
 
@@ -4057,9 +4065,9 @@ assignFrom(oElement, {
4057
4065
  assignFrom(oElement, {
4058
4066
  '?.textContent =>': {
4059
4067
  do: 'builtIns.join',
4060
- separator: ' | ',
4061
4068
  get: {
4062
- value: ['?.firstName', '?.lastName']
4069
+ value: ['?.firstName', '?.lastName'],
4070
+ separator: ' | '
4063
4071
  }
4064
4072
  }
4065
4073
  }, { from: vm });
package/handlers/join.js CHANGED
@@ -66,8 +66,7 @@ export class JoinHandler {
66
66
  this.config = config;
67
67
  }
68
68
  async assign(lhsTarget, resolvedParams) {
69
- const { value } = resolvedParams;
70
- const separator = this.config.separator ?? '';
69
+ const { value, separator = '' } = resolvedParams;
71
70
  const items = Array.isArray(value) ? processValue(value) : [value];
72
71
  return items.join(separator);
73
72
  }
package/handlers/join.ts CHANGED
@@ -71,8 +71,7 @@ export class JoinHandler implements AssignFromHandler {
71
71
  }
72
72
 
73
73
  async assign(lhsTarget: any, resolvedParams: Record<string, any>): Promise<string> {
74
- const { value } = resolvedParams;
75
- const separator = this.config.separator ?? '';
74
+ const { value, separator = '' } = resolvedParams;
76
75
 
77
76
  const items = Array.isArray(value) ? processValue(value) : [value];
78
77
  return items.join(separator);
@@ -1,4 +1,5 @@
1
1
  import assignGingerly, { EnhancementRegistry, ItemscopeRegistry, getInstanceMap } from './assignGingerly.js';
2
+ import assignTentatively from './assignTentatively.js';
2
3
  import { parseWithAttrs } from './parseWithAttrs.js';
3
4
  /**
4
5
  * Normalizes lifecycleKeys to always return an object with dispose and resolved keys
@@ -426,18 +427,13 @@ Object.defineProperty(Object.prototype, 'assignGingerly', {
426
427
  });
427
428
  /**
428
429
  * Adds assignTentatively method to all objects via the Object prototype
429
- * This is an alias for assignGingerly
430
+ * Returns a reversal object that can undo the changes when passed to assignGingerly.
430
431
  */
431
432
  Object.defineProperty(Object.prototype, 'assignTentatively', {
432
433
  value: function (source, options) {
433
- // Auto-populate registry from customElementRegistry if this is an Element
434
- if (this instanceof Element && (!options || !options.registry)) {
435
- if (!options)
436
- options = {};
437
- options.registry = this.customElementRegistry?.enhancementRegistry;
438
- }
439
- assignGingerly(this, source, options);
440
- return this;
434
+ const reversal = options?.reversal ?? {};
435
+ assignTentatively(this, source, { reversal });
436
+ return reversal;
441
437
  },
442
438
  writable: true,
443
439
  enumerable: false,
@@ -1,4 +1,5 @@
1
1
  import assignGingerly, { EnhancementRegistry, ItemscopeRegistry, IAssignGingerlyOptions, getInstanceMap, INSTANCE_MAP_GUID } from './assignGingerly.js';
2
+ import assignTentatively from './assignTentatively.js';
2
3
  import { EnhancementConfig, SpawnContext } from './types/assign-gingerly/types.js';
3
4
  import { parseWithAttrs } from './parseWithAttrs.js';
4
5
 
@@ -60,22 +61,24 @@ declare global {
60
61
  ): this;
61
62
 
62
63
  /**
63
- * Alias for assignGingerly. Carefully merge properties from a source object into this object.
64
- * Supports nested paths with ?. notation and dependency injection via registry.
64
+ * Carefully merge properties from a source object into this object, tracking changes
65
+ * for reversibility. Returns a reversal object that can undo all modifications.
65
66
  *
66
67
  * @param source - The source object to merge
67
- * @param options - Optional configuration with registry for dependency injection
68
- * @returns This object after merging
68
+ * @param options - Optional configuration with reversal tracking
69
+ * @returns A reversal object that, when passed to assignGingerly, undoes the changes
69
70
  *
70
71
  * @example
71
- * const target = {};
72
- * target.assignTentatively({ '?.style?.height': '15px' });
73
- * console.log(target); // { style: { height: '15px' } }
72
+ * const obj = { name: 'Alice', age: 30 };
73
+ * const reversal = obj.assignTentatively({ name: 'Bob', score: 100 });
74
+ * // obj = { name: 'Bob', age: 30, score: 100 }
75
+ * obj.assignGingerly(reversal);
76
+ * // obj = { name: 'Alice', age: 30 } — score removed, name restored
74
77
  */
75
78
  assignTentatively(
76
79
  source: Record<string | symbol, any>,
77
- options?: IAssignGingerlyOptions
78
- ): this;
80
+ options?: { reversal?: Record<string | symbol, any> }
81
+ ): Record<string | symbol, any>;
79
82
  }
80
83
  }
81
84
 
@@ -567,21 +570,17 @@ Object.defineProperty(Object.prototype, 'assignGingerly', {
567
570
 
568
571
  /**
569
572
  * Adds assignTentatively method to all objects via the Object prototype
570
- * This is an alias for assignGingerly
573
+ * Returns a reversal object that can undo the changes when passed to assignGingerly.
571
574
  */
572
575
  Object.defineProperty(Object.prototype, 'assignTentatively', {
573
576
  value: function <T extends object>(
574
577
  this: T,
575
578
  source: Record<string | symbol, any>,
576
- options?: IAssignGingerlyOptions
577
- ): T {
578
- // Auto-populate registry from customElementRegistry if this is an Element
579
- if (this instanceof Element && (!options || !options.registry)) {
580
- if (!options) options = {};
581
- options.registry = (this as any).customElementRegistry?.enhancementRegistry;
582
- }
583
- assignGingerly(this, source, options);
584
- return this;
579
+ options?: { reversal?: Record<string | symbol, any> }
580
+ ): Record<string | symbol, any> {
581
+ const reversal = options?.reversal ?? {};
582
+ assignTentatively(this, source, { reversal });
583
+ return reversal;
585
584
  },
586
585
  writable: true,
587
586
  enumerable: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assign-gingerly",
3
- "version": "0.0.61",
3
+ "version": "0.0.63",
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": {