From a3efadd2c2d5d77911ec10efdffc05b573e4c1d5 Mon Sep 17 00:00:00 2001 From: Stephen Whitmore Date: Mon, 11 Apr 2016 16:01:48 -0700 Subject: [PATCH] readme <3 --- README.md | 218 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 165 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index a0dd3616..4a9ba51a 100644 --- a/README.md +++ b/README.md @@ -10,108 +10,220 @@ js-multiaddr > [multiaddr](https://github.com/jbenet/multiaddr) implementation in JavaScript. -# Usage +# What is multiaddr? -### In Node.js through npm +A standard way to represent addresses that -```bash -> npm install multiaddr --save +- support any standard network protocol +- are self-describing +- have a binary packed format +- have a nice string representation +- encapsulate well + +# Example + +```js +$ node + +> const multiaddr = require('multiaddr') + +> const addr = multiaddr("/ip4/127.0.0.1/udp/1234") + + +> addr.buffer + + +> addr.toString() +'/ip4/127.0.0.1/udp/1234' + +> addr.protos() +[ + {code: 4, name: 'ip4', size: 32}, + {code: 17, name: 'udp', size: 16} +] + +> addr.nodeAddress() +{ + family: "IPv4", + port: 1234, + address: "127.0.0.1" +} + +> addr.encapsulate('/sctp/5678') + ``` -```JavaScript +# API + +```js const multiaddr = require('multiaddr') ``` -### In the Browser through Webpack +## Create -Same as in Node.js, you just have to transpile it with Webpack before serving the code. Follow the webpack config example. +### const addr = multiaddr(str) -### In the Browser through browserify +Creates a multiaddress from a string (e.g. `/ip4/127.0.0.1/udp/1234`). -Same as in Node.js, you just have to [browserify](https://github.com/substack/node-browserify) the code before serving it. See the browserify repo for how to do that. +### const addr = multiaddr(buf) -### In the Browser through `