@libp2p/utils 1.0.8 → 1.0.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.
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
interface Address {
|
|
3
|
-
multiaddr: Multiaddr;
|
|
4
|
-
isCertified: boolean;
|
|
5
|
-
}
|
|
1
|
+
import type { Address } from '@libp2p/interfaces/peer-store';
|
|
6
2
|
/**
|
|
7
|
-
*
|
|
3
|
+
* Compare function for array.sort().
|
|
4
|
+
* This sort aims to move the private addresses to the end of the array.
|
|
8
5
|
* In case of equality, a certified address will come first.
|
|
9
6
|
*/
|
|
10
|
-
export declare function publicAddressesFirst(
|
|
11
|
-
export {};
|
|
7
|
+
export declare function publicAddressesFirst(a: Address, b: Address): -1 | 0 | 1;
|
|
12
8
|
//# sourceMappingURL=address-sort.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address-sort.d.ts","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"address-sort.d.ts","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAA;AAG5D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAiBxE"}
|
package/dist/src/address-sort.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isPrivate } from './multiaddr/is-private.js';
|
|
2
2
|
/**
|
|
3
3
|
* Compare function for array.sort().
|
|
4
|
-
* This sort aims to move the private
|
|
4
|
+
* This sort aims to move the private addresses to the end of the array.
|
|
5
5
|
* In case of equality, a certified address will come first.
|
|
6
6
|
*/
|
|
7
|
-
function
|
|
7
|
+
export function publicAddressesFirst(a, b) {
|
|
8
8
|
const isAPrivate = isPrivate(a.multiaddr);
|
|
9
9
|
const isBPrivate = isPrivate(b.multiaddr);
|
|
10
10
|
if (isAPrivate && !isBPrivate) {
|
|
@@ -22,11 +22,4 @@ function addressesPublicFirstCompareFunction(a, b) {
|
|
|
22
22
|
}
|
|
23
23
|
return 0;
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Sort given addresses by putting public addresses first.
|
|
27
|
-
* In case of equality, a certified address will come first.
|
|
28
|
-
*/
|
|
29
|
-
export function publicAddressesFirst(addresses) {
|
|
30
|
-
return [...addresses].sort(addressesPublicFirstCompareFunction);
|
|
31
|
-
}
|
|
32
25
|
//# sourceMappingURL=address-sort.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address-sort.js","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"address-sort.js","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAE,CAAU,EAAE,CAAU;IAC1D,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACzC,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAEzC,IAAI,UAAU,IAAI,CAAC,UAAU,EAAE;QAC7B,OAAO,CAAC,CAAA;KACT;SAAM,IAAI,CAAC,UAAU,IAAI,UAAU,EAAE;QACpC,OAAO,CAAC,CAAC,CAAA;KACV;IACD,mBAAmB;IACnB,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE;QACnC,OAAO,CAAC,CAAC,CAAA;KACV;SAAM,IAAI,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,WAAW,EAAE;QAC1C,OAAO,CAAC,CAAA;KACT;IAED,OAAO,CAAC,CAAA;AACV,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p-utils#readme",
|
package/src/address-sort.ts
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Address } from '@libp2p/interfaces/peer-store'
|
|
2
2
|
import { isPrivate } from './multiaddr/is-private.js'
|
|
3
3
|
|
|
4
|
-
interface Address {
|
|
5
|
-
multiaddr: Multiaddr
|
|
6
|
-
isCertified: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
4
|
/**
|
|
10
5
|
* Compare function for array.sort().
|
|
11
|
-
* This sort aims to move the private
|
|
6
|
+
* This sort aims to move the private addresses to the end of the array.
|
|
12
7
|
* In case of equality, a certified address will come first.
|
|
13
8
|
*/
|
|
14
|
-
function
|
|
9
|
+
export function publicAddressesFirst (a: Address, b: Address): -1 | 0 | 1 {
|
|
15
10
|
const isAPrivate = isPrivate(a.multiaddr)
|
|
16
11
|
const isBPrivate = isPrivate(b.multiaddr)
|
|
17
12
|
|
|
@@ -29,11 +24,3 @@ function addressesPublicFirstCompareFunction (a: Address, b: Address) {
|
|
|
29
24
|
|
|
30
25
|
return 0
|
|
31
26
|
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Sort given addresses by putting public addresses first.
|
|
35
|
-
* In case of equality, a certified address will come first.
|
|
36
|
-
*/
|
|
37
|
-
export function publicAddressesFirst (addresses: Address[]) {
|
|
38
|
-
return [...addresses].sort(addressesPublicFirstCompareFunction)
|
|
39
|
-
}
|