Skip to content

feat: Add C.F.R. part/section separation support#7

Merged
beshkenadze merged 1 commit intomainfrom
feat/cfr-part-section-support
Aug 21, 2025
Merged

feat: Add C.F.R. part/section separation support#7
beshkenadze merged 1 commit intomainfrom
feat/cfr-part-section-support

Conversation

@beshkenadze
Copy link
Owner

Summary

This PR adds proper support for separating C.F.R. citations into part and section components, eliminating the need for manual string splitting of citations like "778.113" into part "778" and section "113".

Changes Made

Core Implementation

  • ✅ Add part field to Metadata interface
  • ✅ Add part, sectionOnly, and backward-compatible section getters to FullLawCitation
  • ✅ Update C.F.R. regex patterns in laws.json to capture part and section separately
  • ✅ Fix ID resolution logic in resolve.ts to handle part.section substitution correctly

Testing

  • ✅ Add comprehensive test suite (tests/cfr-part-section.test.ts) with 11 test cases
  • ✅ Update existing tests to work with new part/section structure
  • ✅ All 423 tests passing with 0 failures

API Changes

New Properties Available

const citation = citations[0] as FullLawCitation

// New functionality
const part = citation.part           // "778" 
const sectionOnly = citation.sectionOnly  // "113"

// Backward compatible (existing code continues to work)
const combined = citation.section    // "778.113"

Before vs After

Before (manual parsing required):

const [part, section] = citation.section.split('.')

After (direct access):

const part = citation.part        // "778"
const section = citation.sectionOnly  // "113"  
const combined = citation.section     // "778.113" (backward compatible)

Backward Compatibility

No breaking changes - All existing code continues to work unchanged.
✅ The section getter still returns the combined "778.113" format for backward compatibility.
✅ New functionality is additive only.

Test Results

✅ 423 tests passing
❌ 0 tests failing  
📊 2,146 assertions executed successfully

Coverage

  • Single section parsing: 29 C.F.R. § 778.113 → part: "778", section: "113"
  • Multiple sections: 29 C.F.R. §§ 778.113, 778.114 (maintains original behavior)
  • Complex sections: 29 C.F.R. § 1910.1200 → part: "1910", section: "1200"
  • Pin cites: 29 C.F.R. § 778.113(a) → part: "778", section: "113", pinCite: "(a)"
  • ID resolution: Id. § 778.114(a)(5) correctly substitutes both part and section

Demo

The demo script (demo-citation-extraction.ts) shows the new functionality in action with real C.F.R. and U.S.C. citations.

Resolves the user's request to avoid manual string parsing of C.F.R. part.section identifiers.

Add proper support for separating C.F.R. citations into part and section
components, eliminating the need for manual string splitting.

Changes:
- Add `part` field to Metadata interface and FullLawCitation getters
- Update C.F.R. regex patterns to capture part and section separately
- Maintain backward compatibility with combined section getter
- Fix ID resolution logic to handle part.section substitution correctly
- Add comprehensive test suite for C.F.R. part/section parsing
- Update existing tests to work with new part/section structure

Breaking changes: None (backward compatible)

Resolves user request to avoid manual parsing of "778.113" into
part "778" and section "113" components.

Before:
```typescript
const [part, section] = citation.section.split('.')
```

After:
```typescript
const part = citation.part        // "778"
const section = citation.sectionOnly  // "113"
const combined = citation.section     // "778.113" (backward compatible)
```
@beshkenadze
Copy link
Owner Author

🚀 Thanks for the PR! The CI checks are running. Once they pass, this PR will be ready for review.

@beshkenadze beshkenadze merged commit d2aef62 into main Aug 21, 2025
2 checks passed
@beshkenadze beshkenadze deleted the feat/cfr-part-section-support branch August 21, 2025 13:13
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