feat: add isInteger function for integer validation #59
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR introduces a new
isIntegervalidation function and enhances existing validation functions with consistent whitespace handling. TheisIntegerfunction validates whether a string represents a whole number (integer) without decimal places, providing a more specific validation option compared to the existingisNumericfunction which accepts decimal numbers.Changes
New Feature: isInteger Validation Function
Core Implementation (
src/isInteger.ts)isInteger(str: string): booleanfunction to validate integer-only strings/^-?\d+$/for performance.0suffix), scientific notation, and special valuesType System Integration (
src/types/)IntegerStringbranded type for compile-time type safetyisValidIntegertype guard functiontoIntegerStringbuilder function (returnsIntegerString | null)assertIsIntegerStringassertion function with runtime error handlingTesting (
tests/isInteger.test.ts)Documentation & Integration
isIntegerdocumentation and examplesnano-string isInteger "42"docs-src/index.html)docs-src/src/metadata.ts)Enhancement: Consistent Whitespace Handling
Modified validation functions (all now trim leading/trailing whitespace):
isASCII- Validates ASCII-only charactersisAlphanumeric- Validates alphanumeric stringsisEmail- Validates email addressesisHexColor- Validates hex color codesisUUID- Validates UUID stringsisUrl- Validates URL stringsTest Updates - Added whitespace handling test cases to each affected function's test suite
Build & Performance Data
benchmarks/bundle-sizes.json)benchmarks/performance-benchmarks.json)Technical Details
Key Differences: isInteger vs isNumeric
isIntegerisNumeric"3.14""3.14""42.0""42.0""1e5""1e5""-17""-17""007""007"Implementation Highlights
Performance Optimizations:
Type Safety:
IntegerStringReal-World Use Cases
The
isIntegerfunction is particularly useful for:Breaking Changes
None - this is a purely additive change. All existing functionality remains unchanged, and the whitespace trimming enhancement is a quality-of-life improvement that should not break existing use cases.
Testing
Test Coverage
isIntegercovering all edge casesManual Testing
Run the following to verify: