-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add intToIp converter to network #360
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,13 +2,22 @@ | |||||||||||||
|
||||||||||||||
const os = require('os'); | ||||||||||||||
|
||||||||||||||
// Convert IP string to number | ||||||||||||||
// Signature: [ip] | ||||||||||||||
// ip - <string>, (optional), default: '127.0.0.1', IP address | ||||||||||||||
// Convert IPv4 address from string form to number form | ||||||||||||||
// Signature: IP_string | ||||||||||||||
// IP_string - <string>, (optional), default: '127.0.0.1', IPv4 address in string form | ||||||||||||||
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
// Returns: <number> | ||||||||||||||
const ipToInt = (ip = '127.0.0.1') => | ||||||||||||||
ip.split('.').reduce((res, item) => (res << 8) + +item, 0); | ||||||||||||||
|
||||||||||||||
// Convert IPv4 address from number form to string form | ||||||||||||||
// Signature: IP_number | ||||||||||||||
// IP_number - <number>, (optional), default: 0, IPv4 address in number form | ||||||||||||||
Comment on lines
+12
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
// Returns: <string> | ||||||||||||||
const intToIp = (ipInt = 0) => | ||||||||||||||
[ipInt >>> 24, (ipInt >> 16) & 255, (ipInt >> 8) & 255, ipInt & 255].join( | ||||||||||||||
'.' | ||||||||||||||
); | ||||||||||||||
Comment on lines
+16
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to put 4 parts of address into 4 separate variables and concatenate them without creating array and call join |
||||||||||||||
|
||||||||||||||
let LOCAL_IPS_CACHE; | ||||||||||||||
|
||||||||||||||
// Get local network interfaces | ||||||||||||||
|
@@ -44,6 +53,7 @@ const parseHost = host => { | |||||||||||||
|
||||||||||||||
module.exports = { | ||||||||||||||
ipToInt, | ||||||||||||||
intToIp, | ||||||||||||||
localIPs, | ||||||||||||||
parseHost, | ||||||||||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.