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
package/src/index.ts ADDED
@@ -0,0 +1,23 @@
1
+ // import Crunchy from './crunchy.js'
2
+ // import Ipv4 from './ipv4.js'
3
+ // import Ipv6 from './ipv6.js'
4
+ // import Prefix from './prefix.js'
5
+ // import Ipv6Mapped from './ipv6_mapped.js'
6
+ // import Ipv6Loopback from './ipv6_loopback.js'
7
+ // import Ipv6Unspec from './ipv6_unspec.js'
8
+ import IPAddress from "./ipaddress.js";
9
+
10
+ export * from "./crunchy.js";
11
+ export * from "./prefix.js";
12
+ export * from "./ip_bits.js";
13
+ export * from "./ip_version.js";
14
+ export * from "./ipaddress.js";
15
+ export * from "./ipv4.js";
16
+ export * from "./ipv6.js";
17
+ export * from "./ipv6_mapped.js";
18
+ export * from "./ipv6_loopback.js";
19
+ export * from "./ipv6_unspec.js";
20
+
21
+ // export = Crunchy;
22
+ export default IPAddress;
23
+ // declare let Ip: IPAddress;
package/src/ip_bits.ts ADDED
@@ -0,0 +1,148 @@
1
+ import Crunchy from "./crunchy.js";
2
+
3
+ import Rle from "./rle.js";
4
+
5
+ import IpVersion from "./ip_version.js";
6
+
7
+ export type ToString = (source: IpBits, num: Crunchy) => string;
8
+
9
+ // #[derive(Debug, Clone)]
10
+ export class IpBits {
11
+ version!: IpVersion;
12
+ vt_as_compressed_string!: ToString;
13
+ vt_as_uncompressed_string!: ToString;
14
+ bits!: number;
15
+ part_bits!: number;
16
+ dns_bits!: number;
17
+ rev_domain!: string;
18
+ part_mod!: number;
19
+ host_ofs!: Crunchy; // ipv4=1, ipv6=0
20
+
21
+ public clone(): IpBits {
22
+ // let my = new IpBits();
23
+ // my.version = this.version;
24
+ // my.vt_as_compressed_string = this.vt_as_compressed_string;
25
+ // my.vt_as_uncompressed_string = this.vt_as_uncompressed_string;
26
+ // my.bits = this.bits;
27
+ // my.part_bits = this.part_bits;
28
+ // my.dns_bits = this.dns_bits;
29
+ // my.rev_domain = this.rev_domain;
30
+ // my.part_mod = this.part_mod;
31
+ // my.host_ofs = this.host_ofs.clone();
32
+ return this;
33
+ }
34
+
35
+ public parts(bu: Crunchy): number[] {
36
+ const vec: number[] = [];
37
+ let my = bu.clone();
38
+ const part_mod = Crunchy.one().shl(this.part_bits); // - Crunchy::one();
39
+ for (let i = 0; i < this.bits / this.part_bits; ++i) {
40
+ // console.log("parts-1:", my, part_mod, my.mod(part_mod), my.mod(part_mod).toString());
41
+ vec.push(+my.mod(part_mod).toString());
42
+ my = my.shr(this.part_bits);
43
+ }
44
+ // console.log("parts:", vec);
45
+ return vec.reverse();
46
+ }
47
+
48
+ public as_compressed_string(bu: Crunchy): string {
49
+ return this.vt_as_compressed_string(this, bu);
50
+ }
51
+
52
+ public as_uncompressed_string(bu: Crunchy): string {
53
+ return this.vt_as_uncompressed_string(this, bu);
54
+ }
55
+
56
+ public dns_part_format(i: number): string {
57
+ switch (this.version) {
58
+ case IpVersion.V4:
59
+ return `${i}`;
60
+ case IpVersion.V6:
61
+ return `${i.toString(16)}`;
62
+ }
63
+ }
64
+
65
+ public static _v4: IpBits | null = null;
66
+ public static v4(): IpBits {
67
+ if (IpBits._v4) {
68
+ return IpBits._v4;
69
+ }
70
+ const my = new IpBits();
71
+ IpBits._v4 = my;
72
+ my.version = IpVersion.V4;
73
+ my.vt_as_compressed_string = IpBits.ipv4_as_compressed;
74
+ my.vt_as_uncompressed_string = IpBits.ipv4_as_compressed;
75
+ my.bits = 32;
76
+ my.part_bits = 8;
77
+ my.dns_bits = 8;
78
+ my.rev_domain = "in-addr.arpa";
79
+ my.part_mod = 1 << 8;
80
+ my.host_ofs = Crunchy.one();
81
+ return my;
82
+ }
83
+
84
+ public static _v6: IpBits | null = null;
85
+ public static v6(): IpBits {
86
+ if (IpBits._v6) {
87
+ return IpBits._v6;
88
+ }
89
+ const my = new IpBits();
90
+ IpBits._v6 = my;
91
+ my.version = IpVersion.V6;
92
+ my.vt_as_compressed_string = IpBits.ipv6_as_compressed;
93
+ my.vt_as_uncompressed_string = IpBits.ipv6_as_uncompressed;
94
+ my.bits = 128;
95
+ my.part_bits = 16;
96
+ my.dns_bits = 4;
97
+ my.rev_domain = "ip6.arpa";
98
+ my.part_mod = 1 << 16;
99
+ my.host_ofs = Crunchy.zero();
100
+ return my;
101
+ }
102
+
103
+ public static ipv4_as_compressed(ip_bits: IpBits, host_address: Crunchy): string {
104
+ let ret = "";
105
+ let sep = "";
106
+ for (const part of ip_bits.parts(host_address)) {
107
+ ret += sep;
108
+ ret += `${part}`;
109
+ sep = ".";
110
+ }
111
+ return ret;
112
+ }
113
+
114
+ public static ipv6_as_compressed(ip_bits: IpBits, host_address: Crunchy): string {
115
+ // println!("ipv6_as_compressed:{}", host_address);
116
+ let ret = "";
117
+ let colon = "";
118
+ let done = false;
119
+ for (const rle of Rle.code(ip_bits.parts(host_address))) {
120
+ // console.log(rle.toString());
121
+ for (let _ = 0; _ < rle.cnt; _++) {
122
+ if (done || !(rle.part == 0 && rle.max)) {
123
+ ret += `${colon}${rle.part.toString(16)}`;
124
+ colon = ":";
125
+ } else if (rle.part == 0 && rle.max) {
126
+ ret += "::";
127
+ colon = "";
128
+ done = true;
129
+ break;
130
+ }
131
+ }
132
+ }
133
+ return ret;
134
+ }
135
+
136
+ public static ipv6_as_uncompressed(ip_bits: IpBits, host_address: Crunchy): string {
137
+ let ret = "";
138
+ let sep = "";
139
+ for (const part of ip_bits.parts(host_address)) {
140
+ ret += sep;
141
+ ret += (0x10000 + part).toString(16).slice(1);
142
+ sep = ":";
143
+ }
144
+ return ret;
145
+ }
146
+ }
147
+
148
+ export default IpBits;
@@ -0,0 +1,6 @@
1
+ enum IpVersion {
2
+ V4 = 4,
3
+ V6 = 6,
4
+ }
5
+
6
+ export default IpVersion;