npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

couchdb-compile

v1.11.2

Published

Build CouchDB documents from fs.

Downloads

8,403

Readme

couchdb-compile

Build CouchDB documents from directory, JSON or module.

API

compile(source[, options], callback)

  • source - Can be an object, a CouchDB Directory Tree (see below), a JSON file or a CommonJS module
  • options.index - When set to true, folders are searched for index.js, which, if present, is treated as CommonJS module. Default is false.
  • options.multipart - When set to true, attachments are handled as multipart. Default is false.
  • callback - called when done with two arguments: error and doc.

In case options.multipart is set, callback is called with a third argument: attachments. This is a multipart attachments array as required by nanos db.multipart.insert:

{
  name: 'rabbit.png',
  content_type: 'image/png',
  data: <Buffer>
}

data can be a Buffer or a String.

Example

var compile = require('couchdb-compile');
compile('project/couchdb', function(error, doc) {
  // doc is a compile object now
});

CLI

couchdb-compile [SOURCE] [OPTIONS]

When SOURCE is omitted, the current directory will be used.
OPTIONS can be --index and --pretty, see above.

Use --pretty to get a pretty printed json output.

Example

couchdb-compile project/couchdb
couchdb-compile project/couchdb --pretty

Stringifying Functions

If there is a function inside source (passed as object or path to CommonJS module), functions get stringified by calling toString on them.

eg:

compile({
  foo: function () {
    return 42
  }
}, (error, result) => {
  // {
  //   foo: 'function () {\n  return 42\n}'
  // }
})

The CouchDB Directory Tree

couchdb-compile uses a filesystem mapping similar to Couchapp python tool and Erica: The Couchapp Filesystem Mapping.

It is quite self-explanatory. For example:

myapp
├── _id
├── language
└── views
    └── numbers
        ├── map.js
        └── reduce.js

becomes:

{
  "_id": "_design/myapp",
  "language": "javascript",
  "views": {
    "numbers": {
      "map": "function...",
      "reduce": "function..."
    }
  }
}

See test/fixtures and test/expected for usage examples.

IDs

If you do not include an _id property, the filename will be used.

File Extensions

For property names file extensions will be stripped:

{
  "validate_doc_update": "content of validate_doc_update.js",
}

Attachments

Files inside the _attachments directory are handled special: They become attachment entries of the form

{
  "a/file.txt": {
    "data": "SGVsbG8gV29ybGQhCg==",
    "content_type": "text/plain"
  }
}

The content_type is computed using mime, with a fallback to application/octet-stream. data is the base64 encoded value of the file.

Read more about Inline Attachments.

Tests

npm test

(c) 2014-2018 Johannes J. Schmidt Apache 2.0 License