Skip to content

Commit 7d284e4

Browse files
authored
feat: add types (#189)
BREAKING CHANGES: entry point uses named exports
1 parent aac0144 commit 7d284e4

25 files changed

+1072
-1130
lines changed

.aegir.js

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Desktop (please complete the following information):**
27+
- OS: [e.g. iOS]
28+
- Browser [e.g. chrome, safari]
29+
- Version [e.g. 22]
30+
31+
**Smartphone (please complete the following information):**
32+
- Device: [e.g. iPhone6]
33+
- OS: [e.g. iOS8.1]
34+
- Browser [e.g. stock browser, safari]
35+
- Version [e.g. 22]
36+
37+
**Additional context**
38+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

.github/workflows/main.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: ci
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
10+
jobs:
11+
check:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- run: npm install
16+
- run: npx aegir lint
17+
- run: npx aegir ts -p check
18+
- run: npx aegir build
19+
- run: npx aegir dep-check
20+
- uses: ipfs/aegir/actions/bundle-size@master
21+
with:
22+
github_token: ${{ secrets.GITHUB_TOKEN }}
23+
test-node:
24+
needs: check
25+
runs-on: ${{ matrix.os }}
26+
strategy:
27+
matrix:
28+
os: [windows-latest, ubuntu-latest, macos-latest]
29+
node: [14, 15]
30+
fail-fast: true
31+
steps:
32+
- uses: actions/checkout@v2
33+
- uses: actions/setup-node@v1
34+
with:
35+
node-version: ${{ matrix.node }}
36+
- run: npm install
37+
- run: npx aegir test -t node --bail --cov
38+
- uses: codecov/codecov-action@v1
39+
test-chrome:
40+
needs: check
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v2
44+
- uses: microsoft/playwright-github-action@v1
45+
- run: npm install
46+
- run: npx aegir test -t browser --bail --cov
47+
- run: npx aegir test -t webworker --bail
48+
- uses: codecov/codecov-action@v1
49+
test-firefox:
50+
needs: check
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v2
54+
- uses: microsoft/playwright-github-action@v1
55+
- run: npm install
56+
- run: npx aegir test -t browser -t webworker --bail -- --browser firefox
57+
test-webkit:
58+
needs: check
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v2
62+
- uses: microsoft/playwright-github-action@v1
63+
- run: npm install
64+
- run: npx aegir test -t browser -t webworker --bail -- --browser webkit
65+
test-electron-main:
66+
needs: check
67+
runs-on: ubuntu-latest
68+
steps:
69+
- uses: actions/checkout@v2
70+
- run: npm install
71+
- run: npx xvfb-maybe aegir test -t electron-main --bail
72+
test-electron-renderer:
73+
needs: check
74+
runs-on: ubuntu-latest
75+
steps:
76+
- uses: actions/checkout@v2
77+
- run: npm install
78+
- run: npx xvfb-maybe aegir test -t electron-renderer --bail

.travis.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

README.md

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ js-multiaddr
2424
- [Background](#background)
2525
- [What is multiaddr?](#what-is-multiaddr)
2626
- [Install](#install)
27-
- [Setup](#setup)
28-
- [Node.js](#nodejs)
29-
- [Browser: Browserify, Webpack, other bundlers](#browser-browserify-webpack-other-bundlers)
30-
- [Browser: `<script>` Tag](#browser-script-tag)
27+
- [NPM](#npm)
28+
- [Browser: `<script>` Tag](#browser-script-tag)
3129
- [Usage](#usage)
3230
- [API](#api)
3331
- [Resolvers](#resolvers)
@@ -48,30 +46,12 @@ A standard way to represent addresses that
4846

4947
## Install
5048

49+
### NPM
5150
```sh
5251
npm i multiaddr
5352
```
5453

55-
### Setup
56-
57-
#### Node.js
58-
59-
```js
60-
const multiaddr = require('multiaddr')
61-
```
62-
63-
#### Browser: Browserify, Webpack, other bundlers
64-
65-
The code published to npm that gets loaded on require is in fact a ES5
66-
transpiled version with the right shims added. This means that you can require
67-
it and use with your favourite bundler without having to adjust asset management
68-
process.
69-
70-
```js
71-
const multiaddr = require('multiaddr')
72-
```
73-
74-
#### Browser: `<script>` Tag
54+
### Browser: `<script>` Tag
7555

7656
Loading this module through a script tag will make the `Multiaddr` obj available in
7757
the global namespace.
@@ -83,35 +63,43 @@ the global namespace.
8363
## Usage
8464

8565
```js
86-
$ node
66+
// if we are coming from <= 8.x you can use the factory function
67+
constmultiaddr } = require('multiaddr')
68+
const addr =  multiaddr("/ip4/127.0.0.1/udp/1234")
69+
// <Multiaddr /ip4/127.0.0.1/udp/1234>
8770

88-
> const multiaddr = require('multiaddr')
71+
// or just the class directly
72+
constMultiaddr } = require('multiaddr')
8973

90-
> const addr = multiaddr("/ip4/127.0.0.1/udp/1234")
91-
<Multiaddr /ip4/127.0.0.1/udp/1234>
74+
const addr = new Multiaddr("/ip4/127.0.0.1/udp/1234")
75+
// <Multiaddr /ip4/127.0.0.1/udp/1234>
9276

93-
> addr.bytes
94-
<Uint8Array 04 7f 00 00 01 11 04 d2>
77+
addr.bytes
78+
// <Uint8Array 04 7f 00 00 01 11 04 d2>
9579

96-
> addr.toString()
97-
'/ip4/127.0.0.1/udp/1234'
80+
addr.toString()
81+
// '/ip4/127.0.0.1/udp/1234'
9882

99-
> addr.protos()
83+
addr.protos()
84+
/*
10085
[
10186
{code: 4, name: 'ip4', size: 32},
10287
{code: 273, name: 'udp', size: 16}
10388
]
89+
*/
10490

10591
// gives you an object that is friendly with what Node.js core modules expect for addresses
106-
> addr.nodeAddress()
92+
addr.nodeAddress()
93+
/*
10794
{
108-
family: "4",
95+
family: 4,
10996
port: 1234,
11097
address: "127.0.0.1"
11198
}
99+
*/
112100

113-
> addr.encapsulate('/sctp/5678')
114-
<Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678>
101+
addr.encapsulate('/sctp/5678')
102+
// <Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678>
115103
```
116104

117105
## API
@@ -124,10 +112,10 @@ https://multiformats.github.io/js-multiaddr/
124112
To provide multiaddr resolvers you can do:
125113

126114
```js
127-
const multiaddr = require('multiaddr')
115+
const { Multiaddr } = require('multiaddr')
128116
const resolvers = require('multiaddr/src/resolvers')
129117

130-
multiaddr.resolvers.set('dnsaddr', resolvers.dnsaddrResolver)
118+
Multiaddr.resolvers.set('dnsaddr', resolvers.dnsaddrResolver)
131119
```
132120

133121
The available resolvers are:

documentation.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/try.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
'use strict'
22

3-
var multiaddr = require('../src')
4-
var log = console.log
3+
const { Multiaddr } = require('../src')
4+
// eslint-disable-next-line no-console
5+
const log = console.log
56

6-
var addr = multiaddr('/ip4/127.0.0.1/udp/1234')
7+
const addr = new Multiaddr('/ip4/127.0.0.1/udp/1234')
78
log(addr)
89
log(addr.bytes)
910
log(addr.toString())
10-
log(multiaddr(addr.bytes))
11+
log(new Multiaddr(addr.bytes))
1112

1213
log(addr.protoCodes())
1314
log(addr.protoNames())
1415
log(addr.protos())
1516

1617
log(addr.nodeAddress())
17-
log(multiaddr.fromNodeAddress(addr.nodeAddress(), 'udp'))
18+
log(Multiaddr.fromNodeAddress(addr.nodeAddress(), 'udp'))
1819

1920
log(addr.encapsulate('/sctp/5678'))
2021
log(addr.decapsulate('/udp'))
2122

22-
var printer = multiaddr('/ip4/192.168.0.13/tcp/80')
23-
var proxy = multiaddr('/ip4/10.20.30.40/tcp/443')
24-
var printerOverProxy = proxy.encapsulate(printer)
23+
const printer = new Multiaddr('/ip4/192.168.0.13/tcp/80')
24+
const proxy = new Multiaddr('/ip4/10.20.30.40/tcp/443')
25+
const printerOverProxy = proxy.encapsulate(printer)
2526
log(printerOverProxy)
2627

27-
var proxyAgain = printerOverProxy.decapsulate('/ip4')
28+
const proxyAgain = printerOverProxy.decapsulate('/ip4')
2829
log(proxyAgain)

0 commit comments

Comments
 (0)