ipaddress 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/src/crunchy.d.ts +130 -0
  2. package/dist/src/crunchy.d.ts.map +1 -0
  3. package/dist/src/crunchy.js +616 -0
  4. package/dist/src/index.d.ts +13 -0
  5. package/dist/src/index.d.ts.map +1 -0
  6. package/dist/src/index.js +21 -0
  7. package/{ip_bits.d.ts → dist/src/ip_bits.d.ts} +6 -7
  8. package/dist/src/ip_bits.d.ts.map +1 -0
  9. package/dist/src/ip_bits.js +133 -0
  10. package/{ip_version.d.ts → dist/src/ip_version.d.ts} +2 -1
  11. package/dist/src/ip_version.d.ts.map +1 -0
  12. package/dist/src/ip_version.js +6 -0
  13. package/{ipaddress.d.ts → dist/src/ipaddress.d.ts} +38 -35
  14. package/dist/src/ipaddress.d.ts.map +1 -0
  15. package/dist/src/ipaddress.js +1243 -0
  16. package/dist/src/ipv4.d.ts +15 -0
  17. package/dist/src/ipv4.d.ts.map +1 -0
  18. package/dist/src/ipv4.js +187 -0
  19. package/dist/src/ipv6.d.ts +13 -0
  20. package/dist/src/ipv6.d.ts.map +1 -0
  21. package/dist/src/ipv6.js +190 -0
  22. package/dist/src/ipv6_loopback.d.ts +6 -0
  23. package/dist/src/ipv6_loopback.d.ts.map +1 -0
  24. package/dist/src/ipv6_loopback.js +51 -0
  25. package/dist/src/ipv6_mapped.d.ts +6 -0
  26. package/dist/src/ipv6_mapped.d.ts.map +1 -0
  27. package/dist/src/ipv6_mapped.js +159 -0
  28. package/dist/src/ipv6_unspec.d.ts +6 -0
  29. package/dist/src/ipv6_unspec.d.ts.map +1 -0
  30. package/dist/src/ipv6_unspec.js +57 -0
  31. package/{prefix.d.ts → dist/src/prefix.d.ts} +10 -7
  32. package/dist/src/prefix.d.ts.map +1 -0
  33. package/dist/src/prefix.js +142 -0
  34. package/dist/src/prefix128.d.ts +7 -0
  35. package/dist/src/prefix128.d.ts.map +1 -0
  36. package/dist/src/prefix128.js +39 -0
  37. package/dist/src/prefix32.d.ts +7 -0
  38. package/dist/src/prefix32.d.ts.map +1 -0
  39. package/dist/src/prefix32.js +29 -0
  40. package/dist/src/rle.d.ts +19 -0
  41. package/dist/src/rle.d.ts.map +1 -0
  42. package/dist/src/rle.js +73 -0
  43. package/dist/test/test_crunchy_impls.d.ts +2 -0
  44. package/dist/test/test_crunchy_impls.d.ts.map +1 -0
  45. package/dist/test/test_crunchy_impls.js +150 -0
  46. package/dist/test/test_crunchy_with32bit.d.ts +2 -0
  47. package/dist/test/test_crunchy_with32bit.d.ts.map +1 -0
  48. package/dist/test/test_crunchy_with32bit.js +382 -0
  49. package/dist/test/test_ipaddress.d.ts +2 -0
  50. package/dist/test/test_ipaddress.d.ts.map +1 -0
  51. package/dist/test/test_ipaddress.js +182 -0
  52. package/dist/test/test_ipv4.d.ts +2 -0
  53. package/dist/test/test_ipv4.d.ts.map +1 -0
  54. package/dist/test/test_ipv4.js +561 -0
  55. package/dist/test/test_ipv6.d.ts +2 -0
  56. package/dist/test/test_ipv6.d.ts.map +1 -0
  57. package/dist/test/test_ipv6.js +313 -0
  58. package/dist/test/test_ipv6_loopback.d.ts +2 -0
  59. package/dist/test/test_ipv6_loopback.d.ts.map +1 -0
  60. package/dist/test/test_ipv6_loopback.js +40 -0
  61. package/dist/test/test_ipv6_mapped.d.ts +2 -0
  62. package/dist/test/test_ipv6_mapped.d.ts.map +1 -0
  63. package/dist/test/test_ipv6_mapped.js +89 -0
  64. package/dist/test/test_ipv6_unspec.d.ts +2 -0
  65. package/dist/test/test_ipv6_unspec.d.ts.map +1 -0
  66. package/dist/test/test_ipv6_unspec.js +39 -0
  67. package/dist/test/test_prefix128.d.ts +2 -0
  68. package/dist/test/test_prefix128.d.ts.map +1 -0
  69. package/dist/test/test_prefix128.js +35 -0
  70. package/dist/test/test_prefix32.d.ts +2 -0
  71. package/dist/test/test_prefix32.d.ts.map +1 -0
  72. package/dist/test/test_prefix32.js +126 -0
  73. package/dist/test/test_rle.d.ts +2 -0
  74. package/dist/test/test_rle.d.ts.map +1 -0
  75. package/dist/test/test_rle.js +141 -0
  76. package/dist/vitest.config.d.ts +3 -0
  77. package/dist/vitest.config.d.ts.map +1 -0
  78. package/dist/vitest.config.js +11 -0
  79. package/package.json +41 -37
  80. package/src/crunchy.ts +731 -0
  81. package/src/index.ts +23 -0
  82. package/src/ip_bits.ts +148 -0
  83. package/src/ip_version.ts +6 -0
  84. package/src/ipaddress.ts +1347 -0
  85. package/src/ipv4.ts +203 -0
  86. package/src/ipv6.ts +202 -0
  87. package/src/ipv6_loopback.ts +55 -0
  88. package/src/ipv6_mapped.ts +163 -0
  89. package/src/ipv6_unspec.ts +59 -0
  90. package/src/prefix.ts +170 -0
  91. package/src/prefix128.ts +42 -0
  92. package/src/prefix32.ts +32 -0
  93. package/src/rle.ts +85 -0
  94. package/test/test_crunchy_impls.ts +179 -0
  95. package/test/test_crunchy_with32bit.ts +510 -0
  96. package/test/test_ipaddress.ts +208 -0
  97. package/test/test_ipv4.ts +596 -0
  98. package/test/test_ipv6.ts +325 -0
  99. package/test/test_ipv6_loopback.ts +52 -0
  100. package/test/test_ipv6_mapped.ts +101 -0
  101. package/test/test_ipv6_unspec.ts +51 -0
  102. package/test/test_prefix128.ts +39 -0
  103. package/test/test_prefix32.ts +130 -0
  104. package/test/test_rle.ts +144 -0
  105. package/LICENSE +0 -20
  106. package/README.md +0 -960
  107. package/crunchy.d.ts +0 -55
  108. package/index.d.ts +0 -12
  109. package/ipaddress.js +0 -2869
  110. package/ipaddress.js.map +0 -1
  111. package/ipv4.d.ts +0 -14
  112. package/ipv6.d.ts +0 -12
  113. package/ipv6_loopback.d.ts +0 -5
  114. package/ipv6_mapped.d.ts +0 -5
  115. package/ipv6_unspec.d.ts +0 -5
  116. package/prefix128.d.ts +0 -6
  117. package/prefix32.d.ts +0 -6
  118. package/rle.d.ts +0 -14
