ipaddress 0.2.6 → 0.2.9

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 (57) hide show
  1. package/dist/src/crunchy.d.ts +107 -33
  2. package/dist/src/crunchy.d.ts.map +1 -1
  3. package/dist/src/crunchy.js +274 -142
  4. package/dist/src/ip_bits.d.ts +2 -2
  5. package/dist/src/ip_bits.d.ts.map +1 -1
  6. package/dist/src/ipaddress.d.ts +24 -23
  7. package/dist/src/ipaddress.d.ts.map +1 -1
  8. package/dist/src/ipaddress.js +22 -7
  9. package/dist/src/ipv4.d.ts +3 -3
  10. package/dist/src/ipv4.d.ts.map +1 -1
  11. package/dist/src/ipv4.js +26 -15
  12. package/dist/src/ipv6.d.ts +4 -4
  13. package/dist/src/ipv6.d.ts.map +1 -1
  14. package/dist/src/ipv6.js +1 -1
  15. package/dist/src/ipv6_loopback.d.ts +1 -1
  16. package/dist/src/ipv6_loopback.d.ts.map +1 -1
  17. package/dist/src/ipv6_mapped.d.ts +1 -1
  18. package/dist/src/ipv6_mapped.d.ts.map +1 -1
  19. package/dist/src/ipv6_unspec.d.ts +1 -1
  20. package/dist/src/ipv6_unspec.d.ts.map +1 -1
  21. package/dist/src/prefix128.d.ts +1 -1
  22. package/dist/src/prefix128.d.ts.map +1 -1
  23. package/dist/src/prefix128.js +5 -1
  24. package/dist/src/prefix32.d.ts +1 -1
  25. package/dist/src/prefix32.d.ts.map +1 -1
  26. package/dist/src/prefix32.js +5 -1
  27. package/dist/test/test_crunchy_impls.d.ts +2 -0
  28. package/dist/test/test_crunchy_impls.d.ts.map +1 -0
  29. package/dist/test/test_crunchy_impls.js +150 -0
  30. package/dist/test/test_crunchy_with32bit.d.ts +2 -0
  31. package/dist/test/test_crunchy_with32bit.d.ts.map +1 -0
  32. package/dist/test/{test_crunchy.js → test_crunchy_with32bit.js} +113 -182
  33. package/dist/test/test_ipv4.js +1 -1
  34. package/dist/test/test_ipv6.js +1 -1
  35. package/package.json +10 -9
  36. package/src/crunchy.ts +365 -180
  37. package/src/ip_bits.ts +11 -11
  38. package/src/ipaddress.ts +49 -33
  39. package/src/ipv4.ts +32 -19
  40. package/src/ipv6.ts +6 -6
  41. package/src/ipv6_loopback.ts +1 -1
  42. package/src/ipv6_mapped.ts +1 -1
  43. package/src/ipv6_unspec.ts +1 -1
  44. package/src/prefix128.ts +6 -2
  45. package/src/prefix32.ts +6 -2
  46. package/test/test_crunchy_impls.ts +179 -0
  47. package/test/{test_crunchy.ts → test_crunchy_with32bit.ts} +131 -235
  48. package/test/test_ipaddress.ts +9 -9
  49. package/test/test_ipv4.ts +115 -115
  50. package/test/test_ipv6.ts +62 -62
  51. package/test/test_ipv6_loopback.ts +1 -1
  52. package/test/test_ipv6_mapped.ts +4 -4
  53. package/test/test_ipv6_unspec.ts +1 -1
  54. package/test/test_prefix128.ts +2 -2
  55. package/test/test_prefix32.ts +13 -13
  56. package/dist/test/test_crunchy.d.ts +0 -2
  57. package/dist/test/test_crunchy.d.ts.map +0 -1
@@ -1,105 +1,106 @@
1
- import Crunchy from "../src/crunchy.js";
1
+ import { CrunchyWith32Bit } from "../src/crunchy.js";
2
+ const c32 = new CrunchyWith32Bit();
2
3
  describe("#compare", function () {
3
4
  it("Should confirm equality", function () {
4
- const x = Crunchy.from_string("12345678901234567890");
5
- const y = Crunchy.from_string("12345678901234567890");
5
+ const x = c32.from_string("12345678901234567890");
6
+ const y = c32.from_string("12345678901234567890");
6
7
  assert.isTrue(x.eq(y));
7
8
  // this.done();
8
9
  });
9
10
  it("Should find first is greater than second", function () {
10
- const x = Crunchy.from_string("12345678901234567890");
11
- const y = Crunchy.from_string("1234567890");
11
+ const x = c32.from_string("12345678901234567890");
12
+ const y = c32.from_string("1234567890");
12
13
  assert.isTrue(x.gt(y));
13
14
  // this.done();
14
15
  });
15
16
  it("Should find first is less than second", function () {
16
- const x = Crunchy.from_string("1234567890");
17
- const y = Crunchy.from_string("12345678901234567890");
17
+ const x = c32.from_string("1234567890");
18
+ const y = c32.from_string("12345678901234567890");
18
19
  assert.isTrue(x.lt(y));
19
20
  // this.done();
20
21
  });
21
22
  });
