(fixes #8) - Make it work as CouchDB CommonJS

Do not export a function.
`docuri()` is now called `docuri.definition()`.
pull/9/head
Johannes J. Schmidt 10 years ago
parent 4da8a2b0a2
commit ac4af0f980

@ -74,21 +74,21 @@ docuri.arity({ type: 'mytype', subtype: 'mysubtype' });
// 3 // 3
``` ```
### `docuri([definition])` ### `docuri.definition([array])`
Use custom definition: Access or use custom definition:
```js ```js
docuri(); docuri.definition();
// ['type', 'id', 'subtype', 'index', 'version'] // ['type', 'id', 'subtype', 'index', 'version']
docuri(['id', 'meta']); docuri
docuri(); .definition(['id', 'meta'])
// ['id', 'meta'] .parse('42/answer');
docuri.parse('42/answer');
// { // {
// id: '42', // id: '42',
// meta: 'answer' // meta: 'answer'
// } // }
``` ```
Note: `definition` MUST be an array of strings with at least one item. Note: the (optional) argument to `docuri.definition` MUST be an array of strings
containing at least one item.
## Browser support ## Browser support

@ -7,8 +7,11 @@
// type/id/subtype/index/version // type/id/subtype/index/version
var DEFINITION = ['type', 'id', 'subtype', 'index', 'version']; var DEFINITION = ['type', 'id', 'subtype', 'index', 'version'];
var docuri;
function docuri(definition) { module.exports = exports = docuri = {};
docuri.definition = function(definition) {
if (definition) { if (definition) {
DEFINITION = definition; DEFINITION = definition;

@ -1,6 +1,6 @@
{ {
"name": "docuri", "name": "docuri",
"version": "2.2.0", "version": "3.0.0",
"description": "Rich document ids for CouchDB", "description": "Rich document ids for CouchDB",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

@ -1,28 +0,0 @@
var test = require('tap').test;
var docuri = require('..');
test('default configuration', function(t) {
t.deepEqual(docuri(), ['type', 'id', 'subtype', 'index', 'version'], 'should return default parts');
t.end();
});
test('set configuration', function(t) {
var parts = ['my', 'parts'];
t.type(docuri(parts).merge, 'function', 'should return docuri api: merge');
t.type(docuri(parts).parse, 'function', 'should return docuri api: parse');
t.type(docuri(parts).stringify, 'function', 'should return docuri api: stringify');
t.end();
});
test('change configuration', function(t) {
var parts = ['my', 'parts'];
docuri(parts);
t.deepEqual(docuri(), parts, 'should return custom parts');
t.end();
});
test('use changed configuration', function(t) {
var parts = ['my', 'parts'];
t.deepEqual(docuri(parts).parse('one/two'), { my: 'one', parts: 'two'}, 'should use custom parts');
t.end();
});

@ -0,0 +1,28 @@
var test = require('tap').test;
var definition = require('..').definition;
test('default configuration', function(t) {
t.deepEqual(definition(), ['type', 'id', 'subtype', 'index', 'version'], 'should return default parts');
t.end();
});
test('set configuration', function(t) {
var parts = ['my', 'parts'];
t.type(definition(parts).merge, 'function', 'should return docuri api: merge');
t.type(definition(parts).parse, 'function', 'should return docuri api: parse');
t.type(definition(parts).stringify, 'function', 'should return docuri api: stringify');
t.end();
});
test('change configuration', function(t) {
var parts = ['my', 'parts'];
definition(parts);
t.deepEqual(definition(), parts, 'should return custom parts');
t.end();
});
test('use changed configuration', function(t) {
var parts = ['my', 'parts'];
t.deepEqual(definition(parts).parse('one/two'), { my: 'one', parts: 'two'}, 'should use custom parts');
t.end();
});
Loading…
Cancel
Save