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

gun-plus

v1.0.0

Published

GunPlus is a package that enhances the functionality and usability of GunDB, a decentralized database, by providing convenience methods and wrapper classes. It simplifies the integration of GunDB into your projects and offers additional features for effic

Downloads

5

Readme

GunPlus

GunPlus is a library that extends the functionality of the decentralized database system Gun by providing convenience functions and wrapper functionality.

Features

  • Define you database and get intellisense.
  • Use streams for retrieving data.
  • Extend gun nodes with common functionality.

Installation

You can install GunPlus via npm:

npm install gun-plus

Usage

// Import GunPlus
import GunPlus from "gun-plus"

// Instantiate the instance. GunPlus is a singleton.
new GunPlus({Gun, SEA}, "your-app-scope");

// Define you database nodes
class UserNode extends GunNode {
	//...
	name = () => GunNode(this.chain.get("name"));
}

// Use convenience functions and wrapper classes
const pair = await GunPlus.SEA.pair();
const user = await GunPlus.auth(pair, UserNode)
user.name.put("Alice");

Initialization

If you are using a fullstack framework like e.g. Svelte.js, importing Gun may accidentally lead to Gun running on the server side. This may not be what you want. The GunPlus.imports function will import gun at runtime, allowing you to do this only on the client side.

// In the browser part of you framework (like onMount in +layout.svelte)
onMount(() => {
	GunPlus.imports().then( imports => new GunPlus(imports, "your-app-scope") );
})

Documentation

For detailed documentation, please refer to the relevant .md file in the docs folder.

Examples:


Every GunNode can be read as a stream that supports async iterators. If the stream is cancelled, GunPlus will automatically unsubscribe the underlying .on gun call.

// Reading as a stream.
for await (const {value, key, node} of user.groups.stream()) {
	if(value) console.log(node.name) // logs group name
}

You can define GunNodes that will carry the correct context when using map on them, by supplying the class in the iterates option.

// Defining an array-like iterable
class UserNode extends GunNode {
	// ...
	get groups() { return new GunNode(this.chain.get("groups"), {iterates: GroupNode}) }
}
class GroupNode extends GunNode {
	get title() { return new GunNode(this.chain.get("name")) };
}

// Using it after getting a reference to a UserNode
user.groups.map().title.stream() // stream of all group titles.

You can wrap any node in whatever of your specified nodes you want by passing it to the soul function.

const user = gp.soul(gp.user.pair({strict: true}).pub, UserNode);
user.groups().title // do something UserNode specific.

const group = gp.soul(group_public_key, GroupNode);
group.title // do something GroupNode specific.

Contributing

We welcome contributions! If you'd like to contribute to GunPlus, please see our Contribution Guidelines.

License

GunPlus is licensed under the MIT License.