diff --git a/README.md b/README.md index fa147ca..6356a9b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/index.js b/index.js index 9c99113..be9df18 100644 --- a/index.js +++ b/index.js @@ -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) }, '') diff --git a/package-lock.json b/package-lock.json index 04db847..66bbd70 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "multiaddr-to-stupid-string", + "name": "multiaddr-to-uri", "version": "1.0.0", "lockfileVersion": 1, "requires": true, diff --git a/package.json b/package.json index 654ccab..2e8218d 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/test.js b/test.js index 1f846f4..77d36dd 100644 --- a/test.js +++ b/test.js @@ -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')) })