Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksi-abr committed Feb 28, 2024
1 parent 337be14 commit 4673184
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 44 deletions.
11 changes: 7 additions & 4 deletions CHANGES.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# 2.0.0
# 2.0.1
* Updated `README`

## 2.0.0
* Refactored to TypeScript

# 1.1.7
## 1.1.7
* Added `LICENSE` file

## 1.1.0
* `isIp()` and `isDecimalIp()` functions
* Added `isIp()` and `isDecimalIp()` functions
* Added tests
* Added `.editorconfig`, `.eslintrc`, and `.jshintrc` files
* `calculate()`, `calculateSubnetMask()`, and `calculateCIDRPrefix()` now accept IPs in string and number format

## 1.0.0
Initial release
* Initial release
58 changes: 18 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
IP Subnet Calculator
=================

JavaScript class for calculating optimal subnet masks for non-standard IP ranges, e.g. `5.4.3.21 - 6.7.8.9`
# IP Subnet Calculator
This module calculates optimal subnet masks for non-standard IP ranges, e.g. `5.4.3.21 - 6.7.8.9`

[View demo](http://salieri.github.io/IPSubnetCalculator/)


What does it do?
----------------

## What does it do?
* Calculates subnet masks for standard and non-standard IP ranges. For example, `10.0.0.5 - 10.0.0.23` will result in `10.0.0.5/32, 10.0.0.6/31, 10.0.0.8/29, 10.0.0.16/29`.
* Calculates CIDR prefixes from subnet masks, e.g. `10.0.0.5/255.255.128.0` will result in `10.0.0.0/17`.
* Calculates subnet masks from CIDR prefixes, e.g. `10.0.0.5/17` will result in `255.255.128.0`.


Support
-------

## Support
* Node.js
* Direct browser use


Installation
------------

## Installation
```sh
> npm install ip-subnet-calculator
```


Node.js
-------
## Node.js
```javascript
import * as IPSubnetCalculator from 'ip-subnet-calculator';
// or: const IPSubnetCalculator = require('ip-subnet-calculator');
Expand All @@ -41,9 +32,7 @@ console.log(IpSubnetCalculator.toDecimal('127.0.0.1')); // 2130706433
console.log(IpSubnetCalculator.calculate('5.4.3.21', '6.7.8.9'));
```


Direct browser use
------------------
## Direct browser use
```html
<script src='lib/ip-subnet-calculator.browser.js'></script>

Expand All @@ -56,10 +45,9 @@ Direct browser use
```
API
---
### IpSubnetCalculator.calculate(ipStart, ipEnd) ###
## API
### IpSubnetCalculator.calculate(ipStart, ipEnd)
Calculates an optimal set of IP masks for the given IP address range.
> *ipStart* (`string|number`) Lowest IP in the range to be calculated in string (`123.123.123.0`) or numeric (`2071689984`) format.
Expand Down Expand Up @@ -103,9 +91,7 @@ Each object in question contain the following properties:
| `invertedMaskStr` | String representation of the inverted prefix mask |
| `invertedSize` | Size of the inverted prefix max in bits |
### IpSubnetCalculator.calculateSubnetMask(ip, prefixSize) ###
### IpSubnetCalculator.calculateSubnetMask(ip, prefixSize)
Calculates a subnet mask from CIDR prefix.
> *ip* (`string|number`) IP address in string or numeric format
Expand All @@ -114,9 +100,7 @@ Calculates a subnet mask from CIDR prefix.
The function returns an object containing full description of the IP range, as described in `IpSubnetCalculator.calculate()`.
### IpSubnetCalculator.calculateCIDRPrefix(ip, subnetMask) ###
### IpSubnetCalculator.calculateCIDRPrefix(ip, subnetMask)
Calculates a CIDR prefix from subnet mask.
> *ip* (`string|number`) IP address in string or numeric format
Expand All @@ -126,29 +110,26 @@ Calculates a CIDR prefix from subnet mask.
The function returns an object containing full description of the IP range, as described in `IpSubnetCalculator.calculate()`.
## Test Functions ##
### IpSubnetCalculator.isIp(ipStr) ###
## Test Functions
### IpSubnetCalculator.isIp(ipStr)
Tests whether string is an IP address.
> *ipStr* (`string`) A string
The function returns a `true` if the string is an IP address, `false` otherwise.
### IpSubnetCalculator.isDecimalIp(ipNum) ###
### IpSubnetCalculator.isDecimalIp(ipNum)
Tests whether `ipNum` is a decimal IP address.
> *ipNum* (`number`) A number
The function returns a `true` if the number is an IP address, `false` otherwise.
## Conversion Functions ##
### IpSubnetCalculator.toDecimal(ip) ###
## Conversion Functions
### IpSubnetCalculator.toDecimal(ip)
Calculates a decimal integer from an string IP address.
> *ip* (`string|number`) IP address in string format
Expand All @@ -159,8 +140,7 @@ of an IP is passed to this function, it is returned unmodified.
If an invalid value is passed to the function, it will `throw` an `Error` object.
### IpSubnetCalculator.toString(num) ###
### IpSubnetCalculator.toString(num)
> *num* (`number|string`) Decimal representation of an IP address.
The function returns an IP address as a string. If a valid string representation of an IP is passed to this function,
Expand All @@ -169,9 +149,7 @@ it is returned unmodified.
If an invalid value is passed to the function, it will `throw` an `Error` object.
License
-------
## License
[MIT](http://opensource.org/licenses/MIT)

0 comments on commit 4673184

Please sign in to comment.