Skip to content

feat(Arktype/Utils): Adds new functionality to ArkType utils#22

Merged
jhechtf merged 1 commit intomainfrom
feat/update-arktype-utils
Aug 4, 2025
Merged

feat(Arktype/Utils): Adds new functionality to ArkType utils#22
jhechtf merged 1 commit intomainfrom
feat/update-arktype-utils

Conversation

@jhechtf
Copy link
Copy Markdown
Owner

@jhechtf jhechtf commented Jul 19, 2025

TL;DR

Enhanced formDataToObject to support deeply nested objects and arrays using dot and bracket notation.

What changed?

  • Completely rewrote the formDataToObject function to handle complex nested structures
  • Added support for dot notation (e.g., payments.id1.location)
  • Added support for bracket notation for arrays (e.g., locations[].members[])
  • Implemented parseKeyPath function to parse complex key paths
  • Added setDeep function for recursive object/array construction
  • Added comprehensive tests for nested objects and arrays
  • Updated documentation with examples of deeply nested structures

How to test?

Test with complex form data structures:

// Test nested objects with dot notation
const fd = new FormData();
fd.append('payments.id1.location', 'England');
fd.append('payments.id1.age', '37');
fd.append('payments.id2.location', 'New York');
const obj = formDataToObject(fd);

// Test nested arrays with bracket notation
const fd2 = new FormData();
fd2.append('locations[].name', 'England');
fd2.append('locations[].members[]', 'John');
fd2.append('locations[].members[]', 'Joe');
fd2.append('locations[].name', 'France');
const obj2 = formDataToObject(fd2);

Why make this change?

The previous implementation had limited support for nested structures, making it difficult to work with complex form data. This enhancement allows for more intuitive mapping of form fields to deeply nested JavaScript objects, supporting real-world use cases like multi-level forms with repeating sections and arrays of objects.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jul 19, 2025

🦋 Changeset detected

Latest commit: 3e69627

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@jhecht/arktype-utils Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Owner Author

jhechtf commented Jul 19, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@jhechtf jhechtf marked this pull request as ready for review July 19, 2025 07:57
@jhechtf jhechtf force-pushed the feat/update-arktype-utils branch from 4ce9629 to 42257c0 Compare August 4, 2025 04:19
@jhechtf jhechtf force-pushed the feat/update-arktype-utils branch from 42257c0 to 3e69627 Compare August 4, 2025 04:22
@jhechtf jhechtf merged commit 5a8aac9 into main Aug 4, 2025
4 checks passed
@jhechtf jhechtf deleted the feat/update-arktype-utils branch August 4, 2025 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant