ipaddress 0.2.3 → 0.2.6

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 (113) hide show
  1. package/{crunchy.d.ts → dist/src/crunchy.d.ts} +1 -0
  2. package/dist/src/crunchy.d.ts.map +1 -0
  3. package/dist/src/crunchy.js +484 -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 -5
  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} +18 -16
  14. package/dist/src/ipaddress.d.ts.map +1 -0
  15. package/dist/src/ipaddress.js +1228 -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 +176 -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 +35 -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 +25 -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.d.ts +2 -0
  44. package/dist/test/test_crunchy.d.ts.map +1 -0
  45. package/dist/test/test_crunchy.js +451 -0
  46. package/dist/test/test_ipaddress.d.ts +2 -0
  47. package/dist/test/test_ipaddress.d.ts.map +1 -0
  48. package/dist/test/test_ipaddress.js +182 -0
  49. package/dist/test/test_ipv4.d.ts +2 -0
  50. package/dist/test/test_ipv4.d.ts.map +1 -0
  51. package/dist/test/test_ipv4.js +561 -0
  52. package/dist/test/test_ipv6.d.ts +2 -0
  53. package/dist/test/test_ipv6.d.ts.map +1 -0
  54. package/dist/test/test_ipv6.js +313 -0
  55. package/dist/test/test_ipv6_loopback.d.ts +2 -0
  56. package/dist/test/test_ipv6_loopback.d.ts.map +1 -0
  57. package/dist/test/test_ipv6_loopback.js +40 -0
  58. package/dist/test/test_ipv6_mapped.d.ts +2 -0
  59. package/dist/test/test_ipv6_mapped.d.ts.map +1 -0
  60. package/dist/test/test_ipv6_mapped.js +89 -0
  61. package/dist/test/test_ipv6_unspec.d.ts +2 -0
  62. package/dist/test/test_ipv6_unspec.d.ts.map +1 -0
  63. package/dist/test/test_ipv6_unspec.js +39 -0
  64. package/dist/test/test_prefix128.d.ts +2 -0
  65. package/dist/test/test_prefix128.d.ts.map +1 -0
  66. package/dist/test/test_prefix128.js +35 -0
  67. package/dist/test/test_prefix32.d.ts +2 -0
  68. package/dist/test/test_prefix32.d.ts.map +1 -0
  69. package/dist/test/test_prefix32.js +126 -0
  70. package/dist/test/test_rle.d.ts +2 -0
  71. package/dist/test/test_rle.d.ts.map +1 -0
  72. package/dist/test/test_rle.js +141 -0
  73. package/dist/vitest.config.d.ts +3 -0
  74. package/dist/vitest.config.d.ts.map +1 -0
  75. package/dist/vitest.config.js +11 -0
  76. package/package.json +40 -37
  77. package/src/crunchy.ts +546 -0
  78. package/src/index.ts +23 -0
  79. package/src/ip_bits.ts +148 -0
  80. package/src/ip_version.ts +6 -0
  81. package/src/ipaddress.ts +1331 -0
  82. package/src/ipv4.ts +190 -0
  83. package/src/ipv6.ts +202 -0
  84. package/src/ipv6_loopback.ts +55 -0
  85. package/src/ipv6_mapped.ts +163 -0
  86. package/src/ipv6_unspec.ts +59 -0
  87. package/src/prefix.ts +170 -0
  88. package/src/prefix128.ts +38 -0
  89. package/src/prefix32.ts +28 -0
  90. package/src/rle.ts +85 -0
  91. package/test/test_crunchy.ts +614 -0
  92. package/test/test_ipaddress.ts +208 -0
  93. package/test/test_ipv4.ts +596 -0
  94. package/test/test_ipv6.ts +325 -0
  95. package/test/test_ipv6_loopback.ts +52 -0
  96. package/test/test_ipv6_mapped.ts +101 -0
  97. package/test/test_ipv6_unspec.ts +51 -0
  98. package/test/test_prefix128.ts +39 -0
  99. package/test/test_prefix32.ts +130 -0
  100. package/test/test_rle.ts +144 -0
  101. package/LICENSE +0 -20
  102. package/README.md +0 -956
  103. package/index.d.ts +0 -12
  104. package/ipaddress.js +0 -2854
  105. package/ipaddress.js.map +0 -1
  106. package/ipv4.d.ts +0 -14
  107. package/ipv6.d.ts +0 -12
  108. package/ipv6_loopback.d.ts +0 -5
  109. package/ipv6_mapped.d.ts +0 -5
  110. package/ipv6_unspec.d.ts +0 -5
  111. package/prefix128.d.ts +0 -6
  112. package/prefix32.d.ts +0 -6
  113. package/rle.d.ts +0 -14
