Skip to content

Conversation

@niradler
Copy link
Owner

@niradler niradler commented Sep 23, 2025

  • Complete TypeScript rewrite
  • Added 5 new carriers: LaserShip, Canada Post, China Post, Australia Post, and Royal Mail
  • Tracking number generation capabilities
  • Advanced validation and courier detection functions
  • Fixed UPS tracking URLs
  • Enhanced USPS barcode support (95 prefix)
  • Modern ESM build system

@niradler niradler requested a review from Copilot September 23, 2025 10:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR represents a complete TypeScript rewrite of the tracking number validation library with substantial improvements and new features.

  • Complete migration from JavaScript to TypeScript with full type definitions
  • Addition of 5 new shipping carriers: LaserShip, Canada Post, China Post, Australia Post, and Royal Mail
  • Implementation of tracking number generation capabilities for testing purposes
  • Enhanced validation with advanced courier detection functions and checksum validation
  • Updated UPS tracking URLs to remove deprecated /mobile/ path and added support for USPS barcodes starting with 95

Reviewed Changes

Copilot reviewed 33 out of 37 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/validate_tracking_numbers.test.ts New comprehensive TypeScript test suite replacing legacy JS tests
tests/tracking_numbers.ts Updated test data with TypeScript definitions and extensive new carrier test cases
tests/is_valid.test.ts New TypeScript validation tests with comprehensive invalid number coverage
tests/get_tracking_url.test.ts New TypeScript URL generation tests with specific UPS URL fix validation
tests/get_couriers.test.ts New TypeScript courier detection tests with enhanced error handling
src/index.ts Complete TypeScript rewrite with modern API design and backward compatibility
src/generate-tracking.ts New tracking number generation functionality with comprehensive format support
src/couriers/ New modular TypeScript courier system with individual carrier modules
package.json Updated dependencies, build system, and TypeScript tooling configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@niradler niradler requested a review from Copilot September 23, 2025 10:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 33 out of 37 changed files in this pull request and generated 5 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


for (let i = digits.length - 2; i >= 0; i--) {
const digitChar = digits[i];
if (!digitChar) continue;
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

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

The null check for digitChar is unnecessary since digits[i] will always return a string character or undefined. The check should be if (digitChar === undefined) continue; or simply removed since replace(/\D/g, '') ensures all characters are digits.

Suggested change
if (!digitChar) continue;

Copilot uses AI. Check for mistakes.
}

const lastDigitChar = digits[digits.length - 1];
if (!lastDigitChar) return false;
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

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

Similar to above, this null check is unnecessary. Since digits is created by replacing non-digits, lastDigitChar will always be a valid digit character or undefined if the string is empty (which is already handled by the length check at the beginning).

Suggested change
if (!lastDigitChar) return false;

Copilot uses AI. Check for mistakes.
const sum = digits.slice(0, -1).split('').reduce((acc, d) => acc + parseInt(d), 0);
const checkDigit = sum % 7;
const lastDigitChar = digits[digits.length - 1];
if (!lastDigitChar) return false;
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

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

The same unnecessary null check pattern appears here. This should be consistent with the validateMod10 function's handling.

Suggested change
if (!lastDigitChar) return false;

Copilot uses AI. Check for mistakes.
const digits = match[1];
const checkDigitStr = match[2];

if (!digits || !checkDigitStr) return false;
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

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

The null check for digits and checkDigitStr is unnecessary since they are extracted from a successful regex match. If the regex matches, these capture groups will always contain strings.

Suggested change
if (!digits || !checkDigitStr) return false;
// The null check for digits and checkDigitStr is unnecessary since they are guaranteed by the regex match.

Copilot uses AI. Check for mistakes.
for (let i = 0; i < 8; i++) {
const digitChar = digits[i];
const weight = weights[i];
if (!digitChar || weight === undefined) return false;
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

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

The check for digitChar is unnecessary since digits comes from a regex match that ensures 8 digits. The weight check is also unnecessary since weights array has exactly 8 elements and i is bounded by the loop.

Suggested change
if (!digitChar || weight === undefined) return false;

Copilot uses AI. Check for mistakes.
@niradler niradler merged commit 531cc9c into master Sep 23, 2025
2 checks passed
@niradler niradler deleted the v3 branch September 23, 2025 12:15
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.

2 participants