Skip to content

Conversation

@ben-nasi
Copy link
Contributor

@ben-nasi ben-nasi commented Nov 19, 2025

Adds three new modifiers for arrays

Slice modifier
Usage: ::slice(start, end) or ::slice(start)
Example: {stream.visualTags::slice(0, 2)}
Input: 10bit, HDR, DV, 3D, IMAX
Output: 10bit, HDR

Sort modifier
Usage: ::sort(asc) or ::sort(desc)
Example (alphabetical): {stream.audioTags::sort(asc)}
Input: Atmos, DTS-HD MA, TrueHD, OPUS, AAC
Output: AAC, Atmos, DTS-HD MA, OPUS, TrueHD
Example (numerical): {stream.seasons::sort(desc)}
Input: 1, 2, 3, 4, 5, 6, 7, 8
Output: 8, 7, 6, 5, 4, 3, 2, 1
Note: Combined alphabetical/numerical sorting is possible

Merge modifier
Usage: ::merge('{example.Array}')
Example: {stream.audioTags::merge('{stream.audioChannels}')}
Input: Atmos, TrueHD + 7.1
Output: Atmos, TrueHD, 7.1

Combined usage
Example: {stream.visualTags::merge('{stream.audioTags}')::merge('{stream.audioChannels}')::sort(asc)::slice(0, 4)::join(' - ')}
Input: HDR10, DV + Atmos, TrueHD + 7.1
Output: 7.1 - Atmos - DV - HDR10

Technical changes
Updated applySingleModifier: Added support for returning arrays, added parseValue parameter to support context access for merging.

Summary by CodeRabbit

Release Notes

  • New Features
    • Three new formatting modifiers now available: slice for substring extraction, sort for numeric-aware ascending/descending ordering, and merge for combining arrays from specified variable paths.
    • Enhanced variable handling with improved support for array and string operations.
    • Improved sorting comparison logic to intelligently handle mixed numeric and text values.
    • Extended type support for more flexible data transformations.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 19, 2025

Walkthrough

Extends the modifier system by adding parseValue as a context parameter to applySingleModifier, updating return types to support arrays, and implementing three new modifiers (slice, sort, merge) that enable array manipulation and cross-variable value concatenation.

Changes

Cohort / File(s) Summary
Modifier System Enhancement
packages/core/src/formatters/base.ts
Added parseValue parameter to applySingleModifier for context-aware modifications; extended return type to string | boolean | any[]; implemented new array modifiers (slice(n[, m]), sort(asc|desc), merge(...)) with numeric-aware sorting; updated hardcodedModifiersForRegexMatching map; propagated parseValue through parseModifiedVariable call sites.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review new array modifier logic (slice, sort, merge), especially the merge resolver that concatenates arrays via path parsing
  • Verify return type extension (any[]) is correctly handled throughout the modifier application chain
  • Confirm parseValue parameter threading is consistent across all call sites
  • Validate numeric-aware sorting implementation for correctness

Possibly related PRs

Suggested reviewers

  • Viren070

Poem

🐰 Arrays now slice and sort with grace,
Merge paths find their rightful place,
Context flows through modifiers deep,
Numeric wisdom for values to keep,
Formatters dance in a better space!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarises the main change: adding three new array modifiers (slice, sort, merge) to the core formatter.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/core/src/formatters/base.ts (1)

754-768: Slice modifier implementation is correct.

The logic correctly handles both slice(start) and slice(start, end) patterns with appropriate fallback behaviour.

Minor style inconsistency: Line 757 has _mod.length -1 whilst line 771 uses _mod.length - 1 with proper spacing around the operator.

Apply this diff for consistency:

-          const args = _mod
-            .substring(6, _mod.length -1)
-            .split(',')
-            .map((arg) => parseInt(arg.trim(), 10));
+          const args = _mod
+            .substring(6, _mod.length - 1)
+            .split(',')
+            .map((arg) => parseInt(arg.trim(), 10));
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 76bf4a2 and 6219029.

📒 Files selected for processing (1)
  • packages/core/src/formatters/base.ts (5 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-14T16:46:18.507Z
Learnt from: DavidGracias
Repo: Viren070/AIOStreams PR: 375
File: packages/core/src/formatters/base.ts:0-0
Timestamp: 2025-09-14T16:46:18.507Z
Learning: In packages/core/src/formatters/base.ts, the modifier definitions intentionally include regex patterns (like "join('.*?')", "$.*?", "^.*?") that require pattern matching functionality. The buildModifierRegexPattern() method should not fully escape all regex metacharacters as this would break the intended regex matching behavior within modifier definitions.

Applied to files:

  • packages/core/src/formatters/base.ts
🔇 Additional comments (6)
packages/core/src/formatters/base.ts (6)

592-594: LGTM! Context parameter properly propagated.

The addition of parseValue as a parameter enables context-aware modifiers like merge to access other variables from the parse context.


636-637: LGTM! Return type appropriately extended.

The extended return type any[] allows array modifiers to preserve array types through chaining, which is essential for the new slice, sort, and merge functionality.


769-791: LGTM! Robust sort implementation with numeric awareness.

The implementation correctly:

  • Validates the direction parameter
  • Uses spread operator to avoid mutation
  • Provides numeric-aware sorting via localeCompare with numeric: true option
  • Handles both pure numeric and mixed-type arrays appropriately

797-820: LGTM! Merge implementation with sensible fallback.

The implementation correctly:

  • Validates the variable path format (requires {...} wrapper)
  • Checks that the target property is an array before merging
  • Gracefully falls back to the original array if the merge target is invalid

Note: The merge modifier doesn't support modifiers within the path (e.g., merge('{stream.audioChannels::slice(0, 2)}')), which is a reasonable design choice to maintain simplicity.


964-972: LGTM! Type signature appropriately broadened.

The updated signature any[] enables the sort modifier to handle arrays containing numbers, strings, or mixed types whilst maintaining numeric-aware comparison for consistency with the new parametrised sort modifier.


1025-1030: LGTM! Regex patterns correctly defined.

The hardcoded modifier patterns appropriately:

  • Match both single-argument slice(n) and two-argument slice(n, m) forms with flexible whitespace
  • Cover both ascending and descending sort directions
  • Support both single and double quote delimiters for merge

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