@@ -0,0 +1,126 @@
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
+ class Prefix32Test {
6
+ netmask0 = "0.0.0.0";
7
+ netmask8 = "255.0.0.0";
8
+ netmask16 = "255.255.0.0";
9
+ netmask24 = "255.255.255.0";
10
+ netmask30 = "255.255.255.252";
11
+ netmasks = [];
12
+ prefix_hash = [];
13
+ octets_hash = [];
14
+ u32_hash = [];
15
+ }
16
+ describe("prefix32", () => {
17
+ function assertArrayEqual(a, b) {
18
+ assert.equal(a.length, b.length, "length missmatch");
19
+ for (let i = 0; i < a.length; ++i) {
20
+ assert.equal(a[i], b[i]);
21
+ }
22
+ }
23
+ function setup() {
24
+ const p32t = new Prefix32Test();
25
+ p32t.netmasks.push(p32t.netmask0);
26
+ p32t.netmasks.push(p32t.netmask8);
27
+ p32t.netmasks.push(p32t.netmask16);
28
+ p32t.netmasks.push(p32t.netmask24);
29
+ p32t.netmasks.push(p32t.netmask30);
30
+ p32t.prefix_hash.push(["0.0.0.0", 0]);
31
+ p32t.prefix_hash.push(["255.0.0.0", 8]);
32
+ p32t.prefix_hash.push(["255.255.0.0", 16]);
33
+ p32t.prefix_hash.push(["255.255.255.0", 24]);
34
+ p32t.prefix_hash.push(["255.255.255.252", 30]);
35
+ p32t.octets_hash.push([[0, 0, 0, 0], 0]);
36
+ p32t.octets_hash.push([[255, 0, 0, 0], 8]);
37
+ p32t.octets_hash.push([[255, 255, 0, 0], 16]);
38
+ p32t.octets_hash.push([[255, 255, 255, 0], 24]);
39
+ p32t.octets_hash.push([[255, 255, 255, 252], 30]);
40
+ p32t.u32_hash.push([0, Crunchy.zero()]);
41
+ p32t.u32_hash.push([8, Crunchy.parse("4278190080")]);
42
+ p32t.u32_hash.push([16, Crunchy.parse("4294901760")]);
43
+ p32t.u32_hash.push([24, Crunchy.parse("4294967040")]);
44
+ p32t.u32_hash.push([30, Crunchy.parse("4294967292")]);
45
+ return p32t;
46
+ }
47
+ it("test_attributes", () => {
48
+ for (const e of setup().prefix_hash) {
49
+ const prefix = Prefix32.create(e[1]);
50
+ assert.equal(e[1], prefix.num);
51
+ }
52
+ });
53
+ it("test_parse_netmask_to_prefix", () => {
54
+ for (const e of setup().prefix_hash) {
55
+ const netmask = e[0];
56
+ const num = e[1];
57
+ // console.log(e);
58
+ const prefix = IPAddress.parse_netmask_to_prefix(netmask);
59
+ assert.equal(num, prefix);
60
+ }
61
+ });
62
+ it("test_method_to_ip", () => {
63
+ for (const hash of setup().prefix_hash) {
64
+ const netmask = hash[0];
65
+ const num = hash[1];
66
+ const prefix = Prefix32.create(num);
67
+ assert.equal(netmask, prefix.to_ip_str());
68
+ }
69
+ });
70
+ it("test_method_to_s", () => {
71
+ const prefix = Prefix32.create(8);
72
+ assert.equal("8", prefix.to_s());
73
+ });
74
+ it("test_method_bits", () => {
75
+ const prefix = Prefix32.create(16);
76
+ assert.equal("11111111111111110000000000000000", prefix.bits());
77
+ });
78
+ it("test_method_to_u32", () => {
79
+ for (const i of setup().u32_hash) {
80
+ const num = i[0];
81
+ const ip32 = i[1];
82
+ assert.isTrue(ip32.eq(Prefix32.create(num).netmask()));
83
+ }
84
+ });
85
+ it("test_method_plus", () => {
86
+ const p1 = Prefix32.create(8);
87
+ const p2 = Prefix32.create(10);
88
+ assert.equal(18, p1.add_prefix(p2).num);
89
+ assert.equal(12, p1.add(4).num);
90
+ });
91
+ it("test_method_minus", () => {
92
+ const p1 = Prefix32.create(8);
93
+ const p2 = Prefix32.create(24);
94
+ assert.equal(16, p1.sub_prefix(p2).num);
95
+ assert.equal(16, p2.sub_prefix(p1).num);
96
+ assert.equal(20, p2.sub(4).num);
97
+ });
98
+ it("test_initialize", () => {
99
+ assert.isNull(Prefix32.create(33));
100
+ assert.isOk(Prefix32.create(8));
101
+ });
102
+ it("test_method_octets", () => {
103
+ for (const i of setup().octets_hash) {
104
+ const arr = i[0];
105
+ const pref = i[1];
106
+ const prefix = Prefix32.create(pref);
107
+ assertArrayEqual(prefix.ip_bits.parts(prefix.netmask()), arr);
108
+ }
109
+ });
110
+ it("test_method_brackets", () => {
111
+ for (const i of setup().octets_hash) {
112
+ const arr = i[0];
113
+ const pref = i[1];
114
+ const prefix = Prefix32.create(pref);
115
+ for (let index = 0; index < arr.length; ++index) {
116
+ // console.log("xxxx", prefix.netmask());
117
+ assert.equal(prefix.ip_bits.parts(prefix.netmask())[index], arr[index]);
118
+ }
119
+ }
120
+ });
121
+ it("test_method_hostmask", () => {
122
+ const prefix = Prefix32.create(8);
123
+ // console.log(">>>>", prefix.host_mask());
124
+ assert.equal("0.255.255.255", Ipv4.from_number(prefix.host_mask(), 0).to_s());
125
+ });
126
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test_rle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test_rle.d.ts","sourceRoot":"","sources":["../../test/test_rle.ts"],"names":[],"mappings":""}
@@ -0,0 +1,141 @@
1
+ import Rle from "../src/rle.js";
2
+ function assert_rle(left, right) {
3
+ assert.equal(left.length, right.length, "array length missmatch");
4
+ for (let i = 0; i < left.length; ++i) {
5
+ assert.isOk(left[i].eq(right[i]), `left:${left[i].toString()} right:${right[i].toString()}`);
6
+ }
7
+ }
8
+ describe("rle", () => {
9
+ it("test_rle", () => {
10
+ const empty = [];
11
+ assert_rle(Rle.code(empty), []);
12
+ assert_rle(Rle.code([4711]), [
13
+ new Rle({
14
+ part: 4711,
15
+ pos: 0,
16
+ cnt: 1,
17
+ max: true,
18
+ }),
19
+ ]);
20
+ assert_rle(Rle.code([4711, 4711]), [
21
+ new Rle({
22
+ part: 4711,
23
+ pos: 0,
24
+ cnt: 2,
25
+ max: true,
26
+ }),
27
+ ]);
28
+ assert_rle(Rle.code([4711, 4711, 4811]), [
29
+ new Rle({
30
+ part: 4711,
31
+ pos: 0,
32
+ cnt: 2,
33
+ max: true,
34
+ }),
35
+ new Rle({
36
+ part: 4811,
37
+ pos: 1,
38
+ cnt: 1,
39
+ max: true,
40
+ }),
41
+ ]);
42
+ assert_rle(Rle.code([4711, 4711, 4811, 4711, 4711]), [
43
+ new Rle({
44
+ part: 4711,
45
+ pos: 0,
46
+ cnt: 2,
47
+ max: true,
48
+ }),
49
+ new Rle({
50
+ part: 4811,
51
+ pos: 1,
52
+ cnt: 1,
53
+ max: true,
54
+ }),
55
+ new Rle({
56
+ part: 4711,
57
+ pos: 2,
58
+ cnt: 2,
59
+ max: true,
60
+ }),
61
+ ]);
62
+ assert_rle(Rle.code([4711, 4711, 4711, 4811, 4711, 4711]), [
63
+ new Rle({
64
+ part: 4711,
65
+ pos: 0,
66
+ cnt: 3,
67
+ max: true,
68
+ }),
69
+ new Rle({
70
+ part: 4811,
71
+ pos: 1,
72
+ cnt: 1,
73
+ max: true,
74
+ }),
75
+ new Rle({
76
+ part: 4711,
77
+ pos: 2,
78
+ cnt: 2,
79
+ max: false,
80
+ }),
81
+ ]);
82
+ assert_rle(Rle.code([4711, 4711, 4711, 4811, 4711, 4711, 4911, 4911, 4911]), [
83
+ new Rle({
84
+ part: 4711,
85
+ pos: 0,
86
+ cnt: 3,
87
+ max: true,
88
+ }),
89
+ new Rle({
90
+ part: 4811,
91
+ pos: 1,
92
+ cnt: 1,
93
+ max: true,
94
+ }),
95
+ new Rle({
96
+ part: 4711,
97
+ pos: 2,
98
+ cnt: 2,
99
+ max: false,
100
+ }),
101
+ new Rle({
102
+ part: 4911,
103
+ pos: 3,
104
+ cnt: 3,
105
+ max: true,
106
+ }),
107
+ ]);
108
+ assert_rle(Rle.code([0x2001, 0x888, 0, 0x6630, 0, 0, 0, 0]), [
109
+ new Rle({
110
+ part: 0x2001,
111
+ pos: 0,
112
+ cnt: 1,
113
+ max: true,
114
+ }),
115
+ new Rle({
116
+ part: 0x888,
117
+ pos: 1,
118
+ cnt: 1,
119
+ max: true,
120
+ }),
121
+ new Rle({
122
+ part: 0,
123
+ pos: 2,
124
+ cnt: 1,
125
+ max: false,
126
+ }),
127
+ new Rle({
128
+ part: 0x6630,
129
+ pos: 3,
130
+ cnt: 1,
131
+ max: true,
132
+ }),
133
+ new Rle({
134
+ part: 0,
135
+ pos: 4,
136
+ cnt: 4,
137
+ max: true,
138
+ }),
139
+ ]);
140
+ });
141
+ });
@@ -0,0 +1,3 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;
3
+ //# sourceMappingURL=vitest.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest.config.d.ts","sourceRoot":"","sources":["../vitest.config.ts"],"names":[],"mappings":";AAIA,wBAQG"}
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from "vitest/config";
2
+ import tsconfigPaths from "vite-tsconfig-paths";
3
+ export default defineConfig({
4
+ plugins: [tsconfigPaths()],
5
+ test: {
6
+ name: "generic-js",
7
+ exclude: [],
8
+ include: ["test/**/test_*.?(c|m)[jt]s?(x)"],
9
+ globals: true,
10
+ },
11
+ });
package/package.json CHANGED
@@ -1,55 +1,58 @@
1
1
  {
2
2
  "name": "ipaddress",
3
- "version": "0.2.3",
3
+ "version": "0.2.6",
4
4
  "description": "ipaddress handles ipv4 and ipv6",
5
- "main": "./ipaddress.js",
5
+ "main": "./dist/src/index.js",
6
+ "type": "module",
7
+ "files": [
8
+ "dist/",
9
+ "src/",
10
+ "test/",
11
+ "package.json"
12
+ ],
6
13
  "scripts": {
7
- "clean": "rimraf dist",
14
+ "clean": "rm -rf dist",
8
15
  "prebuild": "npm run clean",
9
- "build": "webpack",
10
- "build:watch": "webpack --watch --debug --output-pathinfo --progress",
11
- "start": "nodemon ./dist/ipaddress.js",
12
- "pretest": "npm run build",
13
- "test": "mocha dist/test",
14
- "changelog": "conventional-changelog -p angular -i CHANGELOG.md -w",
15
- "preversion": "npm test",
16
- "version": "npm run build && conventional-changelog -p angular -v -r 0 > CHANGELOG.md && git add -A .",
17
- "postversion": "git push && git push --tags",
18
- "prepublish": "not-in-install && npm run build || echo 'In install cycle, skipping prepublish'"
16
+ "build": "tsc",
17
+ "build:watch": "tsc --watch",
18
+ "start": "",
19
+ "lint": "eslint",
20
+ "format": "prettier",
21
+ "pretest": "npm run lint",
22
+ "test": "vitest --run"
19
23
  },
24
+ "keywords": [
25
+ "ip",
26
+ "ipv4",
27
+ "ipv6"
28
+ ],
20
29
  "repository": {
21
30
  "type": "git",
22
- "url": "mabels/ipaddress"
31
+ "url": "git+https://github.com/mabels/ipaddress.git"
23
32
  },
24
33
  "license": "AFL-2.0",
25
34
  "bugs": {
26
35
  "url": "https://github.com/mabels/ipaddress/issues"
27
36
  },
28
37
  "homepage": "https://github.com/mabels/ipaddress#readme",
29
- "devDependencies": {
30
- "@types/chai": "^3.4.32",
31
- "@types/mocha": "^2.2.31",
32
- "awesome-typescript-loader": "1.1.1",
33
- "babel-core": "6.9.1",
34
- "babel-plugin-transform-es2015-modules-commonjs": "6.10.3",
35
- "chai": "latest",
36
- "mocha": "latest",
37
- "globby": "5.0.0",
38
- "in-publish": "^2.0.0",
39
- "rimraf": "^2.5.4",
40
- "source-map-support": "0.4.1",
41
- "tslint": "3.11.0",
42
- "shelljs": "latest",
43
- "typescript": "2.0.0",
44
- "typings": "1.3.2",
45
- "webpack": "1.13.1"
38
+ "standard": {
39
+ "globals": [
40
+ "describe",
41
+ "it",
42
+ "assert"
43
+ ]
46
44
  },
47
- "publishConfig": {
48
- "tag": "next"
45
+ "devDependencies": {
46
+ "@types/node": "^24.0.7",
47
+ "eslint": "9.21.0",
48
+ "prettier": "^3.6.2",
49
+ "standard": "^17.1.2",
50
+ "typescript": "^5.8.2",
51
+ "vite-tsconfig-paths": "^5.1.4",
52
+ "vitest": "^3.2.4"
49
53
  },
50
- "config": {
51
- "commitizen": {
52
- "path": "./node_modules/cz-conventional-changelog"
53
- }
54
+ "dependencies": {
55
+ "ts-standard": "^12.0.2",
56
+ "typescript-eslint": "^8.35.0"
54
57
  }
55
58
  }