Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nhz-io/nhz-io-pouch-db-manager-helpers
https://github.com/nhz-io/nhz-io-pouch-db-manager-helpers
Last synced: 22 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/nhz-io/nhz-io-pouch-db-manager-helpers
- Owner: nhz-io
- License: mit
- Created: 2017-11-17T21:56:07.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-18T22:19:00.000Z (about 7 years ago)
- Last Synced: 2024-11-07T05:46:21.359Z (2 months ago)
- Language: CoffeeScript
- Size: 88.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.litcoffee
- License: LICENSE
Awesome Lists containing this project
README
# PouchDB Manager Helpers
[![Travis Build][travis]](https://travis-ci.org/nhz-io/nhz-io-pouch-db-manager-helpers)
[![NPM Version][npm]](https://www.npmjs.com/package/@nhz.io/pouch-db-manager-helpers)## Install
```bash
npm i -S @nhz.io/pouch-db-manager-helpers
```## Usage
```js
const helpers = require('@nhz.io/pouch-db-manager-helpers')...
```## Literate Source
### Helpers
assign = (args...) -> Object.assign {}, args...
allPass = (predicates) ->
predicates = predicates.filter (i) -> i
(test) ->
return for predicate in predicates when not predicate test
true
isObject = (target) -> typeof target is 'object'
priority = (test) -> ['sync', 'live', 'realtime'].indexOf test
### Sanitizers
dbname = (db) -> if isObject db then db.name else db
docid = (doc) -> if isObject doc then doc._id else doc
urlname = (url) ->
url = new URL url
"#{ url.host }#{ url.pathname }"
### Generators
mkkey = (resource) -> switch resource.type
when 'sync' then "#{ resource.local } <-> #{ resource.remote }"
when 'push' then "#{ resource.local } -> #{ resource.remote }"
when 'pull' then "#{ resource.local } <- #{ resource.remote }"
mkconf = (resource, key = mkkey resource) ->
return unless key
{ type, queue, local, remote } = resource
{ key, type, queue, local, remote, retry: false, live: queue in ['realtime', 'live'] }
mkname = (target) ->
name = unless isObject target then target else target.name
unless name.match? /^https?:\/\// then name else urlname name
### Exports
module.exports = {
assign, allPass, isObject, dbname, docid, urlname, mkkey, mkconf, priority, mkname
}## Tests
test = require 'tape-async'
test 'exports', (t) ->
t.plan 1t.deepEqual module.exports, {
assign, allPass, isObject, dbname, docid, urlname, mkkey, mkconf, priority, mkname
}## Version 0.1.7
## License [MIT](LICENSE)
[travis]: https://img.shields.io/travis/nhz-io/nhz-io-pouch-db-manager-helpers.svg?style=flat
[npm]: https://img.shields.io/npm/v/@nhz.io/pouch-db-manager-helpers.svg?style=flat