renames to multiaddr-to-uri

This commit is contained in:
Alan Shaw 2018-03-21 10:09:39 +00:00
parent 4ac5788b5e
commit 42d8704061
No known key found for this signature in database
GPG Key ID: 101D1B7A03DFAD4C
5 changed files with 19 additions and 19 deletions

View File

@ -1,22 +1,22 @@
# multiaddr-to-stupid-string
# multiaddr-to-uri
[![Build Status](https://travis-ci.org/tableflip/multiaddr-to-stupid-string.svg?branch=master)](https://travis-ci.org/tableflip/multiaddr-to-stupid-string) [![dependencies Status](https://david-dm.org/tableflip/multiaddr-to-stupid-string/status.svg)](https://david-dm.org/tableflip/multiaddr-to-stupid-string) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![Build Status](https://travis-ci.org/tableflip/multiaddr-to-uri.svg?branch=master)](https://travis-ci.org/tableflip/multiaddr-to-uri) [![dependencies Status](https://david-dm.org/tableflip/multiaddr-to-uri/status.svg)](https://david-dm.org/tableflip/multiaddr-to-uri) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
> Convert a Multiaddr to a stupid string /dnsaddr/ipfs.io/http -> http://ipfs.io
> Convert a Multiaddr to a URI /dnsaddr/ipfs.io/http -> http://ipfs.io
## Install
```sh
npm install multiaddr-to-stupid-string
npm install multiaddr-to-uri
```
## Usage
```js
const toStupid = require('multiaddr-to-stupid-string')
const toUri = require('multiaddr-to-uri')
console.log(toStupid('/dnsaddr/protocol.ai/https'))
console.log(toUri('/dnsaddr/protocol.ai/https'))
// -> https://protocol.ai
```
@ -25,11 +25,11 @@ Note:
* Might be lossy - e.g. a DNSv6 multiaddr
* Can throw if the passed multiaddr:
* is not a valid multiaddr
* is not supported as a stupid string e.g. circuit
* is not supported as a URI e.g. circuit
## Contribute
Feel free to dive in! [Open an issue](https://github.com/tableflip/multiaddr-to-stupid-string/issues/new) or submit PRs.
Feel free to dive in! [Open an issue](https://github.com/tableflip/multiaddr-to-uri/issues/new) or submit PRs.
## License

View File

@ -1,7 +1,7 @@
const Multiaddr = require('multiaddr')
const reduceValue = (_, v) => v
const StupidReducers = {
const Reducers = {
ip4: reduceValue,
ip6: reduceValue,
tcp: (str, content, i, parts) => (
@ -32,7 +32,7 @@ module.exports = (multiaddr) => (
content: tuple[1]
}))
.reduce((str, part, i, parts) => {
const reduce = StupidReducers[part.protocol]
const reduce = Reducers[part.protocol]
if (!reduce) throw new Error(`Unsupported protocol ${part.protocol}`)
return reduce(str, part.content, i, parts)
}, '')

2
package-lock.json generated
View File

@ -1,5 +1,5 @@
{
"name": "multiaddr-to-stupid-string",
"name": "multiaddr-to-uri",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,

View File

@ -1,7 +1,7 @@
{
"name": "multiaddr-to-stupid-string",
"name": "multiaddr-to-uri",
"version": "1.0.0",
"description": "Convert a Multiaddr to a stupid string /dnsaddr/ipfs.io/http -> http://ipfs.io",
"description": "Convert a Multiaddr to a URI /dnsaddr/ipfs.io/http -> http://ipfs.io",
"main": "index.js",
"scripts": {
"test": "npm run lint && npm run test:coverage",
@ -25,10 +25,10 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/tableflip/multiaddr-to-stupid-string.git"
"url": "git+https://github.com/tableflip/multiaddr-to-uri.git"
},
"bugs": {
"url": "https://github.com/tableflip/multiaddr-to-stupid-string/issues"
"url": "https://github.com/tableflip/multiaddr-to-uri/issues"
},
"homepage": "https://github.com/tableflip/multiaddr-to-stupid-string#readme"
"homepage": "https://github.com/tableflip/multiaddr-to-uri#readme"
}

View File

@ -1,5 +1,5 @@
const test = require('ava')
const toStupid = require('./')
const toUri = require('./')
test('should convert multiaddr to stupid', (t) => {
const data = [
@ -76,9 +76,9 @@ test('should convert multiaddr to stupid', (t) => {
]
]
data.forEach(d => t.is(toStupid(d[0]), d[1]))
data.forEach(d => t.is(toUri(d[0]), d[1]))
})
test('should throw for unsupported protocol', (t) => {
t.throws(() => toStupid('/quic'))
t.throws(() => toUri('/quic'))
})