assign-gingerly 0.0.34 → 0.0.35

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
@@ -3303,6 +3303,28 @@ console.log(result);
3303
3303
 
3304
3304
  -->
3305
3305
 
3306
+ ## Resolving and Assigning with `assignFrom`
3307
+
3308
+ The `assignFrom` function combines RHS path resolution with `assignGingerly` in a single call. It resolves `?.`-prefixed RHS values against a source object, then assigns the results into a target. Use `?.` alone as a RHS value to reference the entire source object itself.
3309
+
3310
+ ```TypeScript
3311
+ import { assignFrom } from 'assign-gingerly/assignFrom.js';
3312
+
3313
+ const viewModel = { username: 'Alice', clone: someDocumentFragment };
3314
+
3315
+ assignFrom(target, {
3316
+ '?.appendChild': '?..clone', // source.clone
3317
+ '?.clone?.q?..username?.textContent': '?.username', // source.username
3318
+ ref: '?.' // the source object itself
3319
+ }, {
3320
+ from: viewModel,
3321
+ withMethods: ['appendChild'],
3322
+ aka: { 'q': 'querySelector' }
3323
+ });
3324
+ ```
3325
+
3326
+ For full documentation, see [docs/assignFrom.md](docs/assignFrom.md).
3327
+
3306
3328
  ## Itemscope Managers (Chrome 146+)
3307
3329
 
3308
3330
  Itemscope Managers provide a way to manage DOM fragments and their associated data/view models for elements with the `itemscope` attribute. This feature enables frameworks and libraries to manage light children of web components, DOM fragments from looping constructs, and scenarios where custom element wrapping is not feasible.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assign-gingerly",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
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/resolveValues.js CHANGED
@@ -26,8 +26,10 @@ export function resolveValues(pattern, source) {
26
26
  const result = {};
27
27
  for (const [key, value] of Object.entries(pattern)) {
28
28
  if (typeof value === 'string' && value.startsWith('?.')) {
29
- // Parse path: split by '.', strip '?', filter empties
30
- const parts = value.split('.').map(p => p.replace(/\?/g, '')).filter(p => p.length > 0);
29
+ // Parse path: split on '?.' delimiter, filter empties
30
+ // Use '?.' as the sole delimiter to preserve dots in values (e.g., CSS selectors)
31
+ // Special case: '?.' alone (empty path) resolves to the source object itself
32
+ const parts = value.split('?.').filter(p => p.length > 0);
31
33
  let current = source;
32
34
  for (const part of parts) {
33
35
  if (current == null)
package/resolveValues.ts CHANGED
@@ -29,8 +29,10 @@ export function resolveValues(
29
29
  const result: Record<string, any> = {};
30
30
  for (const [key, value] of Object.entries(pattern)) {
31
31
  if (typeof value === 'string' && value.startsWith('?.')) {
32
- // Parse path: split by '.', strip '?', filter empties
33
- const parts = value.split('.').map(p => p.replace(/\?/g, '')).filter(p => p.length > 0);
32
+ // Parse path: split on '?.' delimiter, filter empties
33
+ // Use '?.' as the sole delimiter to preserve dots in values (e.g., CSS selectors)
34
+ // Special case: '?.' alone (empty path) resolves to the source object itself
35
+ const parts = value.split('?.').filter(p => p.length > 0);
34
36
  let current = source;
35
37
  for (const part of parts) {
36
38
  if (current == null) break;