Package detail

@ipld/garbage

ipld782Apache-2.0 OR MIT6.0.11

Garbage data generator for the IPLD Data Model

IPLD, garbage

readme

@ipld/garbage

codecov CI

Garbage data generator for the IPLD Data Model

Table of contents

Install

$ npm i @ipld/garbage

Based on substack's "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.

import { garbage } from '@ipld/garbage'

console.log(garbage(100, { weights: { float: 0, object: 0 }}))

Might yield:

{
  'QbN/}`EO\tb6>\tI,`': 7827882605575541,
  "~'wD!☺S}<Q|d1$☺": Uint8Array(12) [
    116,  12, 191, 180, 214,
      0,  88,  26, 116, 213,
     88, 109
  ],
  'q<': CID(baguqefrapdjrz7rknhnokqxo75ogs2hfpmdqiy7weez55ezaoyh63sd22n4q)
}

All IPLD Data Model types are within range for random creation, including top-level returns (a single call to garbage() might just return a null):

  • null
  • boolean
  • integer
  • float
  • string
  • bytes
  • list
  • map
  • CID

Use import { toString } from '@ipld/garbage/to-string' to import a function that can turn an object returned by garbage() to a JavaScript string. This may be useful for generating a fixed set of test fixtures rather than relying on randomness during each run.

License

Licensed under either of

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.

changelog

6.0.11 (2025-06-04)

Dependencies

  • dev: bump @sindresorhus/is from 6.3.1 to 7.0.2 (#75) (f1edcb1)

6.0.10 (2025-05-22)

Bug Fixes

Trivial Changes

Dependencies

  • dev: bump aegir from 46.0.5 to 47.0.10 (1e71caa)

6.0.9 (2025-05-08)

Dependencies

  • dev: bump aegir from 45.2.1 to 46.0.0 (09f2f58)

6.0.8 (2024-10-29)

Dependencies

  • dev: bump aegir from 44.1.4 to 45.0.1 (0db5399)

6.0.7 (2024-06-24)

Dependencies

  • dev: bump aegir from 42.2.11 to 44.0.0 (901ef73)

6.0.6 (2024-01-10)

Dependencies

  • dev: bump aegir from 41.3.5 to 42.1.0 (e86d37e)

6.0.5 (2023-12-30)

Dependencies

  • bump multiformats from 12.1.3 to 13.0.0 (#61) (80428ee)

6.0.4 (2023-10-03)

Dependencies

  • dev: bump aegir from 40.0.13 to 41.0.0 (dd7ed82)

6.0.3 (2023-08-28)

Dependencies

  • bump multiformats from 11.0.2 to 12.1.0 (14fe432)
  • dev: bump @sindresorhus/is from 5.6.0 to 6.0.0 (52e5938)

6.0.2 (2023-08-28)

Bug Fixes

Trivial Changes

  • add or force update .github/workflows/js-test-and-release.yml (a2cb066)
  • delete templates [skip ci] (#55) (5bc4292)

Dependencies

  • dev: bump aegir from 37.12.1 to 40.0.11 (5ac2a2f)

6.0.1 (2023-01-03)

Dependencies

  • bump multiformats from 10.0.3 to 11.0.0 (f19e29d)

6.0.0 (2022-10-19)

⚠ BREAKING CHANGES

  • publish as esm-only (#36)

Features

Trivial Changes

  • no-release: bump actions/setup-node from 3.3.0 to 3.4.0 (#30) (f5bb329)
  • no-release: bump actions/setup-node from 3.4.0 to 3.4.1 (#31) (69e12de)
  • no-release: bump actions/setup-node from 3.4.1 to 3.5.0 (#32) (27a9d56)
  • no-release: bump actions/setup-node from 3.5.0 to 3.5.1 (#34) (81dab8c)

Documentation

  • update readme badges and repo links (cfe5d1b)

5.0.0 (2022-06-14)

⚠ BREAKING CHANGES

  • remove Node.js 12.x support (#29)

Trivial Changes

  • no-release: bump @sindresorhus/is from 4.6.0 to 5.1.0 (#28) (2e5ee08)
  • no-release: bump actions/checkout from 2.4.0 to 3 (#20) (7f94712)
  • no-release: bump actions/setup-node from 2.5.0 to 2.5.1 (#18) (a47a558)
  • no-release: bump actions/setup-node from 2.5.1 to 3.0.0 (#19) (d5297a2)
  • no-release: bump actions/setup-node from 3.0.0 to 3.1.1 (#22) (606e04a)
  • no-release: bump actions/setup-node from 3.1.1 to 3.2.0 (#25) (272daa9)
  • no-release: bump actions/setup-node from 3.2.0 to 3.3.0 (#26) (576f82f)
  • no-release: bump polendina from 2.0.15 to 3.0.0 (#24) (03e7e0b)
  • no-release: bump standard from 16.0.4 to 17.0.0 (#23) (4b434a5)
  • remove Node.js 12.x support (#29) (066a2b1)

4.0.10 (2021-12-08)

Trivial Changes

  • deps-dev: bump polendina from 1.1.1 to 2.0.0 (#17) (d7f846e)
  • no-release: bump actions/setup-node from 2.4.1 to 2.5.0 (#16) (48a5b0a)

4.0.9 (2021-11-04)

Trivial Changes

  • deps: bump actions/checkout from 2.3.5 to 2.4.0 (b1dee24)

4.0.8 (2021-10-18)

Trivial Changes

  • deps: bump actions/checkout from 2.3.4 to 2.3.5 (31ddada)

4.0.7 (2021-09-28)

Trivial Changes

  • deps: bump actions/setup-node from 2.4.0 to 2.4.1 (ed3a8b9)

4.0.6 (2021-08-05)

Trivial Changes

  • deps: bump actions/setup-node from 2.3.2 to 2.4.0 (c342987)

4.0.5 (2021-08-05)

Trivial Changes

  • deps: bump actions/setup-node from 2.3.1 to 2.3.2 (cc9edec)

4.0.4 (2021-08-03)

Trivial Changes

  • deps: bump actions/setup-node from 2.3.0 to 2.3.1 (3b8eda4)

4.0.3 (2021-07-20)

Trivial Changes

  • deps: bump actions/setup-node from 2.2.0 to 2.3.0 (8fe05a9)

4.0.2 (2021-07-01)

Trivial Changes

  • deps: bump actions/setup-node from 2.1.5 to 2.2.0 (a4de0e7)

4.0.1 (2021-05-27)

Trivial Changes

  • adjust release rules (f103a92)
  • fix oopsie json (80ca465)
  • further fixes for conventionalcommits handling (c28fe4c)

4.0.0 (2021-05-27)

3.0.6 (2021-05-27)

Bug Fixes

  • build and publish dist (05a89ba)
  • install conventional-changelog-conventionalcommits plugin (1e98e97)