@@ -17,6 +17,7 @@ js-multiaddr <!-- omit in toc -->
17
17
18
18
- [ Background] ( #background )
19
19
- [ What is multiaddr?] ( #what-is-multiaddr )
20
+ - [ Migrate to 0.9] ( #migrate-to-09 )
20
21
- [ Install] ( #install )
21
22
- [ NPM] ( #npm )
22
23
- [ Browser: ` <script> ` Tag] ( #browser-script-tag )
@@ -38,6 +39,45 @@ A standard way to represent addresses that
38
39
- have a nice string representation
39
40
- encapsulate well
40
41
42
+ ## Migrate to 0.9
43
+ Before 0.9 ` multiaddr ` would return an constructor function.
44
+ ``` js
45
+ const multiaddr = require (' multiaddr' )
46
+
47
+ const mh1 = multiaddr (' /ip4/127.0.0.1/udp/1234' )
48
+
49
+ const mh2 = new multiaddr (' /ip4/127.0.0.1/udp/1234' )
50
+ // both mh1 and mh2 were multiaddr instances
51
+
52
+ multiaddr .isName ()
53
+ multiaddr .protocols
54
+ // etc
55
+
56
+ ```
57
+ In 0.9 ` multiaddr ` returns a class.
58
+ ``` js
59
+ const Multiaddr = require (' multiaddr' )
60
+ // you need to use `new` to create and instance
61
+ const mh1 = new Multiaddr (' /ip4/127.0.0.1/udp/1234' )
62
+ ```
63
+
64
+ ``` js
65
+ // The Multiaddr class has a factory method to help migration
66
+ const { multiaddr } = require (' multiaddr' )
67
+
68
+ const mh1 = multiaddr (' /ip4/127.0.0.1/udp/1234' )
69
+ ```
70
+ ``` js
71
+ // In case you are using the static methods/getters `fromNodeAddress`, `isName` , `isMultiaddr`, `protocols` and `resolvers`
72
+ // You will need to do a couple more changes
73
+ const Multiaddr = require (' multiaddr' )
74
+ const { multiaddr , isName } = Multiaddr
75
+
76
+ // multiaddr.isName() will not work anymore, only the default export has those methods/getters
77
+ Multiaddr .isName () // or just `isName()`
78
+
79
+ ```
80
+
41
81
## Install
42
82
43
83
``` sh
0 commit comments