source: node_modules/ip-address/dist/common.js@ 81bc7da

finki-main main
Last change on this file since 81bc7da was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[81bc7da]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.isInSubnet = isInSubnet;
4exports.isCorrect = isCorrect;
5exports.numberToPaddedHex = numberToPaddedHex;
6exports.stringToPaddedHex = stringToPaddedHex;
7exports.testBit = testBit;
8function isInSubnet(address) {
9 if (this.subnetMask < address.subnetMask) {
10 return false;
11 }
12 if (this.mask(address.subnetMask) === address.mask()) {
13 return true;
14 }
15 return false;
16}
17function isCorrect(defaultBits) {
18 return function () {
19 if (this.addressMinusSuffix !== this.correctForm()) {
20 return false;
21 }
22 if (this.subnetMask === defaultBits && !this.parsedSubnet) {
23 return true;
24 }
25 return this.parsedSubnet === String(this.subnetMask);
26 };
27}
28function numberToPaddedHex(number) {
29 return number.toString(16).padStart(2, '0');
30}
31function stringToPaddedHex(numberString) {
32 return numberToPaddedHex(parseInt(numberString, 10));
33}
34/**
35 * @param binaryValue Binary representation of a value (e.g. `10`)
36 * @param position Byte position, where 0 is the least significant bit
37 */
38function testBit(binaryValue, position) {
39 const { length } = binaryValue;
40 if (position > length) {
41 return false;
42 }
43 const positionInString = length - position;
44 return binaryValue.substring(positionInString, positionInString + 1) === '1';
45}
46//# sourceMappingURL=common.js.map
Note: See TracBrowser for help on using the repository browser.