You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

couchdb-tools

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

couchdb-tools

A library of handy functions for use when working with CouchDB documents.

0.0.1
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

couchdb-tools

A library of handy functions for use when working with CouchDB documents. All functions are database adapter agnostic.

Some functions are unique to this library, others are just wrappers around some of the best packages for the job from the Node.JS community - and which case thanks for your hard work :)

ddoc(obj[,name])

Build a JSON/CouchDB compatible design document from a native JavaScript object. The main utility of this function is to translate any map/reduce functions encountered in the design document into tidy JSON-safe strings.

The name parameter is optional, and only required if you wish to create the design document's id too.

Example
var tools = require('couchdb-tools');
var projects = {
    views: {
        projectsById: {
            map: function (doc) {
                if ( doc.type == "project") {
                    emit(doc._id,doc);
                }
            }
        }
    }
}

var projectsDesignDoc = tools.ddoc(projects,'projects');
console.log(projectsDesignDoc);

The following will be output to the console:

{
    _id: '_design/projects',
    views: {
        projectsById: {
            map: 'function(doc){if(doc.type=="project"){emit(doc._id,doc)}}'
        }
    }
}

combine(a,b)

Create a new object that is the result of copying the properties of the second parameter into the first.

Example
var tools = require('couchdb-tools');
var a = {foo:'bar',baz:'qux'};
var b = {foo:'quux',qux:'quuux'};
var combination = tools.combine(a,b);
console.log(combination);

The following will be output to the console:

{
    foo: 'quux',
    baz: 'qux',
    qux: 'quuux'
}

shortid([seed])

Generate URI-safe, short, non-sequential unique ids. Optionally pass in a unique-for-your-app random number seed which will make your ids more secure. Passing the seed only needs to be done once at the start.

Example
var tools = require('couchdb-tools');
tools.shortid(343983);
console.log(tools.shortid());
console.log(tools.shortid());
console.log(tools.shortid());

Similar contents to the following will be output to the console:

FG2Ws27qck
dGEEs27X15
oHeEydIXck

slug(text)

Converts a string into a URI-safe slug. Symbols are removed and foreign characters are coerced into to their English equivalent.

Example

var tools = require('couchdb-tools');
console.log(tools.slug('Hello $$$ world'));

The following will be output to the console:

hello-world

Keywords

couchdb

FAQs

Package last updated on 26 Mar 2014

Did you know?

Socket

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.

Install

Related posts