Skip to content

feat(toon): add detectTruncation() API with structured truncation report#313

Open
kahaidous wants to merge 1 commit into
toon-format:mainfrom
kahaidous:feat/detect-truncation
Open

feat(toon): add detectTruncation() API with structured truncation report#313
kahaidous wants to merge 1 commit into
toon-format:mainfrom
kahaidous:feat/detect-truncation

Conversation

@kahaidous

Copy link
Copy Markdown

Description

Adds detectTruncation(), a new public API that analyzes TOON input and
returns a structured report about missing items, without throwing exceptions.

Closes #312

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test coverage improvement

Changes Made

  • packages/toon/src/index.ts - adds detectTruncation()
  • packages/toon/src/types.ts - adds TruncationReport and TruncatedArray types
  • packages/toon/test/truncation.test.ts - 9 tests

Testing

  • 9 new tests covering complete, truncated, and edge cases

  • 466/466 existing tests still pass

  • All existing tests pass

  • Added new tests for changes

  • Tests cover edge cases and spec compliance

Pre-submission Checklist

  • My code follows the project's coding standards
  • I have run code formatting/linting tools
  • I have added tests that prove my fix/feature works
  • New and existing tests pass locally
  • I have updated documentation if needed
  • I have reviewed the TOON specification for relevant sections

Breaking Changes

  • No breaking changes
  • Breaking changes (describe migration path below)

API

const report = detectTruncation('employees[100]{id,name}:\n  1,Alice\n  2,Bob')
// {
//   isTruncated: true,
//   arrays: [{
//     key: 'employees',
//     declaredCount: 100,
//     actualCount: 2,
//     missingItems: 98,
//     completionRate: 0.02
//   }]
// }

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.

feat: detectTruncation() public API

1 participant