22
23
  describe("#add", function () {
23
24
  it("Should add numbers", function () {
24
- const x = Crunchy.from_8bit([242, 62]);
25
- const y = Crunchy.from_8bit([42, 2]);
25
+ const x = CrunchyWith32Bit.from_8bit([242, 62]);
26
+ const y = CrunchyWith32Bit.from_8bit([42, 2]);
26
27
  assert.deepEqual(x.add(y).to_8bit(), [1, 28, 64]);
27
28
  // x.should.eql([242, 62]);
28
29
  // y.should.eql([42, 2]);
29
30
  });
30
31
  it("Should add numbers, first longer than second", function () {
31
- const x = Crunchy.from_8bit([26, 255, 230, 17]);
32
- const y = Crunchy.from_8bit([42, 34]);
32
+ const x = CrunchyWith32Bit.from_8bit([26, 255, 230, 17]);
33
+ const y = CrunchyWith32Bit.from_8bit([42, 34]);
33
34
  assert.deepEqual(x.add(y).to_8bit(), [27, 0, 16, 51]);
34
35
  // x, [26, 255, 230, 17]);
35
36
  // y.should.eql([42, 34]);
36
37
  });
37
38
  it("Should add numbers, second longer than first", function () {
38
- const x = Crunchy.from_8bit([234, 34]);
39
- const y = Crunchy.from_8bit([255, 255, 230, 17]);
39
+ const x = CrunchyWith32Bit.from_8bit([234, 34]);
40
+ const y = CrunchyWith32Bit.from_8bit([255, 255, 230, 17]);
40
41
  assert.deepEqual(x.add(y).to_8bit(), [1, 0, 0, 208, 51]);
41
42
  // x.should.eql([234, 34]);
42
43
  // y.should.eql([255, 255, 230, 17]);
43
44
  });
44
45
  it("Should add two identical numbers", function () {
45
- const x = Crunchy.from_8bit([255, 255, 255, 255, 255, 255]);
46
- const y = Crunchy.from_8bit([255, 255, 255, 255, 255, 255]);
46
+ const x = CrunchyWith32Bit.from_8bit([255, 255, 255, 255, 255, 255]);
47
+ const y = CrunchyWith32Bit.from_8bit([255, 255, 255, 255, 255, 255]);
47
48
  assert.deepEqual(x.add(y).to_8bit(), [1, 255, 255, 255, 255, 255, 254]);
48
49
  // x.should.eql([255, 255, 255, 255, 255, 255]);
49
50
  // y.should.eql([255, 255, 255, 255, 255, 255]);
50
51
  });
51
52
  it("Should add positive to negative number expecting positive result", function () {
52
- const x = Crunchy.from_8bit([51, 254, 144, 207]);
53
- const y = Crunchy.from_8bit([-20, 89, 145, 32]);
53
+ const x = CrunchyWith32Bit.from_8bit([51, 254, 144, 207]);
54
+ const y = CrunchyWith32Bit.from_8bit([-20, 89, 145, 32]);
54
55
  assert.deepEqual(x.add(y).to_8bit(), [31, 164, 255, 175]);
55
56
  // x.should.eql([51, 254, 144, 207]);
56
57
  // y.should.eql([-20, 89, 145, 32]);
57
58
  });
58
59
  it("Should add positive to negative number expecting negative result", function () {
59
- const x = Crunchy.from_8bit([242, 62]);
60
- const y = Crunchy.from_8bit([-242, 64]);
60
+ const x = CrunchyWith32Bit.from_8bit([242, 62]);
61
+ const y = CrunchyWith32Bit.from_8bit([-242, 64]);
61
62
  assert.deepEqual(x.add(y).to_8bit(), [-2]);
62
63
  // x.should.eql([242, 62]);
63
64
  // y.should.eql([-242, 64]);
64
65
  });
65
66
  it("Should add negative to positive number expecting positive result", function () {
66
- const x = Crunchy.from_8bit([-42, 2]);
67
- const y = Crunchy.from_8bit([242, 62]);
67
+ const x = CrunchyWith32Bit.from_8bit([-42, 2]);
68
+ const y = CrunchyWith32Bit.from_8bit([242, 62]);
68
69
  assert.deepEqual(x.add(y).to_8bit(), [200, 60]);
69
70
  // x, [-42, 2]);
70
71
  // y, [242, 62]);
71
72
  });
72
73
  it("Should add negative to positive number expecting negative result", function () {
73
- const x = Crunchy.from_8bit([-42, 2]);
74
- const y = Crunchy.from_8bit([42, 0]);
74
+ const x = CrunchyWith32Bit.from_8bit([-42, 2]);
75
+ const y = CrunchyWith32Bit.from_8bit([42, 0]);
75
76
  assert.deepEqual(x.add(y).to_8bit(), [-2]);
76
77
  // x, [-42, 2]);
77
78
  // y, [42, 0]);
78
79
  });
79
80
  it("Should add two negative numbers expecting negative result", function () {
80
- const x = Crunchy.from_8bit([-242, 62]);
81
- const y = Crunchy.from_8bit([-42, 2]);
81
+ const x = CrunchyWith32Bit.from_8bit([-242, 62]);
82
+ const y = CrunchyWith32Bit.from_8bit([-42, 2]);
82
83
  assert.deepEqual(x.add(y).to_8bit(), [-1, 28, 64]);
83
84
  // x, [-242, 62]);
84
85
  // y, [-42, 2]);
85
86
  });
86
87
  it("Should add zero to number", function () {
87
- const x = Crunchy.from_8bit([26, 255, 230, 17]);
88
- const y = Crunchy.from_8bit([0]);
88
+ const x = CrunchyWith32Bit.from_8bit([26, 255, 230, 17]);
89
+ const y = CrunchyWith32Bit.from_8bit([0]);
89
90
  assert.deepEqual(x.add(y).to_8bit(), [26, 255, 230, 17]);
90
91
  // x, [26, 255, 230, 17]);
91
92
  // y, [0]);
92
93
  });
93
94
  it("Should add number to zero", function () {
94
- const x = Crunchy.from_8bit([0]);
95
- const y = Crunchy.from_8bit([43, 123, 200, 1]);
95
+ const x = CrunchyWith32Bit.from_8bit([0]);
96
+ const y = CrunchyWith32Bit.from_8bit([43, 123, 200, 1]);
96
97
  assert.deepEqual(x.add(y).to_8bit(), [43, 123, 200, 1]);
97
98
  // x, [0]);
98
99
  // y, [43, 123, 200, 1]);
99
100
  });
100
101
  it("Should add two zeros", function () {
101
- const x = Crunchy.from_8bit([0]);
102
- const y = Crunchy.from_8bit([0]);
102
+ const x = CrunchyWith32Bit.from_8bit([0]);
103
+ const y = CrunchyWith32Bit.from_8bit([0]);
103
104
  assert.deepEqual(x.add(y).to_8bit(), [0]);
104
105
  // x.should.eql([0]);
105
106
  // y.should.eql([0]);
@@ -108,9 +109,9 @@ describe("#add", function () {
108
109
  describe("#add-from_string", function () {
109
110
  it("Should add numbers", function () {
110
111
  // console.log(new Date());
111
- const x = Crunchy.from_string("12345678911234567891");
112
+ const x = c32.from_string("12345678911234567891");
112
113
  // console.log(new Date());
113
- const y = Crunchy.from_string("12345678901234567890");
114
+ const y = c32.from_string("12345678901234567890");
114
115
  // console.log(new Date(), x, y);
115
116
  // console.log("addddddd:", new Date(), x, x.toString(), y, y.toString(), x.add(y).toString());
116
117
  assert.equal(x.add(y).toString(), "24691357812469135781");
@@ -118,118 +119,118 @@ describe("#add-from_string", function () {
118
119
  // this.done();
119
120
  });
120
121
  it("Should add numbers, first longer than second", function () {
121
- const x = Crunchy.from_string("12345678901234567890");
122
- const y = Crunchy.from_string("1234567890");
122
+ const x = c32.from_string("12345678901234567890");
123
+ const y = c32.from_string("1234567890");
123
124
  assert.equal(x.add(y).toString(), "12345678902469135780");
124
125
  // this.done();
125
126
  });
126
127
  it("Should add numbers, second longer than first", function () {
127
- const x = Crunchy.from_string("1234567890");
128
- const y = Crunchy.from_string("12345678901234567890");
128
+ const x = c32.from_string("1234567890");
129
+ const y = c32.from_string("12345678901234567890");
129
130
  assert.equal(x.add(y).toString(), "12345678902469135780");
130
131
  // this.done();
131
132
  });
132
133
  it("Should add two identical numbers", function () {
133
- const x = Crunchy.from_string("12345678901234567890");
134
- const y = Crunchy.from_string("12345678901234567890");
134
+ const x = c32.from_string("12345678901234567890");
135
+ const y = c32.from_string("12345678901234567890");
135
136
  assert.equal(x.add(y).toString(), "24691357802469135780");
136
137
  // this.done();
137
138
  });
138
139
  it("Should add zero to number", function () {
139
- const x = Crunchy.from_string("12345678901234567890");
140
- const y = Crunchy.from_string("0");
140
+ const x = c32.from_string("12345678901234567890");
141
+ const y = c32.from_string("0");
141
142
  assert.equal(x.add(y).toString(), "12345678901234567890");
142
143
  // this.done();
143
144
  });
144
145
  it("Should add number to zero", function () {
145
- const x = Crunchy.from_string("0");
146
- const y = Crunchy.from_string("12345678901234567890");
146
+ const x = c32.from_string("0");
147
+ const y = c32.from_string("12345678901234567890");
147
148
  assert.equal(x.add(y).toString(), "12345678901234567890");
148
149
  // this.done();
149
150
  });
150
151
  it("Should add two zeros", function () {
151
- const x = Crunchy.from_string("0");
152
- const y = Crunchy.from_string("0");
152
+ const x = c32.from_string("0");
153
+ const y = c32.from_string("0");
153
154
  assert.equal(x.add(y).toString(), "0");
154
155
  // this.done();
155
156
  });
156
157
  });
157
158
  describe("#sub", function () {
158
159
  it("Should subtract numbers", function () {
159
- const x = Crunchy.from_8bit([170, 1, 79, 119, 242, 62]);
160
- const y = Crunchy.from_8bit([17, 241, 123, 250, 42, 2]);
160
+ const x = CrunchyWith32Bit.from_8bit([170, 1, 79, 119, 242, 62]);
161
+ const y = CrunchyWith32Bit.from_8bit([17, 241, 123, 250, 42, 2]);
161
162
  // console.log("Should subtract numbers:", x, y, x.sub(y));
162
163
  assert.deepEqual(x.sub(y).to_8bit(), [152, 15, 211, 125, 200, 60]);
163
164
  // x.to_8bit().should.eql([170, 1, 79, 119, 242, 62]);
164
165
  // y.should.eql([17, 241, 123, 250, 42, 2]);
165
166
  });
166
167
  it("Should subtract one", function () {
167
- const x = Crunchy.from_8bit([240, 0, 0, 0, 0, 0]);
168
- const y = Crunchy.from_8bit([1]);
168
+ const x = CrunchyWith32Bit.from_8bit([240, 0, 0, 0, 0, 0]);
169
+ const y = CrunchyWith32Bit.from_8bit([1]);
169
170
  assert.deepEqual(x.sub(y).to_8bit(), [239, 255, 255, 255, 255, 255]);
170
171
  // x.should.eql([240, 0, 0, 0, 0, 0]);
171
172
  // y.should.eql([1]);
172
173
  });
173
174
  it("Should subtract numbers expecting negative result", function () {
174
- const x = Crunchy.from_8bit([26]);
175
- const y = Crunchy.from_8bit([255]);
175
+ const x = CrunchyWith32Bit.from_8bit([26]);
176
+ const y = CrunchyWith32Bit.from_8bit([255]);
176
177
  assert.deepEqual(x.sub(y).to_8bit(), [-229]);
177
178
  // x.should.eql([26]);
178
179
  // y.should.eql([255]);
179
180
  });
180
181
  it("Should subtract numbers expecting negative result", function () {
181
- const x = Crunchy.from_8bit([188, 196]);
182
- const y = Crunchy.from_8bit([188, 197]);
182
+ const x = CrunchyWith32Bit.from_8bit([188, 196]);
183
+ const y = CrunchyWith32Bit.from_8bit([188, 197]);
183
184
  assert.deepEqual(x.sub(y).to_8bit(), [-1]);
184
185
  // x.should.eql([188, 196]);
185
186
  // y.should.eql([188, 197]);
186
187
  });
187
188
  it("Should subtract negative number from positive", function () {
188
- const x = Crunchy.from_8bit([240, 0, 0, 0, 0, 0]);
189
- const y = Crunchy.from_8bit([-1]);
189
+ const x = CrunchyWith32Bit.from_8bit([240, 0, 0, 0, 0, 0]);
190
+ const y = CrunchyWith32Bit.from_8bit([-1]);
190
191
  // console.log("negative:", x, y, x.sub(y));
191
192
  assert.deepEqual(x.sub(y).to_8bit(), [240, 0, 0, 0, 0, 1]);
192
193
  // x.should.eql([240, 0, 0, 0, 0, 0]);
193
194
  // y.should.eql([-1]);
194
195
  });
195
196
  it("Should subtract positive number from negative", function () {
196
- const x = Crunchy.from_8bit([-240, 0, 0, 0, 0, 0]);
197
- const y = Crunchy.from_8bit([1]);
197
+ const x = CrunchyWith32Bit.from_8bit([-240, 0, 0, 0, 0, 0]);
198
+ const y = CrunchyWith32Bit.from_8bit([1]);
198
199
  assert.deepEqual(x.sub(y).to_8bit(), [-240, 0, 0, 0, 0, 1]);
199
200
  // x.should.eql([-240, 0, 0, 0, 0, 0]);
200
201
  // y.should.eql([1]);
201
202
  });
202
203
  it("Should subtract two negative numbers", function () {
203
- const x = Crunchy.from_8bit([-240, 0, 0, 0, 0, 0]);
204
- const y = Crunchy.from_8bit([-1]);
204
+ const x = CrunchyWith32Bit.from_8bit([-240, 0, 0, 0, 0, 0]);
205
+ const y = CrunchyWith32Bit.from_8bit([-1]);
205
206
  assert.deepEqual(x.sub(y).to_8bit(), [-239, 255, 255, 255, 255, 255]);
206
207
  // x.should.eql([-240, 0, 0, 0, 0, 0]);
207
208
  // y.should.eql([-1]);
208
209
  });
209
210
  it("Should subtract two equal numbers expecting zero", function () {
210
- const x = Crunchy.from_8bit([20]);
211
- const y = Crunchy.from_8bit([20]);
211
+ const x = CrunchyWith32Bit.from_8bit([20]);
212
+ const y = CrunchyWith32Bit.from_8bit([20]);
212
213
  assert.deepEqual(x.sub(y).to_8bit(), [0]);
213
214
  // x.should.eql([20]);
214
215
  // y.should.eql([20]);
215
216
  });
216
217
  it("Should subtract zero", function () {
217
- const x = Crunchy.from_8bit([244, 137, 7, 161]);
218
- const y = Crunchy.from_8bit([0]);
218
+ const x = CrunchyWith32Bit.from_8bit([244, 137, 7, 161]);
219
+ const y = CrunchyWith32Bit.from_8bit([0]);
219
220
  assert.deepEqual(x.sub(y).to_8bit(), [244, 137, 7, 161]);
220
221
  // x.should.eql([244, 137, 7, 161]);
221
222
  // y.should.eql([0]);
222
223
  });
223
224
  it("Should subtract zero from zero", function () {
224
- const x = Crunchy.from_8bit([0]);
225
- const y = Crunchy.from_8bit([0]);
225
+ const x = CrunchyWith32Bit.from_8bit([0]);
226
+ const y = CrunchyWith32Bit.from_8bit([0]);
226
227
  assert.deepEqual(x.sub(y).to_8bit(), [0]);
227
228
  // x.should.eql([0]);
228
229
  // y.should.eql([0]);
229
230
  });
230
231
  it("Should subtract from zero", function () {
231
- const x = Crunchy.from_8bit([0]);
232
- const y = Crunchy.from_8bit([15]);
232
+ const x = CrunchyWith32Bit.from_8bit([0]);
233
+ const y = CrunchyWith32Bit.from_8bit([15]);
233
234
  assert.deepEqual(x.sub(y).to_8bit(), [-15]);
234
235
  // x.should.eql([0]);
235
236
  // y.should.eql([15]);
@@ -237,215 +238,145 @@ describe("#sub", function () {
237
238
  });
238
239
  describe("#mul", function () {
239
240
  it("Should multiply numbers", function () {
240
- const x = Crunchy.from_8bit([162, 51, 95]);
241
- const y = Crunchy.from_8bit([42, 18, 204]);
241
+ const x = CrunchyWith32Bit.from_8bit([162, 51, 95]);
242
+ const y = CrunchyWith32Bit.from_8bit([42, 18, 204]);
242
243
  assert.deepEqual(x.mul(y).to_8bit(), [26, 168, 86, 115, 157, 180]);
243
244
  });
244
245
  it("Should multiply numbers", function () {
245
- const x = Crunchy.from_8bit([255, 65, 34, 51, 95]);
246
- const y = Crunchy.from_8bit([42, 18, 204]);
246
+ const x = CrunchyWith32Bit.from_8bit([255, 65, 34, 51, 95]);
247
+ const y = CrunchyWith32Bit.from_8bit([42, 18, 204]);
247
248
  assert.deepEqual(x.mul(y).to_8bit(), [41, 243, 109, 152, 188, 115, 157, 180]);
248
249
  });
249
250
  it("Should multiply numbers", function () {
250
- const x = Crunchy.from_8bit([255, 255, 255, 255]);
251
- const y = Crunchy.from_8bit([255, 255, 255, 255]);
251
+ const x = CrunchyWith32Bit.from_8bit([255, 255, 255, 255]);
252
+ const y = CrunchyWith32Bit.from_8bit([255, 255, 255, 255]);
252
253
  assert.deepEqual(x.mul(y).to_8bit(), [255, 255, 255, 254, 0, 0, 0, 1]);
253
254
  });
254
255
  it("Should multiply positive with negative number", function () {
255
- const x = Crunchy.from_8bit([77, 242, 62]);
256
- const y = Crunchy.from_8bit([-42, 2, 113, 43, 57, 65]);
256
+ const x = CrunchyWith32Bit.from_8bit([77, 242, 62]);
257
+ const y = CrunchyWith32Bit.from_8bit([-42, 2, 113, 43, 57, 65]);
257
258
  assert.deepEqual(x.mul(y).to_8bit(), [-12, 202, 124, 133, 146, 125, 36, 79, 190]);
258
259
  });
259
260
  it("Should multiply negative with positive number", function () {
260
- const x = Crunchy.from_8bit([-255, 17, 162, 62]);
261
- const y = Crunchy.from_8bit([255, 17, 162, 62]);
261
+ const x = CrunchyWith32Bit.from_8bit([-255, 17, 162, 62]);
262
+ const y = CrunchyWith32Bit.from_8bit([255, 17, 162, 62]);
262
263
  assert.deepEqual(x.mul(y).to_8bit(), [-254, 36, 34, 110, 119, 14, 135, 4]);
263
264
  });
264
265
  it("Should multiply two negative numbers", function () {
265
- const x = Crunchy.from_8bit([-162, 51, 95]);
266
- const y = Crunchy.from_8bit([-42, 18, 204]);
266
+ const x = CrunchyWith32Bit.from_8bit([-162, 51, 95]);
267
+ const y = CrunchyWith32Bit.from_8bit([-42, 18, 204]);
267
268
  assert.deepEqual(x.mul(y).to_8bit(), [26, 168, 86, 115, 157, 180]);
268
269
  });
269
270
  it("Should multiply by zero", function () {
270
- const x = Crunchy.from_8bit([77, 242, 62]);
271
- const y = Crunchy.from_8bit([0]);
271
+ const x = CrunchyWith32Bit.from_8bit([77, 242, 62]);
272
+ const y = CrunchyWith32Bit.from_8bit([0]);
272
273
  assert.deepEqual(x.mul(y).to_8bit(), [0]);
273
274
  });
274
275
  it("Should multiply zero by number", function () {
275
- const x = Crunchy.from_8bit([0]);
276
- const y = Crunchy.from_8bit([77, 242, 62]);
276
+ const x = CrunchyWith32Bit.from_8bit([0]);
277
+ const y = CrunchyWith32Bit.from_8bit([77, 242, 62]);
277
278
  assert.deepEqual(x.mul(y).to_8bit(), [0]);
278
279
  });
279
280
  it("Should multiply zeros", function () {
280
- const x = Crunchy.from_8bit([0]);
281
- const y = Crunchy.from_8bit([0]);
281
+ const x = CrunchyWith32Bit.from_8bit([0]);
282
+ const y = CrunchyWith32Bit.from_8bit([0]);
282
283
  assert.deepEqual(x.mul(y).to_8bit(), [0]);
283
284
  });
284
285
  });
285
286
  describe("#div", function () {
286
287
  it("Should divide numbers", function () {
287
- const x = Crunchy.from_8bit([52, 155, 168, 23, 6, 85]);
288
- const y = Crunchy.from_8bit([19, 26, 247]);
288
+ const x = CrunchyWith32Bit.from_8bit([52, 155, 168, 23, 6, 85]);
289
+ const y = CrunchyWith32Bit.from_8bit([19, 26, 247]);
289
290
  assert.deepEqual(x.div(y).to_8bit(), [2, 192, 234, 136]);
290
291
  });
291
292
  it("Should divide by one", function () {
292
- const x = Crunchy.from_8bit([15, 127, 73, 1]);
293
- const y = Crunchy.from_8bit([1]);
293
+ const x = CrunchyWith32Bit.from_8bit([15, 127, 73, 1]);
294
+ const y = CrunchyWith32Bit.from_8bit([1]);
294
295
  assert.deepEqual(x.div(y).to_8bit(), [15, 127, 73, 1]);
295
296
  });
296
297
  it("Should divide by self", function () {
297
- const x = Crunchy.from_8bit([15, 127, 73, 1]);
298
- const y = Crunchy.from_8bit([15, 127, 73, 1]);
298
+ const x = CrunchyWith32Bit.from_8bit([15, 127, 73, 1]);
299
+ const y = CrunchyWith32Bit.from_8bit([15, 127, 73, 1]);
299
300
  assert.deepEqual(x.div(y).to_8bit(), [1]);
300
301
  });
301
302
  it("Should divide negative number", function () {
302
- const x = Crunchy.from_8bit([-170, 153, 136]);
303
- const y = Crunchy.from_8bit([17, 68]);
303
+ const x = CrunchyWith32Bit.from_8bit([-170, 153, 136]);
304
+ const y = CrunchyWith32Bit.from_8bit([17, 68]);
304
305
  assert.deepEqual(x.div(y).to_8bit(), [-9, 225]);
305
306
  });
306
307
  it("Should divide by negative number", function () {
307
- const x = Crunchy.from_8bit([170, 153, 136, 119, 102, 85]);
308
- const y = Crunchy.from_8bit([-17, 68]);
308
+ const x = CrunchyWith32Bit.from_8bit([170, 153, 136, 119, 102, 85]);
309
+ const y = CrunchyWith32Bit.from_8bit([-17, 68]);
309
310
  assert.deepEqual(x.div(y).to_8bit(), [-9, 225, 129, 255, 9]);
310
311
  });
311
312
  it("Should divide two negative numbers", function () {
312
- const x = Crunchy.from_8bit([-52, 155, 168, 23, 6, 85]);
313
- const y = Crunchy.from_8bit([-19, 26, 247]);
313
+ const x = CrunchyWith32Bit.from_8bit([-52, 155, 168, 23, 6, 85]);
314
+ const y = CrunchyWith32Bit.from_8bit([-19, 26, 247]);
314
315
  assert.deepEqual(x.div(y).to_8bit(), [2, 192, 234, 136]);
315
316
  });
316
317
  it("Should divide zero", function () {
317
- const x = Crunchy.from_8bit([0]);
318
- const y = Crunchy.from_8bit([17, 68]);
318
+ const x = CrunchyWith32Bit.from_8bit([0]);
319
+ const y = CrunchyWith32Bit.from_8bit([17, 68]);
319
320
  assert.deepEqual(x.div(y).to_8bit(), [0]);
320
321
  });
321
322
  it("Shouldn't divide by zero", function () {
322
- const x = Crunchy.from_8bit([170, 153]);
323
- const y = Crunchy.from_8bit([0]);
323
+ const x = CrunchyWith32Bit.from_8bit([170, 153]);
324
+ const y = CrunchyWith32Bit.from_8bit([0]);
324
325
  assert.isNotOk(x.div(y));
325
326
  });
326
327
  it("Shouldn't divide zero by zero", function () {
327
- const x = Crunchy.from_8bit([0]);
328
- const y = Crunchy.from_8bit([0]);
328
+ const x = CrunchyWith32Bit.from_8bit([0]);
329
+ const y = CrunchyWith32Bit.from_8bit([0]);
329
330
  assert.isNotOk(x.div(y));
330
331
  });
331
332
  });
332
- // describe("#mod", function() {
333
- // it("Should calculate modulo", function() {
334
- // let x = [52, 155, 168, 23, 6, 85],
335
- // y = [19, 26, 247];
336
- // Crunch.mod(x, y).should.eql([10, 237, 29]);
337
- // x.should.eql([52, 155, 168, 23, 6, 85]);
338
- // y.should.eql([19, 26, 247]);
339
- // });
340
- // it("Should calculate modulo of number smaller than modulus", function() {
341
- // let x = [1, 0],
342
- // y = [1, 241];
343
- // Crunch.mod(x, y).should.eql([1, 0]);
344
- // x.should.eql([1, 0]);
345
- // y.should.eql([1, 241]);
346
- // });
347
- // it("Should calculate modulo of modulus", function() {
348
- // let x = [1, 241],
349
- // y = [1, 241];
350
- // Crunch.mod(x, y).should.eql([0]);
351
- // x.should.eql([1, 241]);
352
- // y.should.eql([1, 241]);
353
- // });
354
- // it("Should calculate modulo of zero", function() {
355
- // let x = [0],
356
- // y = [1, 241];
357
- // Crunch.mod(x, y).should.eql([0]);
358
- // x.should.eql([0]);
359
- // y.should.eql([1, 241]);
360
- // });
361
- // // it("Should calculate modulo of negative", function() {
362
- // // let x = [-4],
363
- // // y = [3];
364
- // // Crunch.mod(x, y).should.eql([2]);
365
- // // x.should.eql([-4]);
366
- // // y.should.eql([3]);
367
- // // });
368
- // // it("Should calculate modulo of negative", function() {
369
- // // let x = [ -10, 18 ],
370
- // // y = [ 123 ];
371
- // // Crunch.mod(x, y).should.eql([ 5 ]);
372
- // // x.should.eql([ -10, 18 ]);
373
- // // y.should.eql([ 123 ]);
374
- // // });
375
- // // it("Should calculate modulo of negative", function() {
376
- // // let x = [ -15, 62, 62, 18, 176 ],
377
- // // y = [ 139, 207, 194, 82 ];
378
- // // Crunch.mod(x, y).should.eql([ 12, 123, 46, 72 ]);
379
- // // x.should.eql([ -15, 62, 62, 18, 176 ]);
380
- // // y.should.eql([ 139, 207, 194, 82 ]);
381
- // // });
382
- // });
383
333
  describe("#leftShift", function () {
384
334
  it("Should left shift a number", function () {
385
- const x = Crunchy.from_8bit([22, 11]);
335
+ const x = CrunchyWith32Bit.from_8bit([22, 11]);
386
336
  const s = 5;
387
337
  assert.deepEqual(x.shl(s).to_8bit(), [2, 193, 96]);
388
338
  });
389
339
  it("Should left shift a number more", function () {
390
- const x = Crunchy.from_8bit([1]);
340
+ const x = CrunchyWith32Bit.from_8bit([1]);
391
341
  const s = 64;
392
342
  assert.deepEqual(x.shl(s).to_8bit(), [1, 0, 0, 0, 0, 0, 0, 0, 0]);
393
343
  });
394
344
  it("Should left shift zero", function () {
395
- const x = Crunchy.from_8bit([0]);
345
+ const x = CrunchyWith32Bit.from_8bit([0]);
396
346
  const s = 80;
397
347
  assert.deepEqual(x.shl(s).to_8bit(), [0]);
398
348
  });
399
349
  it("Should left shift negative", function () {
400
- const x = Crunchy.from_8bit([-3]);
350
+ const x = CrunchyWith32Bit.from_8bit([-3]);
401
351
  const s = 8;
402
352
  assert.deepEqual(x.shl(s).to_8bit(), [-3, 0]);
403
353
  });
404
354
  it("Should left shift one", function () {
405
- const x = Crunchy.from_8bit([1, 0, 0, 0, 0]);
355
+ const x = CrunchyWith32Bit.from_8bit([1, 0, 0, 0, 0]);
406
356
  const s = 1;
407
357
  assert.deepEqual(x.shl(s).to_8bit(), [2, 0, 0, 0, 0]);
408
358
  });
409
359
  });
410
360
  describe("#rightShift", function () {
411
361
  it("Should right shift a number to zero", function () {
412
- const x = Crunchy.from_14bit([167837953]);
362
+ const x = CrunchyWith32Bit.from_14bit([167837953]);
413
363
  // assert.deepEqual(x.rsh(32).num, [0]);
414
364
  assert.deepEqual(x.shr(32).num, [0]);
415
365
  assert.deepEqual(x.shr(33).num, [0]);
416
366
  });
417
367
  it("Should right shift a number", function () {
418
- const x = Crunchy.from_8bit([22, 11]);
368
+ const x = CrunchyWith32Bit.from_8bit([22, 11]);
419
369
  const s = 5;
420
370
  assert.deepEqual(x.shr(s).to_8bit(), [176]);
421
371
  });
422
372
  it("Should right shift a number out of existance", function () {
423
- const x = Crunchy.from_8bit([22, 11]);
373
+ const x = CrunchyWith32Bit.from_8bit([22, 11]);
424
374
  const s = 20;
425
375
  assert.deepEqual(x.shr(s).to_8bit(), [0]);
426
376
  });
427
377
  it("Should right shift a negative number", function () {
428
- const x = Crunchy.from_8bit([-3]);
378
+ const x = CrunchyWith32Bit.from_8bit([-3]);
429
379
  const s = 8;
430
380
  assert.deepEqual(x.shr(s).to_8bit(), [-0]);
431
381
  });
432
382
  });
433
- // describe("#parse", function() {
434
- // it("Should convert string to integer", function() {
435
- // let s = "6315359056060240643798024";
436
- // Crunchy.parse(s).to_8bit().should.eql([5, 57, 84, 76, 233, 0, 120, 91, 180, 180, 8]);
437
- // s.should.equal("6315359056060240643798024");
438
- // });
439
- // it("Should convert string negative number to integer", function() {
440
- // let s = "-256";
441
- // Crunchy.parse(s).to_8bit().should.eql([-1, 0]);
442
- // s.should.equal("-256");
443
- // });
444
- // });
445
- // describe("#stringify", function() {
446
- // it("Should convert integer to string", function() {
447
- // let x = [5, 57, 84, 76, 233, 0, 120, 91, 180, 180, 8];
448
- // Crunchy.from_8bit(x).to_8bit().should.equal("6315359056060240643798024");
449
- // x.should.eql([5, 57, 84, 76, 233, 0, 120, 91, 180, 180, 8]);
450
- // });
451
- // });
@@ -230,7 +230,7 @@ describe("Ipv4Test", () => {
230
230
  });
231
231
  it("test_method_size", () => {
232
232
  const ip = IPAddress.parse("10.0.0.1/29");
233
- assertArrayEqual(ip.size().num, Crunchy.parse("8").num);
233
+ assert.isOk(ip.size().eq(Crunchy.parse("8")));
234
234
  });
235
235
  it("test_method_network_u32", () => {
236
236
  assert.equal("2886732288", setup().ip.network().host_address.toString());
@@ -232,7 +232,7 @@ describe("ipv6", () => {
232
232
  "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
233
233
  ];
234
234
  for (let prefix = 0; prefix < 128; ++prefix) {
235
- const nr_networks = 1 << (128 - prefix) % 4;
235
+ const nr_networks = 1 << ((128 - prefix) % 4);
236
236
  for (const adr of test_addrs) {
237
237
  const net_adr = IPAddress.parse(`${adr}/${prefix}`);
238
238
  const ret = net_adr.dns_networks();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ipaddress",
3
- "version": "0.2.6",
3
+ "version": "0.2.9",
4
4
  "description": "ipaddress handles ipv4 and ipv6",
5
5
  "main": "./dist/src/index.js",
6
6
  "type": "module",
@@ -43,16 +43,17 @@
43
43
  ]
44
44
  },
45
45
  "devDependencies": {
46
- "@types/node": "^24.0.7",
47
- "eslint": "9.21.0",
48
- "prettier": "^3.6.2",
46
+ "@eslint/js": "^10.0.1",
47
+ "@types/node": "^26.2.0",
48
+ "eslint": "^10.8.1",
49
+ "prettier": "^3.9.6",
49
50
  "standard": "^17.1.2",
50
- "typescript": "^5.8.2",
51
- "vite-tsconfig-paths": "^5.1.4",
52
- "vitest": "^3.2.4"
51
+ "typescript": "^6.0.3",
52
+ "typescript-eslint": "^8.66.0",
53
+ "vite-tsconfig-paths": "^6.1.1",
54
+ "vitest": "^4.1.10"
53
55
  },
54
56
  "dependencies": {
55
- "ts-standard": "^12.0.2",
56
- "typescript-eslint": "^8.35.0"
57
+ "ts-standard": "^12.0.2"
57
58
  }
58
59
  }