Skip to content

Commit 8b7e204

Browse files
authored
feat: add types (#3)
Also fixes up tests so they run on browsers
1 parent 446ff21 commit 8b7e204

11 files changed

+355
-133
lines changed

.travis.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
language: node_js
22
cache: npm
3+
branches:
4+
only:
5+
- master
6+
- /^release\/.*$/
37
stages:
48
- check
59
- test
610
- cov
711

812
node_js:
9-
- '12'
13+
- '14'
14+
- '15'
1015

1116
os:
1217
- linux
1318
- osx
1419
- windows
1520

16-
script: npx nyc -s npm run test:node -- --bail
21+
script: npx nyc -s npm run test -- -t node --bail
1722
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov
1823

1924
jobs:

README.md

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
- [`bucket.toJSON()`](#buckettojson)
3939
- [`bucket.prettyPrint()`](#bucketprettyprint)
4040
- [`bucket.tableSize()`](#buckettablesize)
41-
- [`hamt.isBucket(other)`](#hamtisbucketother)
4241
- [Contribute](#contribute)
4342
- [License](#license)
4443

@@ -53,18 +52,18 @@
5352
### Example
5453

5554
```javascript
56-
const hamt = require('hamt-sharding')
55+
const { createHAMT } = require('hamt-sharding')
5756
const crypto = require('crypto-promise')
5857

59-
// decide how to hash things, can return a Promise
60-
const hashFn = async (value) => {
58+
// decide how to hash buffers made from keys, can return a Promise
59+
const hashFn = async (buf) => {
6160
return crypto
6261
.createHash('sha256')
63-
.update(value)
62+
.update(buf)
6463
.digest()
6564
}
6665

67-
const bucket = hamt({
66+
const bucket = createHAMT({
6867
hashFn: hashFn
6968
})
7069

@@ -77,23 +76,23 @@ const output = await bucket.get('key')
7776
## API
7877

7978
```javascript
80-
const hamt = require('hamt-sharding')
79+
const { createHAMT } = require('hamt-sharding')
8180
```
8281

8382
### `bucket.put(key, value)`
8483

8584
```javascript
86-
const hamt = require('hamt-sharding')
87-
const bucket = hamt({...})
85+
const { createHAMT } = require('hamt-sharding')
86+
const bucket = createHAMT({...})
8887

8988
await bucket.put('key', 'value')
9089
```
9190

9291
### `bucket.get(key)`
9392

9493
```javascript
95-
const hamt = require('hamt-sharding')
96-
const bucket = hamt({...})
94+
const { createHAMT } = require('hamt-sharding')
95+
const bucket = createHAMT({...})
9796

9897
await bucket.put('key', 'value')
9998

@@ -103,8 +102,8 @@ console.info(await bucket.get('key')) // 'value'
103102
### `bucket.del(key)`
104103

105104
```javascript
106-
const hamt = require('hamt-sharding')
107-
const bucket = hamt({...})
105+
const { createHAMT } = require('hamt-sharding')
106+
const bucket = createHAMT({...})
108107

109108
await bucket.put('key', 'value')
110109
await bucket.del('key', 'value')
@@ -115,8 +114,8 @@ console.info(await bucket.get('key')) // undefined
115114
### `bucket.leafCount()`
116115

117116
```javascript
118-
const hamt = require('hamt-sharding')
119-
const bucket = hamt({...})
117+
const { createHAMT } = require('hamt-sharding')
118+
const bucket = createHAMT({...})
120119

121120
console.info(bucket.leafCount()) // 0
122121

@@ -128,8 +127,8 @@ console.info(bucket.leafCount()) // 1
128127
### `bucket.childrenCount()`
129128

130129
```javascript
131-
const hamt = require('hamt-sharding')
132-
const bucket = hamt({...})
130+
const { createHAMT } = require('hamt-sharding')
131+
const bucket = createHAMT({...})
133132

134133
console.info(bucket.childrenCount()) // 0
135134

@@ -142,8 +141,8 @@ console.info(bucket.childrenCount()) // 234 -- dependent on hashing algorithm
142141
### `bucket.eachLeafSeries()`
143142

144143
```javascript
145-
const hamt = require('hamt-sharding')
146-
const bucket = hamt({...})
144+
const { createHAMT } = require('hamt-sharding')
145+
const bucket = createHAMT({...})
147146

148147
await bucket.put('key', 'value')
149148

@@ -157,15 +156,6 @@ for await (const child of bucket.eachLeafSeries()) {
157156
### `bucket.toJSON()`
158157
### `bucket.prettyPrint()`
159158
### `bucket.tableSize()`
160-
### `hamt.isBucket(other)`
161-
162-
```javascript
163-
const hamt = require('hamt-sharding')
164-
const bucket = hamt({...})
165-
166-
console.info(hamt.isBucket(bucket)) // true
167-
console.info(hamt.isBucket(true)) // false
168-
```
169159

170160
## Contribute
171161

package.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
"main": "src/index.js",
77
"scripts": {
88
"test": "aegir test",
9-
"test:node": "aegir test -t node",
10-
"test:browser": "aegir test -t browser",
11-
"test:webworker": "aegir test -t webworker",
12-
"build": "aegir build",
9+
"prepare": "aegir build --no-bundle",
1310
"lint": "aegir lint",
1411
"release": "aegir release",
1512
"release-minor": "aegir release --type minor",
@@ -35,14 +32,15 @@
3532
},
3633
"homepage": "https://github.com/ipfs-shipyard/js-hamt-sharding#readme",
3734
"devDependencies": {
38-
"aegir": "^20.5.0",
39-
"chai": "^4.2.0",
40-
"dirty-chai": "^2.0.1"
35+
"aegir": "^30.3.0",
36+
"multihashing-async": "^2.1.0"
4137
},
4238
"dependencies": {
43-
"sparse-array": "^1.3.1"
39+
"sparse-array": "^1.3.1",
40+
"uint8arrays": "^2.1.2"
4441
},
4542
"contributors": [
4643
"achingbrain <[email protected]>"
47-
]
44+
],
45+
"types": "dist/src/index.d.ts"
4846
}

0 commit comments

Comments
 (0)