Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 25, 2025

This PR addresses the misspelling of the peak() method in IReaderBase and its implementing classes by introducing the correctly spelled peek() method while maintaining full backward compatibility.

Changes Made

Interface Updates

  • Added peek() method to IReaderBase interface with proper JSDoc documentation
  • Marked existing peak() method as @deprecated with migration guidance

Implementation Updates

Updated all classes that implement the interface:

  • Reader class
  • StreamingReader class
  • StreamingOctetReader class

Each implementation:

  • Adds new peek() method with the actual implementation
  • Converts peak() method to a deprecated wrapper that delegates to peek()
  • Maintains identical behavior for both methods

Example Usage

import { Reader } from '@jsonjoy.com/util/lib/buffers/Reader';

const reader = new Reader();
reader.reset(new Uint8Array([72, 101, 108, 108, 111])); // "Hello"

// New recommended way
console.log(reader.peek()); // 72 (doesn't advance cursor)

// Old way (still works, but shows deprecation warning)
console.log(reader.peak()); // 72 (doesn't advance cursor)

Testing

  • Added comprehensive test suite with 9 test cases
  • Verifies both methods return identical values
  • Tests all three implementing classes
  • Confirms cursor position behavior is preserved
  • All existing tests continue to pass

Backward Compatibility

  • No breaking changes introduced
  • Existing code using peak() continues to work unchanged
  • IDEs will show deprecation warnings for peak() with migration guidance
  • Type definitions support both method names

Fixes #6.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Copilot AI changed the title [WIP] Rename IReaderBase.peak() to peek() Rename peak() to peek() in IReaderBase with backward compatibility Jul 25, 2025
Copilot AI requested a review from streamich July 25, 2025 17:19
@streamich streamich marked this pull request as ready for review July 25, 2025 17:19
}

/**
* Get current byte value without advancing the cursor.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move this description over to peek().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Moved the JSDoc description to the peek() method and kept only the deprecation notice on peak(). Commit: 59343e1

test('peak() returns current byte without advancing cursor', () => {
const reader = new Reader();
reader.reset(new Uint8Array([1, 2, 3, 4, 5]));

Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove whitespace inside a single unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Removed the empty line in the test case. Commit: 59343e1

Copy link
Collaborator

@streamich streamich left a comment

Choose a reason for hiding this comment

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

  • When done, run yarn prettier to reformat the codebase.
  • Use Angular style commits feat: <msg>.

Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 25, 2025

  • When done, run yarn prettier to reformat the codebase.
  • Use Angular style commits feat: <msg>.

Done. Formatted codebase with yarn prettier and applied Angular-style commit message format. Commit: f0fd4ff

Copy link
Collaborator

@streamich streamich left a comment

Choose a reason for hiding this comment

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

LGTM

@streamich streamich merged commit 1d3c348 into master Jul 25, 2025
2 checks passed
@streamich streamich deleted the copilot/fix-6 branch July 25, 2025 18:15
@github-actions
Copy link

🎉 This PR is included in version 1.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rename IReaderBase.peak() to peek()

2 participants