Socket
Socket
Sign inDemoInstall

couchdb-tools

Package Overview
Dependencies
5
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

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.


Version published
Weekly downloads
6
Maintainers
1
Install size
1.86 MB
Created
Weekly downloads
 

Readme

Source

couchdb-tools

npm install coucbdb-tools --save

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 in 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)}}'
        }
    }
}

normalise(collection)

Documentation to do.

sync(current,old)

Documentation to do.

clone(obj,obj[,obj...])

Documentation to do.

find(collection,id)

Documentation to do.

equal(a,b)

Documentation to do.

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 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

FAQs

Last updated on 26 Mar 2014

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc