npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ipld/garbage

v6.0.6

Published

Garbage data generator for the IPLD Data Model

Downloads

354

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.