File tree 2 files changed +15
-0
lines changed
2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,16 @@ Multiaddr.prototype.toString = function toString () {
56
56
return codec . bufferToString ( this . buffer )
57
57
}
58
58
59
+ /**
60
+ * Returns Multiaddr as a JSON encoded object
61
+ *
62
+ * @returns {String }
63
+ * @example
64
+ * JSON.stringify(Multiaddr('/ip4/127.0.0.1/tcp/4001'))
65
+ * // '/ip4/127.0.0.1/tcp/4001'
66
+ */
67
+ Multiaddr . prototype . toJSON = Multiaddr . prototype . toString ;
68
+
59
69
/**
60
70
* Returns Multiaddr as a convinient options object to be used with net.createConnection
61
71
*
Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ describe('construction', () => {
36
36
expect ( multiaddr ( udpAddr ) . buffer ) . to . deep . equal ( udpAddr . buffer )
37
37
} )
38
38
39
+ it ( 'reconstruct with JSON' , ( ) => {
40
+ expect ( multiaddr ( JSON . parse ( JSON . stringify ( udpAddr ) ) ) . buffer === udpAddr . buffer ) . to . equal ( false )
41
+ expect ( multiaddr ( JSON . parse ( JSON . stringify ( udpAddr ) ) ) . buffer ) . to . deep . equal ( udpAddr . buffer )
42
+ } )
43
+
39
44
it ( 'empty construct still works' , ( ) => {
40
45
expect ( multiaddr ( '' ) . toString ( ) ) . to . equal ( '/' )
41
46
} )
You can’t perform that action at this time.
0 commit comments