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.
- package/dist/src/crunchy.d.ts +107 -33
- package/dist/src/crunchy.d.ts.map +1 -1
- package/dist/src/crunchy.js +274 -142
- package/dist/src/ip_bits.d.ts +2 -2
- package/dist/src/ip_bits.d.ts.map +1 -1
- package/dist/src/ipaddress.d.ts +24 -23
- package/dist/src/ipaddress.d.ts.map +1 -1
- package/dist/src/ipaddress.js +22 -7
- package/dist/src/ipv4.d.ts +3 -3
- package/dist/src/ipv4.d.ts.map +1 -1
- package/dist/src/ipv4.js +26 -15
- package/dist/src/ipv6.d.ts +4 -4
- package/dist/src/ipv6.d.ts.map +1 -1
- package/dist/src/ipv6.js +1 -1
- package/dist/src/ipv6_loopback.d.ts +1 -1
- package/dist/src/ipv6_loopback.d.ts.map +1 -1
- package/dist/src/ipv6_mapped.d.ts +1 -1
- package/dist/src/ipv6_mapped.d.ts.map +1 -1
- package/dist/src/ipv6_unspec.d.ts +1 -1
- package/dist/src/ipv6_unspec.d.ts.map +1 -1
- package/dist/src/prefix128.d.ts +1 -1
- package/dist/src/prefix128.d.ts.map +1 -1
- package/dist/src/prefix128.js +5 -1
- package/dist/src/prefix32.d.ts +1 -1
- package/dist/src/prefix32.d.ts.map +1 -1
- package/dist/src/prefix32.js +5 -1
- package/dist/test/test_crunchy_impls.d.ts +2 -0
- package/dist/test/test_crunchy_impls.d.ts.map +1 -0
- package/dist/test/test_crunchy_impls.js +150 -0
- package/dist/test/test_crunchy_with32bit.d.ts +2 -0
- package/dist/test/test_crunchy_with32bit.d.ts.map +1 -0
- package/dist/test/{test_crunchy.js → test_crunchy_with32bit.js} +113 -182
- package/dist/test/test_ipv4.js +1 -1
- package/dist/test/test_ipv6.js +1 -1
- package/package.json +10 -9
- package/src/crunchy.ts +365 -180
- package/src/ip_bits.ts +11 -11
- package/src/ipaddress.ts +49 -33
- package/src/ipv4.ts +32 -19
- package/src/ipv6.ts +6 -6
- package/src/ipv6_loopback.ts +1 -1
- package/src/ipv6_mapped.ts +1 -1
- package/src/ipv6_unspec.ts +1 -1
- package/src/prefix128.ts +6 -2
- package/src/prefix32.ts +6 -2
- package/test/test_crunchy_impls.ts +179 -0
- package/test/{test_crunchy.ts → test_crunchy_with32bit.ts} +131 -235
- package/test/test_ipaddress.ts +9 -9
- package/test/test_ipv4.ts +115 -115
- package/test/test_ipv6.ts +62 -62
- package/test/test_ipv6_loopback.ts +1 -1
- package/test/test_ipv6_mapped.ts +4 -4
- package/test/test_ipv6_unspec.ts +1 -1
- package/test/test_prefix128.ts +2 -2
- package/test/test_prefix32.ts +13 -13
- package/dist/test/test_crunchy.d.ts +0 -2
- package/dist/test/test_crunchy.d.ts.map +0 -1
package/dist/src/crunchy.d.ts
CHANGED
|
@@ -1,9 +1,77 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Arbitrary-precision integer used throughout ip address math.
|
|
3
|
+
*
|
|
4
|
+
* Historically this was always the hand-rolled 28-bit-limb
|
|
5
|
+
* implementation below (CrunchyWith32Bit), ported from
|
|
3
6
|
* Crunch - Arbitrary-precision integer arithmetic library
|
|
4
7
|
* Copyright (C) 2014 Nenad Vukicevic crunch.secureroom.net/license
|
|
5
8
|
*
|
|
9
|
+
* Native BigInt is now available in every runtime this library
|
|
10
|
+
* targets, so there are two implementations of CrunchyBase -
|
|
11
|
+
* CrunchyWithBigInt (native BigInt, used whenever available) and
|
|
12
|
+
* CrunchyWith32Bit (the original limb-array implementation, kept for
|
|
13
|
+
* environments without BigInt support). Which one backs `Crunchy` is
|
|
14
|
+
* decided once, at module load, by feature-detecting BigInt.
|
|
15
|
+
*
|
|
16
|
+
* `Crunchy` is a value (not a class), so `new Crunchy()` is not
|
|
17
|
+
* possible - use `Crunchy.create()` (or any of the other factories:
|
|
18
|
+
* `Crunchy.zero()`, `Crunchy.parse()`, ...).
|
|
19
|
+
*/
|
|
20
|
+
export interface CrunchyBase {
|
|
21
|
+
clone(): CrunchyBase;
|
|
22
|
+
compare(y: CrunchyBase): number;
|
|
23
|
+
eq(oth: CrunchyBase): boolean;
|
|
24
|
+
lt(oth: CrunchyBase): boolean;
|
|
25
|
+
lte(oth: CrunchyBase): boolean;
|
|
26
|
+
gt(oth: CrunchyBase): boolean;
|
|
27
|
+
gte(oth: CrunchyBase): boolean;
|
|
28
|
+
add(y: CrunchyBase): CrunchyBase;
|
|
29
|
+
sub(y: CrunchyBase): CrunchyBase;
|
|
30
|
+
shl(s: number): CrunchyBase;
|
|
31
|
+
shr(s: number): CrunchyBase;
|
|
32
|
+
mod(y: CrunchyBase): CrunchyBase;
|
|
33
|
+
toString(radix?: number): string;
|
|
34
|
+
create(value?: number | string): CrunchyBase;
|
|
35
|
+
zero(): CrunchyBase;
|
|
36
|
+
one(): CrunchyBase;
|
|
37
|
+
two(): CrunchyBase;
|
|
38
|
+
parse(val: string): CrunchyBase;
|
|
39
|
+
from_number(val: number): CrunchyBase;
|
|
40
|
+
from_string(val: string, radix?: number): CrunchyBase | null;
|
|
41
|
+
from_string_or_throw(val: string, radix?: number): CrunchyBase;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Native BigInt-backed implementation. Used whenever the runtime
|
|
45
|
+
* supports BigInt (i.e. essentially always: Node 10.4+, every
|
|
46
|
+
* evergreen browser, Deno).
|
|
6
47
|
*/
|
|
48
|
+
export declare class CrunchyWithBigInt implements CrunchyBase {
|
|
49
|
+
readonly value: bigint;
|
|
50
|
+
private constructor();
|
|
51
|
+
static bootstrap(): CrunchyWithBigInt;
|
|
52
|
+
private static valueOf;
|
|
53
|
+
clone(): CrunchyBase;
|
|
54
|
+
compare(y: CrunchyBase): number;
|
|
55
|
+
eq(oth: CrunchyBase): boolean;
|
|
56
|
+
lt(oth: CrunchyBase): boolean;
|
|
57
|
+
lte(oth: CrunchyBase): boolean;
|
|
58
|
+
gt(oth: CrunchyBase): boolean;
|
|
59
|
+
gte(oth: CrunchyBase): boolean;
|
|
60
|
+
add(y: CrunchyBase): CrunchyBase;
|
|
61
|
+
sub(y: CrunchyBase): CrunchyBase;
|
|
62
|
+
shl(s: number): CrunchyBase;
|
|
63
|
+
shr(s: number): CrunchyBase;
|
|
64
|
+
mod(y: CrunchyBase): CrunchyBase;
|
|
65
|
+
toString(radix?: number): string;
|
|
66
|
+
create(value?: number | string): CrunchyBase;
|
|
67
|
+
zero(): CrunchyBase;
|
|
68
|
+
one(): CrunchyBase;
|
|
69
|
+
two(): CrunchyBase;
|
|
70
|
+
parse(val: string): CrunchyBase;
|
|
71
|
+
from_number(val: number): CrunchyBase;
|
|
72
|
+
from_string(val: string, radix?: number): CrunchyBase | null;
|
|
73
|
+
from_string_or_throw(val: string, radix?: number): CrunchyBase;
|
|
74
|
+
}
|
|
7
75
|
/**
|
|
8
76
|
* @module Crunch
|
|
9
77
|
* Radix: 28 bits
|
|
@@ -12,45 +80,51 @@
|
|
|
12
80
|
* @param {boolean} rawIn - expect 28-bit arrays
|
|
13
81
|
* @param {boolean} rawOut - return 28-bit arrays
|
|
14
82
|
*/
|
|
15
|
-
export declare class
|
|
83
|
+
export declare class CrunchyWith32Bit implements CrunchyBase {
|
|
16
84
|
num: number[];
|
|
17
85
|
negative: boolean;
|
|
18
86
|
static zeroes: number[];
|
|
19
|
-
clone():
|
|
87
|
+
clone(): CrunchyWith32Bit;
|
|
20
88
|
static removeLeadingZeros(inn: number[]): number[];
|
|
21
|
-
static from_14bit(a: number[]):
|
|
22
|
-
static from_8bit(a: number[]):
|
|
23
|
-
static
|
|
24
|
-
static
|
|
25
|
-
static
|
|
89
|
+
static from_14bit(a: number[]): CrunchyWith32Bit;
|
|
90
|
+
static from_8bit(a: number[]): CrunchyWith32Bit;
|
|
91
|
+
private static _zero;
|
|
92
|
+
private static _one;
|
|
93
|
+
private static _two;
|
|
94
|
+
create(value?: number | string): CrunchyBase;
|
|
95
|
+
zero(): CrunchyBase;
|
|
96
|
+
one(): CrunchyBase;
|
|
97
|
+
two(): CrunchyBase;
|
|
98
|
+
parse(val: string): CrunchyWith32Bit;
|
|
99
|
+
from_number(val: number): CrunchyWith32Bit;
|
|
100
|
+
from_string_or_throw(val: string, radix?: number): CrunchyWith32Bit;
|
|
101
|
+
from_string(val: string, radix?: number): CrunchyWith32Bit | null;
|
|
26
102
|
to_8bit(): number[];
|
|
27
|
-
compare(y:
|
|
28
|
-
eq(oth:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
gt(oth:
|
|
32
|
-
gte(oth:
|
|
33
|
-
add(y:
|
|
34
|
-
unsigned_add(_y:
|
|
35
|
-
sub(y:
|
|
36
|
-
unsigned_sub(_y:
|
|
37
|
-
lsh(s: number):
|
|
38
|
-
rsh(s: number):
|
|
39
|
-
mul(y:
|
|
40
|
-
static msb(x: number): number;
|
|
41
|
-
shr(s: number):
|
|
42
|
-
shl(s: number):
|
|
43
|
-
cut():
|
|
44
|
-
div(y:
|
|
45
|
-
|
|
103
|
+
compare(y: CrunchyBase): number;
|
|
104
|
+
eq(oth: CrunchyBase): boolean;
|
|
105
|
+
lt(oth: CrunchyBase): boolean;
|
|
106
|
+
lte(oth: CrunchyBase): boolean;
|
|
107
|
+
gt(oth: CrunchyBase): boolean;
|
|
108
|
+
gte(oth: CrunchyBase): boolean;
|
|
109
|
+
add(y: CrunchyBase): CrunchyWith32Bit;
|
|
110
|
+
unsigned_add(_y: CrunchyWith32Bit): CrunchyWith32Bit;
|
|
111
|
+
sub(y: CrunchyBase): CrunchyWith32Bit;
|
|
112
|
+
unsigned_sub(_y: CrunchyWith32Bit, internal?: boolean): CrunchyWith32Bit;
|
|
113
|
+
lsh(s: number): CrunchyWith32Bit;
|
|
114
|
+
rsh(s: number): CrunchyWith32Bit;
|
|
115
|
+
mul(y: CrunchyBase): CrunchyWith32Bit;
|
|
116
|
+
static msb(x: number): number | undefined;
|
|
117
|
+
shr(s: number): CrunchyWith32Bit;
|
|
118
|
+
shl(s: number): CrunchyWith32Bit;
|
|
119
|
+
cut(): CrunchyWith32Bit;
|
|
120
|
+
div(y: CrunchyBase, internal?: boolean): CrunchyWith32Bit | null;
|
|
121
|
+
div_or_throw(y: CrunchyBase, internal?: boolean): CrunchyWith32Bit;
|
|
122
|
+
mod(y: CrunchyBase): CrunchyWith32Bit;
|
|
46
123
|
mds(n: number): number;
|
|
47
124
|
toString(radix?: number): string;
|
|
48
|
-
static _zero: Crunchy;
|
|
49
|
-
static zero(): Crunchy;
|
|
50
|
-
static _one: Crunchy;
|
|
51
|
-
static one(): Crunchy;
|
|
52
|
-
static _two: Crunchy;
|
|
53
|
-
static two(): Crunchy;
|
|
54
125
|
}
|
|
126
|
+
export declare const hasBigInt: boolean;
|
|
127
|
+
export type Crunchy = CrunchyBase;
|
|
128
|
+
export declare const Crunchy: CrunchyBase;
|
|
55
129
|
export default Crunchy;
|
|
56
130
|
//# sourceMappingURL=crunchy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crunchy.d.ts","sourceRoot":"","sources":["../../src/crunchy.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"crunchy.d.ts","sourceRoot":"","sources":["../../src/crunchy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,WAAW;IAC1B,KAAK,IAAI,WAAW,CAAC;IACrB,OAAO,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IAChC,EAAE,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC;IAC9B,EAAE,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC;IAC9B,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC;IAC/B,EAAE,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC;IAC9B,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC;IAC/B,GAAG,CAAC,CAAC,EAAE,WAAW,GAAG,WAAW,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