@@ -0,0 +1,130 @@
1
+ import Prefix32 from "../src/prefix32.js";
2
+ import IPAddress from "../src/ipaddress.js";
3
+ import Ipv4 from "../src/ipv4.js";
4
+ import Crunchy from "../src/crunchy.js";
5
+
6
+ class Prefix32Test {
7
+ netmask0 = "0.0.0.0";
8
+ netmask8 = "255.0.0.0";
9
+ netmask16 = "255.255.0.0";
10
+ netmask24 = "255.255.255.0";
11
+ netmask30 = "255.255.255.252";
12
+ netmasks: string[] = [];
13
+ prefix_hash: [string, number][] = [];
14
+ octets_hash: [number[], number][] = [];
15
+ u32_hash: [number, Crunchy][] = [];
16
+ }
17
+
18
+ describe("prefix32", () => {
19
+ function assertArrayEqual<T>(a: T[], b: T[]): void {
20
+ assert.equal(a.length, b.length, "length missmatch");
21
+ for (let i = 0; i < a.length; ++i) {
22
+ assert.equal(a[i], b[i]);
23
+ }
24
+ }
25
+ function setup(): Prefix32Test {
26
+ const p32t = new Prefix32Test();
27
+ p32t.netmasks.push(p32t.netmask0);
28
+ p32t.netmasks.push(p32t.netmask8);
29
+ p32t.netmasks.push(p32t.netmask16);
30
+ p32t.netmasks.push(p32t.netmask24);
31
+ p32t.netmasks.push(p32t.netmask30);
32
+ p32t.prefix_hash.push(["0.0.0.0", 0]);
33
+ p32t.prefix_hash.push(["255.0.0.0", 8]);
34
+ p32t.prefix_hash.push(["255.255.0.0", 16]);
35
+ p32t.prefix_hash.push(["255.255.255.0", 24]);
36
+ p32t.prefix_hash.push(["255.255.255.252", 30]);
37
+ p32t.octets_hash.push([[0, 0, 0, 0], 0]);
38
+ p32t.octets_hash.push([[255, 0, 0, 0], 8]);
39
+ p32t.octets_hash.push([[255, 255, 0, 0], 16]);
40
+ p32t.octets_hash.push([[255, 255, 255, 0], 24]);
41
+ p32t.octets_hash.push([[255, 255, 255, 252], 30]);
42
+ p32t.u32_hash.push([0, Crunchy.zero()]);
43
+ p32t.u32_hash.push([8, Crunchy.parse("4278190080")]);
44
+ p32t.u32_hash.push([16, Crunchy.parse("4294901760")]);
45
+ p32t.u32_hash.push([24, Crunchy.parse("4294967040")]);
46
+ p32t.u32_hash.push([30, Crunchy.parse("4294967292")]);
47
+ return p32t;
48
+ }
49
+
50
+ it("test_attributes", () => {
51
+ for (const e of setup().prefix_hash) {
52
+ const prefix = Prefix32.create(e[1]);
53
+ assert.equal(e[1], prefix!.num);
54
+ }
55
+ });
56
+
57
+ it("test_parse_netmask_to_prefix", () => {
58
+ for (const e of setup().prefix_hash) {
59
+ const netmask = e[0];
60
+ const num = e[1];
61
+ // console.log(e);
62
+ const prefix = IPAddress.parse_netmask_to_prefix(netmask);
63
+ assert.equal(num, prefix);
64
+ }
65
+ });
66
+ it("test_method_to_ip", () => {
67
+ for (const hash of setup().prefix_hash) {
68
+ const netmask = hash[0];
69
+ const num = hash[1];
70
+ const prefix = Prefix32.create(num);
71
+ assert.equal(netmask, prefix!.to_ip_str());
72
+ }
73
+ });
74
+ it("test_method_to_s", () => {
75
+ const prefix = Prefix32.create(8);
76
+ assert.equal("8", prefix!.to_s());
77
+ });
78
+ it("test_method_bits", () => {
79
+ const prefix = Prefix32.create(16);
80
+ assert.equal("11111111111111110000000000000000", prefix!.bits());
81
+ });
82
+ it("test_method_to_u32", () => {
83
+ for (const i of setup().u32_hash) {
84
+ const num = i[0];
85
+ const ip32 = i[1];
86
+ assert.isTrue(ip32.eq(Prefix32.create(num)!.netmask()));
87
+ }
88
+ });
89
+ it("test_method_plus", () => {
90
+ const p1 = Prefix32.create(8);
91
+ const p2 = Prefix32.create(10);
92
+ assert.equal(18, p1!.add_prefix(p2!).num);
93
+ assert.equal(12, p1!.add(4).num);
94
+ });
95
+ it("test_method_minus", () => {
96
+ const p1 = Prefix32.create(8);
97
+ const p2 = Prefix32.create(24);
98
+ assert.equal(16, p1!.sub_prefix(p2!).num);
99
+ assert.equal(16, p2!.sub_prefix(p1!).num);
100
+ assert.equal(20, p2!.sub(4).num);
101
+ });
102
+ it("test_initialize", () => {
103
+ assert.isNull(Prefix32.create(33));
104
+ assert.isOk(Prefix32.create(8));
105
+ });
106
+ it("test_method_octets", () => {
107
+ for (const i of setup().octets_hash) {
108
+ const arr = i[0];
109
+ const pref = i[1];
110
+ const prefix = Prefix32.create(pref);
111
+ assertArrayEqual(prefix!.ip_bits.parts(prefix!.netmask()), arr);
112
+ }
113
+ });
114
+ it("test_method_brackets", () => {
115
+ for (const i of setup().octets_hash) {
116
+ const arr = i[0];
117
+ const pref = i[1];
118
+ const prefix = Prefix32.create(pref);
119
+ for (let index = 0; index < arr.length; ++index) {
120
+ // console.log("xxxx", prefix.netmask());
121
+ assert.equal(prefix!.ip_bits.parts(prefix!.netmask())[index], arr[index]);
122
+ }
123
+ }
124
+ });
125
+ it("test_method_hostmask", () => {
126
+ const prefix = Prefix32.create(8);
127
+ // console.log(">>>>", prefix.host_mask());
128
+ assert.equal("0.255.255.255", Ipv4.from_number(prefix!.host_mask(), 0)!.to_s());
129
+ });
130
+ });
@@ -0,0 +1,144 @@
1
+ import Rle from "../src/rle.js";
2
+
3
+ function assert_rle(left: Rle[], right: Rle[]) {
4
+ assert.equal(left.length, right.length, "array length missmatch");
5
+ for (let i = 0; i < left.length; ++i) {
6
+ assert.isOk(left[i].eq(right[i]), `left:${left[i].toString()} right:${right[i].toString()}`);
7
+ }
8
+ }
9
+
10
+ describe("rle", () => {
11
+ it("test_rle", () => {
12
+ const empty: number[] = [];
13
+ assert_rle(Rle.code(empty), []);
14
+ assert_rle(Rle.code([4711]), [
15
+ new Rle({
16
+ part: 4711,
17
+ pos: 0,
18
+ cnt: 1,
19
+ max: true,
20
+ }),
21
+ ]);
22
+ assert_rle(Rle.code([4711, 4711]), [
23
+ new Rle({
24
+ part: 4711,
25
+ pos: 0,
26
+ cnt: 2,
27
+ max: true,
28
+ }),
29
+ ]);
30
+ assert_rle(Rle.code([4711, 4711, 4811]), [
31
+ new Rle({
32
+ part: 4711,
33
+ pos: 0,
34
+ cnt: 2,
35
+ max: true,
36
+ }),
37
+ new Rle({
38
+ part: 4811,
39
+ pos: 1,
40
+ cnt: 1,
41
+ max: true,
42
+ }),
43
+ ]);
44
+ assert_rle(Rle.code([4711, 4711, 4811, 4711, 4711]), [
45
+ new Rle({
46
+ part: 4711,
47
+ pos: 0,
48
+ cnt: 2,
49
+ max: true,
50
+ }),
51
+ new Rle({
52
+ part: 4811,
53
+ pos: 1,
54
+ cnt: 1,
55
+ max: true,
56
+ }),
57
+ new Rle({
58
+ part: 4711,
59
+ pos: 2,
60
+ cnt: 2,
61
+ max: true,
62
+ }),
63
+ ]);
64
+ assert_rle(Rle.code([4711, 4711, 4711, 4811, 4711, 4711]), [
65
+ new Rle({
66
+ part: 4711,
67
+ pos: 0,
68
+ cnt: 3,
69
+ max: true,
70
+ }),
71
+ new Rle({
72
+ part: 4811,
73
+ pos: 1,
74
+ cnt: 1,
75
+ max: true,
76
+ }),
77
+ new Rle({
78
+ part: 4711,
79
+ pos: 2,
80
+ cnt: 2,
81
+ max: false,
82
+ }),
83
+ ]);
84
+ assert_rle(Rle.code([4711, 4711, 4711, 4811, 4711, 4711, 4911, 4911, 4911]), [
85
+ new Rle({
86
+ part: 4711,
87
+ pos: 0,
88
+ cnt: 3,
89
+ max: true,
90
+ }),
91
+ new Rle({
92
+ part: 4811,
93
+ pos: 1,
94
+ cnt: 1,
95
+ max: true,
96
+ }),
97
+ new Rle({
98
+ part: 4711,
99
+ pos: 2,
100
+ cnt: 2,
101
+ max: false,
102
+ }),
103
+ new Rle({
104
+ part: 4911,
105
+ pos: 3,
106
+ cnt: 3,
107
+ max: true,
108
+ }),
109
+ ]);
110
+
111
+ assert_rle(Rle.code([0x2001, 0x888, 0, 0x6630, 0, 0, 0, 0]), [
112
+ new Rle({
113
+ part: 0x2001,
114
+ pos: 0,
115
+ cnt: 1,
116
+ max: true,
117
+ }),
118
+ new Rle({
119
+ part: 0x888,
120
+ pos: 1,
121
+ cnt: 1,
122
+ max: true,
123
+ }),
124
+ new Rle({
125
+ part: 0,
126
+ pos: 2,
127
+ cnt: 1,
128
+ max: false,
129
+ }),
130
+ new Rle({
131
+ part: 0x6630,
132
+ pos: 3,
133
+ cnt: 1,
134
+ max: true,
135
+ }),
136
+ new Rle({
137
+ part: 0,
138
+ pos: 4,
139
+ cnt: 4,
140
+ max: true,
141
+ }),
142
+ ]);
143
+ });
144
+ });
package/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009-2016 Marco Ceresa,Meno Abels
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.