MCPcopy Index your code
hub / github.com/tinyhttp/tinyhttp / parseIPNotation

Function parseIPNotation

packages/proxy-addr/src/index.ts:89–115  ·  view source on GitHub ↗
(note: string)

Source from the content-addressed store, hash-verified

87 * @private
88 */
89export function parseIPNotation(note: string) {
90 const pos = note.lastIndexOf('/')
91 const str = pos !== -1 ? note.substring(0, pos) : note
92
93 if (!isip(str)) throw new TypeError('invalid IP address: ' + str)
94
95 let ip = parseip(str)
96
97 if (pos === -1 && ip.kind() === 'ipv6') {
98 ip = ip as IPv6
99
100 if (ip.isIPv4MappedAddress()) ip = ip.toIPv4Address()
101 }
102
103 const max = ip.kind() === 'ipv6' ? 128 : 32
104
105 let range: string | number = pos !== -1 ? note.substring(pos + 1, note.length) : null
106
107 if (range === null) range = max
108 else if (DIGIT_REGEXP.test(range)) range = parseInt(range, 10)
109 else if (ip.kind() === 'ipv4' && isip(range)) range = parseNetmask(range)
110 else range = null
111
112 if (range <= 0 || range > max) throw new TypeError('invalid range on address: ' + note)
113
114 return [ip, range]
115}
116/**
117 * Parse netmask string into CIDR range.
118 *

Callers 1

compileRangeSubnetsFunction · 0.85

Calls 1

parseNetmaskFunction · 0.85

Tested by

no test coverage detected