Repository navigation
Add networkForm() for CIDR network-address strings - #199
Merged
Merged
Conversation
Returns the network address with the CIDR suffix preserved as a string, e.g. `205.65.224.110/29` → `205.65.224.104/29`. Closes the gap raised in #39: previously callers had to assemble the result by hand (`${addr.startAddress().correctForm()}/${addr.subnetMask}`). Available on both Address4 and Address6.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #199 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 330 332 +2
Branches 186 186
=========================================
+ Hits 330 332 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds
networkForm()to bothAddress4andAddress6, returning the network address with the CIDR suffix preserved as a string.Closes the gap raised in #39 (specifically the 2025 follow-up from @nfriedly): previously callers had to assemble the result by hand with
`${addr.startAddress().correctForm()}/${addr.subnetMask}`, which is brittle string templating around a value the library already knows.The
Formsuffix matches the existingcorrectForm()/canonicalForm()/reverseForm()family — these are the methods that return strings rather thanAddress4/Address6instances.The result round-trips through the
Address4/Address6constructor, sonew Address4(addr.networkForm())reproduces the network address with its prefix intact.Test plan
Address4.networkForm()covering /0, /8, the issue What is the point of the mask method? #39 example, /24, the no-subnet (default /32) case, and a constructor round-tripAddress6.networkForm()covering /0, /32, /64, the no-subnet (default /128) case, and a constructor round-tripnpm run docs