# shortstop

> Enable use of protocols (such as file:, buffer:, or method:) in configuration files.

Latest version **1.1.0** (published 2025-04-02) · 0 weekly downloads

## Install

```sh
npm install shortstop
pnpm add shortstop
yarn add shortstop
bun add shortstop
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2025-04-02 |
| First published | 2013-11-15 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 20.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 55 |
| Author | Erik Toth |
| Maintainers | pvenkatakrishnan, grawk, jonathansamines, dreamsparkx, krakenjs-user |
| Keywords | config, configuration |

## Links

- npm: https://www.npmjs.com/package/shortstop
- Repository: https://github.com/krakenjs/shortstop
- Homepage: https://github.com/krakenjs/shortstop#readme
- Issues: https://github.com/krakenjs/shortstop/issues
- npm.io page: https://npm.io/package/shortstop

## Dependencies (2)

- [async](https://npm.io/package/async.md) ~0.2.10
- [core-util-is](https://npm.io/package/core-util-is.md) ~1.0.1

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2025-04-02
- 1.1.0-beta.3 — 2025-03-31
- 1.1.0-beta.2 — 2025-03-31
- 1.1.0-beta.1 — 2025-03-12
- 1.0.5 — 2024-08-13
- 1.0.4 — 2024-08-09
- 1.0.2 — 2023-02-14
- 1.0.3 — 2015-11-10
- 1.0.1 — 2014-06-23
- 1.0.0 — 2014-03-19
- 0.0.1 — 2013-11-15

## README

shortstop
=========

[![Build Status](https://travis-ci.org/krakenjs/shortstop.svg?branch=master)](https://travis-ci.org/krakenjs/shortstop)  

Sometimes JSON just isn't enough for configuration needs. Occasionally it would be nice to use arbitrary types as values,
but JSON is necessarily a subset of all available JS types. `shortstop` enables the use of protocols and handlers to
enable identification and special handling of json values.

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

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


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

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

resolver.resolve(json, function (err, data) {
    console.log(data);
    // {
    //     "secret": <Buffer ... >,
    //     "ssl" {
    //         "pfx": <Buffer ... >,
    //         "key": <Buffer ... >
    //     }
    // }
});
```

## API
### shortstop.create([parent]);

* `parent` (*Object*, optional) - An optional shortstop resolver. Returns a resolver instance.


### resolver.use(protocol, handler);

* `protocol` (*String*) - The protocol used to identify a property to be processed, e.g. "file"
* `handler` (*Function*) - The implementation of the given protocol with signature `function (value, [callback])`

This method returns a function when invoked will remove the handler from the stack for this protocol.


### resolver.resolve(data, callback);

* `data` (*Object*) - The object, containing protocols in values, to be processed.
* `callback` (*Function*) - The callback invoked when the processing is complete with signature `function (err, result)`.


### resolver.resolveFile(path, callback);

* `path` (*String*) - The path to a file which is, or exports, JSON or a javascript object.
* `callback` (*Function*) - The callback invoked when the processing is complete with signature `function (err, result)`.


## Multiple handlers
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.

```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
        return value;
    }
    return path.join(process.cwd(), value);
}


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);
    // {
    //     "key": <Buffer ... >,
    //     "certs": "/path/to/my/certs/myapp"
    // }
});
```


## Removing Handlers

When registered, handlers return an `unregister` function you can call when you no longer want a handler in the chain.

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


function resolve(value) {
    if (path.resolve(value) === value) {
        // Is absolute path already
        return value;
    }
    return path.join(process.cwd(), value);
}

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);
    // {
    //     "key": "/path/to/my/foo/baz.key"
    // }

    unuse();

    resolver.resolve(json, function (err, data) {
        console.log(data);
        // {
        //     "key": "path:foo/baz.key"
        // }
    });
});
```

---
_Source: https://npm.io/package/shortstop · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
