Skip to content

feat: add types #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
language: node_js
cache: npm
branches:
only:
- master
- /^release\/.*$/
stages:
- check
- test
- cov

node_js:
- '12'
- '14'
- '15'

os:
- linux
- osx
- windows

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

jobs:
Expand Down
46 changes: 18 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
- [`bucket.toJSON()`](#buckettojson)
- [`bucket.prettyPrint()`](#bucketprettyprint)
- [`bucket.tableSize()`](#buckettablesize)
- [`hamt.isBucket(other)`](#hamtisbucketother)
- [Contribute](#contribute)
- [License](#license)

Expand All @@ -53,18 +52,18 @@
### Example

```javascript
const hamt = require('hamt-sharding')
const { createHAMT } = require('hamt-sharding')
const crypto = require('crypto-promise')

// decide how to hash things, can return a Promise
const hashFn = async (value) => {
// decide how to hash buffers made from keys, can return a Promise
const hashFn = async (buf) => {
return crypto
.createHash('sha256')
.update(value)
.update(buf)
.digest()
}

const bucket = hamt({
const bucket = createHAMT({
hashFn: hashFn
})

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

```javascript
const hamt = require('hamt-sharding')
const { createHAMT } = require('hamt-sharding')
```

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

```javascript
const hamt = require('hamt-sharding')
const bucket = hamt({...})
const { createHAMT } = require('hamt-sharding')
const bucket = createHAMT({...})

await bucket.put('key', 'value')
```

### `bucket.get(key)`

```javascript
const hamt = require('hamt-sharding')
const bucket = hamt({...})
const { createHAMT } = require('hamt-sharding')
const bucket = createHAMT({...})

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

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

```javascript
const hamt = require('hamt-sharding')
const bucket = hamt({...})
const { createHAMT } = require('hamt-sharding')
const bucket = createHAMT({...})

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

```javascript
const hamt = require('hamt-sharding')
const bucket = hamt({...})
const { createHAMT } = require('hamt-sharding')
const bucket = createHAMT({...})

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

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

```javascript
const hamt = require('hamt-sharding')
const bucket = hamt({...})
const { createHAMT } = require('hamt-sharding')
const bucket = createHAMT({...})

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

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

```javascript
const hamt = require('hamt-sharding')
const bucket = hamt({...})
const { createHAMT } = require('hamt-sharding')
const bucket = createHAMT({...})

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

Expand All @@ -157,15 +156,6 @@ for await (const child of bucket.eachLeafSeries()) {
### `bucket.toJSON()`
### `bucket.prettyPrint()`
### `bucket.tableSize()`
### `hamt.isBucket(other)`

```javascript
const hamt = require('hamt-sharding')
const bucket = hamt({...})

console.info(hamt.isBucket(bucket)) // true
console.info(hamt.isBucket(true)) // false
```

## Contribute

Expand Down
16 changes: 7 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
"main": "src/index.js",
"scripts": {
"test": "aegir test",
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser",
"test:webworker": "aegir test -t webworker",
"build": "aegir build",
"prepare": "aegir build --no-bundle",
"lint": "aegir lint",
"release": "aegir release",
"release-minor": "aegir release --type minor",
Expand All @@ -35,14 +32,15 @@
},
"homepage": "https://github.com/ipfs-shipyard/js-hamt-sharding#readme",
"devDependencies": {
"aegir": "^20.5.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1"
"aegir": "^30.3.0",
"multihashing-async": "^2.1.0"
},
"dependencies": {
"sparse-array": "^1.3.1"
"sparse-array": "^1.3.1",
"uint8arrays": "^2.1.2"
},
"contributors": [
"achingbrain <alex@achingbrain.net>"
]
],
"types": "dist/src/index.d.ts"
}
Loading