Browse Source

publish javascript api as an npm module

ansuz 7 years ago
parent
commit
f35456b940
2 changed files with 54 additions and 0 deletions
  1. 29 0
      README.md
  2. 25 0
      package.json

+ 29 - 0
README.md

@@ -70,3 +70,32 @@ By following this scheme, we make it possible for users to programmatically find
 Credential files must end with `.k`.
 Otherwise, you can name your file whatever you want, but for simplicity's sake, avoid characters which will need to be escaped at the command line.
 
+## Javascript API
+
+Peering credentials in this repository can be accessed via a simple Javascript API (using Nodejs).
+
+It's available as a module on npm:
+
+`npm install hyperboria-peers`
+
+### Usage
+
+```Javascript
+var Peers = require("./index.js");
+
+/*  return a list of public peers located in North America */
+Peers.filter(function (creds, path) {
+    return path.indexOf('NA') !== -1;
+});
+
+/*  return a list of public keys */
+Peers.map(function (creds, path) {
+    return creds[Object.keys(creds)[0]].publicKey;
+});
+
+/*  the underlying data is exposed in a nested json structure */
+console.log(Peers.peers);
+
+console.log(Peers.peers.NA.us.california);
+```
+

+ 25 - 0
package.json

@@ -0,0 +1,25 @@
+{
+  "name": "hyperboria-peers",
+  "version": "1.0.0",
+  "description": "A geographically sorted list of public peering credentials for joining Hyperboria",
+  "main": "index.js",
+  "scripts": {
+    "test": "node tests.js"
+  },
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/hyperboria/peers.git"
+  },
+  "keywords": [
+    "hyperboria",
+    "fc00",
+    "public",
+    "peers"
+  ],
+  "author": "ansuz",
+  "license": "AGPL-3.0",
+  "bugs": {
+    "url": "https://github.com/hyperboria/peers/issues"
+  },
+  "homepage": "https://github.com/hyperboria/peers#readme"
+}