https://github.com/ipld/js-ipld-garbage
Generate garbage objects conformant with the IPLD Data Model
https://github.com/ipld/js-ipld-garbage
Last synced: about 1 month ago
JSON representation
Generate garbage objects conformant with the IPLD Data Model
- Host: GitHub
- URL: https://github.com/ipld/js-ipld-garbage
- Owner: ipld
- License: other
- Created: 2020-12-17T10:50:40.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-06-04T10:34:51.000Z (about 1 year ago)
- Last Synced: 2025-08-08T18:09:41.011Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 368 KB
- Stars: 2
- Watchers: 17
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @ipld/garbage
[](https://codecov.io/gh/ipld/js-ipld-garbage)
[](https://github.com/ipld/js-ipld-garbage/actions/workflows/js-test-and-release.yml)
> Garbage data generator for the IPLD Data Model
## Table of contents
- [Install](#install)
- [API](#api)
- [`options`](#options)
- [License](#license)
- [Contribute](#contribute)
## Install
```console
$ npm i @ipld/garbage
```
Based on [substack's "garbage"](https://github.com/substack/node-garbage).
## API
`garbage(count = 200, options)`
Where `count` determines the approximate target number of bytes a garbage object should consume. And `options` allows for a `weight` object that allows you to provide a number for each object type to weight the random garbage generator. By default, all object types are weighted equally (with a value of `1`), providing a number (>= `0`), you can adjust the liklihood that particular types will appear relative to the weights of the other types. A weighting of `0` will turn off that type entirely.
### `options`
- `options.weights` an object with properties matching the IPLD data model types (see below) with numbers (>= `0`) that will weight randomness selection. Default: `{ list: 1, map: 1, string: 1, bytes: 1, boolean: 1, integer: 1, float: 1, null: 1, CID: 1 }`.
- `options.initialWeights` an object, similar to `options.weights`, that only applies to the initial object. Subsequent object creation will use `options.weights`. This allows for weighting of the container object to be more typical of IPLD data, which is typically some kind of map or list. Default `{ list: 10, map: 10, string: 1, bytes: 1, boolean: 1, integer: 1, float: 1, null: 1, CID: 1 }`.
Where you provide a custom `weights`, it will override `initialWeights`. e.g. `{ weights: { float: 0 } }` will result in no floats at all, even for the initial object.
```js
import { garbage } from '@ipld/garbage'
console.log(garbage(100, { weights: { float: 0, object: 0 }}))
```
Might yield:
```js
{
'QbN/}`EO\tb6>\tI,`': 7827882605575541,
"~'wD!☺S})
- MIT ([LICENSE-MIT](LICENSE-MIT) / )
## Contribute
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.