assign-gingerly 0.0.24 → 0.0.25
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 +31 -1
- package/assignGingerly.js +2 -5
- package/assignGingerly.ts +2 -21
- package/package.json +3 -3
- package/playwright.config.ts +8 -8
package/README.md
CHANGED
|
@@ -108,10 +108,40 @@ console.log(obj);
|
|
|
108
108
|
// }
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
When the right hand side of an expression is an object, assignGingerly
|
|
111
|
+
When the right hand side of an expression is an object, assignGingerly behavior depends on the context:
|
|
112
|
+
- For **nested paths** (starting with `?.`): recursively merges into nested objects, creating them if needed
|
|
113
|
+
- For **plain keys**: performs simple assignment (like `Object.assign`), unless the target property is readonly or a class instance (see Examples 3a and 3b below)
|
|
112
114
|
|
|
113
115
|
Of course, just as Object.assign led to object spread notation, assignGingerly could lead to some sort of deep structural JavaScript syntax, but that is outside the scope of this polyfill package.
|
|
114
116
|
|
|
117
|
+
## Example 3-plain - Plain Key Object Assignment
|
|
118
|
+
|
|
119
|
+
For plain keys (without `?.` prefix), assignGingerly performs simple assignment, just like `Object.assign`:
|
|
120
|
+
|
|
121
|
+
```TypeScript
|
|
122
|
+
const obj = {};
|
|
123
|
+
const template = document.createElement('template');
|
|
124
|
+
template.innerHTML = '<div>Hello</div>';
|
|
125
|
+
|
|
126
|
+
assignGingerly(obj, {
|
|
127
|
+
template: template,
|
|
128
|
+
config: { theme: 'dark', lang: 'en' }
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
console.log(obj.template === template); // true - direct assignment
|
|
132
|
+
console.log(obj.config); // { theme: 'dark', lang: 'en' } - direct assignment
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
This is different from nested paths, which create intermediate objects:
|
|
136
|
+
|
|
137
|
+
```TypeScript
|
|
138
|
+
const obj = {};
|
|
139
|
+
assignGingerly(obj, {
|
|
140
|
+
'?.config?.theme': 'dark'
|
|
141
|
+
});
|
|
142
|
+
console.log(obj.config); // { theme: 'dark' } - intermediate object created
|
|
143
|
+
```
|
|
144
|
+
|
|
115
145
|
## Example 3a - Automatic Readonly Property Detection
|
|
116
146
|
|
|
117
147
|
assignGingerly automatically detects readonly properties and merges into them instead of attempting to replace them. This makes working with DOM properties like `style` and `dataset` much more ergonomic:
|
package/assignGingerly.js
CHANGED
|
@@ -475,11 +475,8 @@ export function assignGingerly(target, source, options) {
|
|
|
475
475
|
assignGingerly(currentValue, value, options);
|
|
476
476
|
}
|
|
477
477
|
else {
|
|
478
|
-
// Property is writable and not a class instance -
|
|
479
|
-
|
|
480
|
-
target[key] = {};
|
|
481
|
-
}
|
|
482
|
-
assignGingerly(target[key], value, options);
|
|
478
|
+
// Property is writable and not a class instance - simple assignment
|
|
479
|
+
target[key] = value;
|
|
483
480
|
}
|
|
484
481
|
}
|
|
485
482
|
else {
|
package/assignGingerly.ts
CHANGED
|
@@ -29,22 +29,6 @@ export interface ItemscopeManagerConfig<T = any> {
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
// Polyfill for WeakMap.prototype.getOrInsert
|
|
33
|
-
|
|
34
|
-
// if (typeof WeakMap.prototype.getOrInsertComputed !== 'function') {
|
|
35
|
-
// WeakMap.prototype.getOrInsertComputed = function(key, insert) {
|
|
36
|
-
// if (this.has(key)) return this.get(key);
|
|
37
|
-
// const value = insert();
|
|
38
|
-
// this.set(key, value);
|
|
39
|
-
// return value;
|
|
40
|
-
// };
|
|
41
|
-
// }
|
|
42
|
-
|
|
43
|
-
// /**
|
|
44
|
-
// * @deprecated Use EnhancementConfig instead
|
|
45
|
-
// */
|
|
46
|
-
// export type IBaseRegistryItem<T = any> = EnhancementConfig<T>;
|
|
47
|
-
|
|
48
32
|
/**
|
|
49
33
|
* Interface for the options passed to assignGingerly
|
|
50
34
|
*/
|
|
@@ -575,11 +559,8 @@ export function assignGingerly(
|
|
|
575
559
|
// Recursively apply assignGingerly to the readonly object or class instance
|
|
576
560
|
assignGingerly(currentValue, value, options);
|
|
577
561
|
} else {
|
|
578
|
-
// Property is writable and not a class instance -
|
|
579
|
-
|
|
580
|
-
target[key] = {};
|
|
581
|
-
}
|
|
582
|
-
assignGingerly(target[key], value, options);
|
|
562
|
+
// Property is writable and not a class instance - simple assignment
|
|
563
|
+
target[key] = value;
|
|
583
564
|
}
|
|
584
565
|
} else {
|
|
585
566
|
target[key] = value;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assign-gingerly",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
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": {
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
"chrome": "npx playwright cr http://localhost:8000"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@playwright/test": "1.59.
|
|
66
|
+
"@playwright/test": "1.59.1",
|
|
67
67
|
"spa-ssi": "0.0.27",
|
|
68
|
-
"@types/node": "25.5.
|
|
68
|
+
"@types/node": "25.5.2",
|
|
69
69
|
"typescript": "6.0.2"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/playwright.config.ts
CHANGED
|
@@ -34,15 +34,15 @@ export default defineConfig({
|
|
|
34
34
|
use: { ...devices['Desktop Chrome'] },
|
|
35
35
|
},
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
{
|
|
38
|
+
name: 'firefox',
|
|
39
|
+
use: { ...devices['Desktop Firefox'] },
|
|
40
|
+
},
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
{
|
|
43
|
+
name: 'webkit',
|
|
44
|
+
use: { ...devices['Desktop Safari'] },
|
|
45
|
+
},
|
|
46
46
|
],
|
|
47
47
|
|
|
48
48
|
/* Run your local dev server before starting the tests */
|