Gathering detailed insights and metrics for pouchdb-collate
Gathering detailed insights and metrics for pouchdb-collate
Gathering detailed insights and metrics for pouchdb-collate
Gathering detailed insights and metrics for pouchdb-collate
@rasgo/pouchdb-collate
Collation functions for PouchDB map/reduce
@coderobot960/pouchdb-collate-react-native
Collation functions for PouchDB map/reduce
rn-patched-pouchdb-collate
Collation functions for PouchDB map/reduce
@guarda-co/pouchdb-collate
Collation functions for PouchDB map/reduce
🦘 - PouchDB is a pocket-sized database.
npm install pouchdb-collate
Typescript
Module System
Node Version
NPM Version
100
Supply Chain
99.5
Quality
83
Maintenance
100
Vulnerability
100
License
JavaScript (98.77%)
Shell (0.68%)
HTML (0.51%)
Dockerfile (0.03%)
Total Downloads
16,710,031
Last Day
2,994
Last Week
52,464
Last Month
220,234
Last Year
2,393,299
Apache-2.0 License
17,303 Stars
5,248 Commits
1,472 Forks
265 Watchers
1,553 Branches
375 Contributors
Updated on Jul 01, 2025
Minified
Minified + Gzipped
Latest Version
9.0.0
Package Id
pouchdb-collate@9.0.0
Unpacked Size
35.27 kB
Size
9.00 kB
File Count
5
NPM Version
10.7.0
Node Version
20.11.1
Published on
Jun 21, 2024
Cumulative downloads
Total Downloads
Last Day
-21.5%
2,994
Compared to previous day
Last Week
-8.2%
52,464
Compared to previous week
Last Month
11.3%
220,234
Compared to previous month
Last Year
-1.6%
2,393,299
Compared to previous year
Collation functions for PouchDB map/reduce. Used by PouchDB map/reduce to maintain consistent CouchDB collation ordering.
The PouchDB Collate API is not exposed by PouchDB itself, but if you'd like to use it in your own projects, it's pretty small, and it has a few functions you may find useful.
1npm install pouchdb-collate
1var pouchCollate = require('pouchdb-collate');
This package is conceptually an internal API used by PouchDB or its plugins. It does not follow semantic versioning (semver), and rather its version is pegged to PouchDB's. Use exact versions when installing, e.g. with --save-exact
.
PouchDB and its sub-packages are distributed as a monorepo.
For a full list of packages, see the GitHub source.
This is probably the most useful function in PouchDB Collate. It converts any object to a serialized string that maintains proper CouchDB collation ordering in both PouchDB and CouchDB (ignoring some subtleties with ICU string ordering in CouchDB vs. ASCII string ordering in PouchDB).
So for example, if you want to sort your documents by many properties in an array, you can do e.g.:
1var pouchCollate = require('pouchdb-collate'); 2var myDoc = { 3 firstName: 'Scrooge', 4 lastName: 'McDuck', 5 age: 67, 6 male: true 7}; 8// sort by age, then gender, then last name, then first name 9myDoc._id = pouchCollate.toIndexableString( 10 [myDoc.age, myDoc.male, mydoc.lastName, mydoc.firstName]);
The doc ID will be:
1'5323256.70000000000000017764\u000021\u00004McDuck\u00004Scrooge\u0000\u0000'
Which is of course totally not human-readable, but it'll sort everything correctly (floats, booleans, ints – you name it). If you need a human-readable doc ID, check out the DocURI project.
Warning! If you are syncing or storing docs in CouchDB, then you will need to modify these doc IDs, due to a bug in how Chrome parses URLs, which causes problems in the replicator when it tries to GET
docs at those URLs.
In short, you will need to replace all the \u0000
characters with some other separator. Assuming you're storing text data and not binary data, \u0001
should be fine:
1pouchCollate.toIndexableString([/* ... */]) 2 .replace(/\u0000/g, '\u0001');
Same as the above, but in reverse. Given an indexable string, it'll give you back a structured object.
For instance:
1var pouchCollate = require('pouchdb-collate'); 2 3// [ 67, true, 'McDuck', 'Scrooge' ] 4pouchCollate.parseIndexableString( 5 '5323256.70000000000000017764\u000021\u00004McDuck\u00004Scrooge\u0000\u0000')
Give it two objects, and it'll return a number comparing them. For example:
1pouchCollate.collate('foo', 'bar'); // 1 2pouchCollate.collate('bar', 'foo'); // -1 3pouchCollate.collate('foo', 'foo'); // 0
Of course it sorts more than just strings - any valid JavaScript object is sortable.
You shouldn't need to use this, but this function will normalize the object and return what CouchDB would expect - e.g. undefined
becomes null
, and Date
s become date.toJSON()
. It's basically what you would get if you called:
1JSON.parse(JSON.stringify(obj));
but a bit faster.
No vulnerabilities found.
Reason
all changesets reviewed
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
6 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
32 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More