Skip to content

Commit

Permalink
Update documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
totherik committed Feb 27, 2014
1 parent d0ce6f8 commit 0bb68b2
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,32 @@ but JSON is necessarily a subset of all available JS types. `shortstop` enables
enable identification and special handling of json values.

#### The Basics

```json
{
"secret": "buffer:SGVsbG8sIHdvcmxkIQ==",
"ssl": {
"pfx": "file:foo/bar",
"key": "file:foo/baz.key",
}
}
```

```javascript
var fs = require('fs');
var shortstop = require('shortstop');


function buffer(value) {
return new Buffer(value);
}


function file(value, cb) {
return fs.readFile(value, cb);
}


var resolver = shortstop.create();
var resolver, json;
resolver = shortstop.create();
resolver.use('buffer', buffer);
resolver.use('file', file);

json = {
"secret": "buffer:SGVsbG8sIHdvcmxkIQ==",
"ssl": {
"pfx": "file:foo/bar",
"key": "file:foo/baz.key",
}
};

resolver.resolve(json, function (err, data) {
console.log(data);
// {
Expand All @@ -57,19 +53,11 @@ resolver.resolve(json, function (err, data) {
Multiple handlers can be registered for a given protocol. They will be executed in the order registered and the output
of one handler will be the input of the next handler in the chain.

```json
{
"key": "file:foo/baz.key",
"certs": "path:certs/myapp"
}
```

```javascript
var fs = require('fs'),
var path = require('path'),
var shortstop = require('shortstop');


function resolve(value) {
if (path.resolve(value) === value) {
// Is absolute path already
Expand All @@ -79,13 +67,17 @@ function resolve(value) {
}


var resolver, data;
var resolver, json;
resolver = shortstop.create();
resolver.use('path', resolve);

resolver.use('file', resolve);
resolver.use('file', fs.readFile);

json = {
"key": "file:foo/baz.key",
"certs": "path:certs/myapp"
}

resolver.resolve(json, function (err, data) {
console.log(data);
// {
Expand Down Expand Up @@ -125,10 +117,14 @@ function resolve(value) {
return path.join(process.cwd(), value;
}

var resolver, unuse, data;

var resolver, unuse, json;
resolver = shortstop.create();
unuse = resolver.use('path', resolve);

json = {
"key": "path:foo/baz.key"
}

resolver.resolve(json, function (err, data) {
console.log(data);
// {
Expand Down

0 comments on commit 0bb68b2

Please sign in to comment.