MCPcopy Create free account
hub / github.com/UnsignedInt8/LightSword / toBytes

Function toBytes

test/ip.js:47–64  ·  view source on GitHub ↗
(fullAddr)

Source from the content-addressed store, hash-verified

45 });
46
47 function toBytes(fullAddr) {
48
49 let type = net.isIP(fullAddr);
50 let addr = [];
51 switch (type) {
52 case 4:
53 addr = fullAddr.split('.').select(s => Number.parseInt(s)).toArray();
54 break;
55 case 6:
56 addr = fullAddr.split(':').select(s => [Number.parseInt(s.substr(0, 2), 16), Number.parseInt(s.substr(2, 2), 16)]).aggregate((c, n) => c.concat(n));
57 break;
58 case 0:
59 fullAddr.each((c, i) => addr.push(fullAddr.charCodeAt(i)));
60 break;
61 }
62
63 return addr;
64 }
65});

Callers 1

ip.jsFile · 0.85

Calls 4

toArrayMethod · 0.80
selectMethod · 0.80
aggregateMethod · 0.80
eachMethod · 0.80

Tested by

no test coverage detected