From aac0c4ae489446e2775f84310aeb5d0b4d3de7b6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 21:06:47 +0000 Subject: [PATCH 1/6] Initial plan From a1d56e692c680b2211688687f997df06c5e81b9c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 21:12:45 +0000 Subject: [PATCH 2/6] Document getProperty export in README Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com> --- nodejs/packages/treebark/README.md | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/nodejs/packages/treebark/README.md b/nodejs/packages/treebark/README.md index bec856a..1ecd11c 100644 --- a/nodejs/packages/treebark/README.md +++ b/nodejs/packages/treebark/README.md @@ -110,6 +110,60 @@ Renders a template to DOM nodes (browser only). **Returns:** `DocumentFragment` - DOM fragment containing rendered nodes +### `getProperty(data, path, parents?, logger?, getOuterProperty?)` + +Get a nested property from data using dot notation. This utility function is used internally by Treebark but is also exported for use in custom property resolution scenarios. + +**Parameters:** +- `data: Data` - The data object to retrieve the property from +- `path: BindPath` - The property path using dot notation (e.g., `"user.name"` or `"items.0.value"`) +- `parents?: Data[]` - (Optional) Array of parent data contexts for parent property access +- `logger?: Logger` - (Optional) Logger instance for error messages +- `getOuterProperty?: OuterPropertyResolver` - (Optional) Fallback function called when property is not found + +**Returns:** `unknown` - The value at the specified path, or `undefined` if not found + +**Special path syntax:** +- `"."` - Returns the data object itself +- `".."` - Access parent context (requires `parents` array) +- `"../.."` - Access grandparent context +- `"user.name"` - Access nested properties with dot notation +- `"items.0.value"` - Access array elements by index + +**Example:** + +```javascript +import { getProperty } from 'treebark'; + +const data = { + user: { + profile: { + name: 'Alice', + age: 30 + } + }, + items: ['first', 'second', 'third'] +}; + +// Simple property access +getProperty(data, 'user.profile.name'); // Returns: 'Alice' + +// Array access +getProperty(data, 'items.0'); // Returns: 'first' + +// Current object reference +getProperty(data, '.'); // Returns: data object itself + +// With fallback handler +const result = getProperty( + data, + 'missing.property', + [], + undefined, + (path) => `default-${path}` +); // Returns: 'default-missing.property' +``` + ## Examples For comprehensive examples, documentation, and advanced features, see the [main Treebark repository](https://github.com/danmarshall/treebark). From 952f10f75fdaacabde7195dbd98580e465110eac Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 21:14:28 +0000 Subject: [PATCH 3/6] Fix parent access syntax in getProperty documentation Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com> --- nodejs/packages/treebark/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nodejs/packages/treebark/README.md b/nodejs/packages/treebark/README.md index 1ecd11c..5f49042 100644 --- a/nodejs/packages/treebark/README.md +++ b/nodejs/packages/treebark/README.md @@ -125,8 +125,8 @@ Get a nested property from data using dot notation. This utility function is use **Special path syntax:** - `"."` - Returns the data object itself -- `".."` - Access parent context (requires `parents` array) -- `"../.."` - Access grandparent context +- `"..propName"` - Access parent context (requires `parents` array) +- `"../../propName"` - Access grandparent context - `"user.name"` - Access nested properties with dot notation - `"items.0.value"` - Access array elements by index From da2d53613bd3ebfbcaecaa4cd52f9b5f5da6278e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 21:17:09 +0000 Subject: [PATCH 4/6] Add simple property access example as the primary use case Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com> --- nodejs/packages/treebark/README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/nodejs/packages/treebark/README.md b/nodejs/packages/treebark/README.md index 5f49042..10080b4 100644 --- a/nodejs/packages/treebark/README.md +++ b/nodejs/packages/treebark/README.md @@ -124,11 +124,12 @@ Get a nested property from data using dot notation. This utility function is use **Returns:** `unknown` - The value at the specified path, or `undefined` if not found **Special path syntax:** +- `"propName"` - Access a simple property (e.g., `"name"`, `"age"`) +- `"user.name"` - Access nested properties with dot notation +- `"items.0"` - Access array elements by index - `"."` - Returns the data object itself - `"..propName"` - Access parent context (requires `parents` array) - `"../../propName"` - Access grandparent context -- `"user.name"` - Access nested properties with dot notation -- `"items.0.value"` - Access array elements by index **Example:** @@ -136,17 +137,22 @@ Get a nested property from data using dot notation. This utility function is use import { getProperty } from 'treebark'; const data = { + name: 'Alice', + age: 30, user: { profile: { - name: 'Alice', - age: 30 + email: 'alice@example.com' } }, items: ['first', 'second', 'third'] }; -// Simple property access -getProperty(data, 'user.profile.name'); // Returns: 'Alice' +// Simple property access (most common case) +getProperty(data, 'name'); // Returns: 'Alice' +getProperty(data, 'age'); // Returns: 30 + +// Nested property access +getProperty(data, 'user.profile.email'); // Returns: 'alice@example.com' // Array access getProperty(data, 'items.0'); // Returns: 'first' @@ -157,11 +163,11 @@ getProperty(data, '.'); // Returns: data object itself // With fallback handler const result = getProperty( data, - 'missing.property', + 'missing', [], undefined, (path) => `default-${path}` -); // Returns: 'default-missing.property' +); // Returns: 'default-missing' ``` ## Examples From 099e783a30d03bd5a2c9ed070ba9049d68e4b52a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Oct 2025 21:19:45 +0000 Subject: [PATCH 5/6] Use concrete property names in parent access examples Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com> --- nodejs/packages/treebark/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nodejs/packages/treebark/README.md b/nodejs/packages/treebark/README.md index 10080b4..0d74e27 100644 --- a/nodejs/packages/treebark/README.md +++ b/nodejs/packages/treebark/README.md @@ -128,8 +128,8 @@ Get a nested property from data using dot notation. This utility function is use - `"user.name"` - Access nested properties with dot notation - `"items.0"` - Access array elements by index - `"."` - Returns the data object itself -- `"..propName"` - Access parent context (requires `parents` array) -- `"../../propName"` - Access grandparent context +- `"..parentProp"` - Access parent context (requires `parents` array) +- `"../../grandProp"` - Access grandparent context **Example:** From 41ee345e7ed8d4564a974e7e60eea13dae0de854 Mon Sep 17 00:00:00 2001 From: Dan Marshall Date: Thu, 30 Oct 2025 12:36:31 -0700 Subject: [PATCH 6/6] Remove example code from README.md Removed example code snippets for getProperty function from README. --- nodejs/packages/treebark/README.md | 43 +----------------------------- 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/nodejs/packages/treebark/README.md b/nodejs/packages/treebark/README.md index 0d74e27..c344113 100644 --- a/nodejs/packages/treebark/README.md +++ b/nodejs/packages/treebark/README.md @@ -131,49 +131,8 @@ Get a nested property from data using dot notation. This utility function is use - `"..parentProp"` - Access parent context (requires `parents` array) - `"../../grandProp"` - Access grandparent context -**Example:** - -```javascript -import { getProperty } from 'treebark'; - -const data = { - name: 'Alice', - age: 30, - user: { - profile: { - email: 'alice@example.com' - } - }, - items: ['first', 'second', 'third'] -}; - -// Simple property access (most common case) -getProperty(data, 'name'); // Returns: 'Alice' -getProperty(data, 'age'); // Returns: 30 - -// Nested property access -getProperty(data, 'user.profile.email'); // Returns: 'alice@example.com' - -// Array access -getProperty(data, 'items.0'); // Returns: 'first' - -// Current object reference -getProperty(data, '.'); // Returns: data object itself - -// With fallback handler -const result = getProperty( - data, - 'missing', - [], - undefined, - (path) => `default-${path}` -); // Returns: 'default-missing' -``` - -## Examples - For comprehensive examples, documentation, and advanced features, see the [main Treebark repository](https://github.com/danmarshall/treebark). ## License -MIT \ No newline at end of file +MIT