# dat-collections

> collections inside of a dat

Latest version **0.2.1** (published 2017-06-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install dat-collections
pnpm add dat-collections
yarn add dat-collections
bun add dat-collections
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2017-06-24 |
| First published | 2017-05-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Sean Dockray |
| Maintainers | seandockray |

## Links

- npm: https://www.npmjs.com/package/dat-collections
- Repository: https://github.com/sdockray/dat-collections
- Homepage: https://github.com/sdockray/dat-collections#README
- Issues: https://github.com/sdockray/dat-collections/issues
- npm.io page: https://npm.io/package/dat-collections

## Dependencies (6)

- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [bluebird](https://npm.io/package/bluebird.md) ^3.4.7
- [hyperdrive](https://npm.io/package/hyperdrive.md) ^9.1.0
- [dat-storage](https://npm.io/package/dat-storage.md) ^1.0.0
- [pauls-dat-api](https://npm.io/package/pauls-dat-api.md) ^4.2.1
- [hyperdiscovery](https://npm.io/package/hyperdiscovery.md) ^1.3.0

## Recent versions

- 0.2.1 (latest) — 2017-06-24
- 0.2.0 — 2017-06-24
- 0.1.0 — 2017-06-20
- 0.0.9 — 2017-06-11
- 0.0.8 — 2017-05-23
- 0.0.7 — 2017-05-23
- 0.0.6 — 2017-05-23
- 0.0.5 — 2017-05-23
- 0.0.4 — 2017-05-23
- 0.0.3 — 2017-05-22
- 0.0.2 — 2017-05-22
- 0.0.1 — 2017-05-22

## README

# Dat collections

A utility for reading and writing `dat-collections.json` files in the dat root.

## Why?

A dat can have tens of thousands of files (or more) and it's occasionally useful to provide a way to make groupings of the contents. That's the whole purpose of dat-collections.json.

## Usage

So far, you can only list collections, get items in a collection, and getAll items in a collection and all of its subcollections. Eventually, I'd like to add writing data.

```javascript
const archive = new Hyperdrive('./some-hyperdrive');
const collections = new Collections(archive);

# Get all top-level collections
collections.list().then(theList => ...)

# Get a list of contents for a collection (but not its subcollections)
collections.get("collection name 1").then(aList => ...)

# Get a list of contents for a subcollection (but not _its_ subcollections)
collections.get("collection name 2", "subcollection name 1").then(aList => ...)

# Get a list of contents for a collection and all of its subcollections
collections.getAll("collection name 2").then(aList => ...)

# Get a flattened list of contents. aList[0] is the path and aList[1] is collection path
collections.flattened().then(aList => ... )

```

## Format

The `dat-collections.json` file can only handle data formatted in a specific way. Right now it is like:

```json

{
  "collection name 1": [
    "path/to/item 1",
    "path/to/item 2",
    "path/to/item 3"
  ],
  "collection name 2": [
    "path/to/item A",
    "path/to/item 1",
    "path/to/item 2"
  ]
}

```

and actually there is a format where you can also make subcollections. In theory, you can make
as many levels of subcollections as you want, but I've only tested one level down.

```json

{
  "collection name 1": [
    "path/to/item 1",
    "path/to/item 2",
    "path/to/item 3"
  ],
  "collection name 2": {
    "subcollections": {
        "subcollection name 1": [
          "path/to/item 1",
          "path/to/item 2"
        ],
        "subcollection name 2": [
          "path/to/item 2",
          "path/to/item 3"
        ]
    },
    "items": [
      "path/to/item A",
      "path/to/item B"      
    ]
  }
}

```

---
_Source: https://npm.io/package/dat-collections · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
