
Product
Go Support Is Now Generally Available
Socket's Go support is now generally available, bringing automatic scanning and deep code analysis to all users with Go projects.
Rich document ids for CouchDB:
'movie/blade-runner/gallery-image/12/medium'
_all_docs
_all_docs
)Give DocURIs a try!
Define methods for certain DocURI fragments and provide a routes hash that pairs routes to methods.
DocURI is inspired by Backbone.Router.
Routes can contain parameter parts, :param
, which match a single DocURI component
between slashes; and splat parts *splat
, which can match any number of DocURI
components. Part of a route can be made optional by surrounding it in
parentheses (/:optional)
.
For example, a route of 'movie/:movie_id/gallery-image'
will generate a function which parses
'movie/blade-runner/gallery-image/12'
// =>
{
movie_id: 'blade-runner',
id: '12'
}
and vice versa.
A route of 'movie/:movie_id/:type/*path'
will generate a function which parses
'movie/blade-runner/gallery-image/12'
// =>
{
movie_id: 'blade-runner',
type: 'gallery-image',
path: ['12']
}
// and
'movie/blade-runner/gallery-image/12/medium'
// =>
{
movie_id: 'blade-runner',
type: 'gallery-image',
path: ['12', 'medium']
}
The route 'movie/:movie_id/gallery-image/:id(/:version)'
will generate a
function which parses
'movie/blade-runner/gallery-image/12'
// =>
{
movie_id: 'blade-runner',
id: '12'
}
// as well as
'movie/blade-runner/gallery-image/12/medium'
// =>
{
movie_id: 'blade-runner',
id: '12',
version: 'medium'
}
docuri.route(route)
Create a single route. The route
argument must be a routing string.
// parses 'page/home' as { id: 'home' }:
var page = docuri.route('page/:id');
route(strOrObj, [obj])
The functions generated by DocURI can have a different behaviour, depending on the type and number of the supplied arguments:
route(str)
: parse DocURI string to objectroute(obj)
: generate DocURI string from objectroute(str, obj)
: change DocURI string parts with values provided by object returning a stringThe function returns false
if a string can not be parsed, enabling type
checks.
movie('movie/blade-runner');
// { id: 'blade-runner' }
movieAsset('movie/blade-runner');
// false
galleryImage({ movie_id: 'blade-runner', id: 12 });
// 'movie/blade-runner/gallery-image/12'
galleryImage('movie/blade-runner/gallery-image/12', { version: 'large' });
// 'movie/blade-runner/gallery-image/12/large'
To use DocURI in your client-side application, browserify it like this:
browserify -s DocURI path/to/docuri/index.js > path/to/your/assets
Or grab it from browserify-as-a-service: docuri@latest.
To run the unit tests:
npm test
Copyright (c) 2014 Johannes J. Schmidt, null2 GmbH
Licensed under the Apache 2.0 license.
FAQs
Rich document ids for CouchDB
The npm package docuri receives a total of 721 weekly downloads. As such, docuri popularity was classified as not popular.
We found that docuri demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Go support is now generally available, bringing automatic scanning and deep code analysis to all users with Go projects.
Security News
vlt adds real-time security selectors powered by Socket, enabling developers to query and analyze package risks directly in their dependency graph.
Security News
CISA extended MITRE’s CVE contract by 11 months, avoiding a shutdown but leaving long-term governance and coordination issues unresolved.