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

reticle

v0.3.0

Published

Scope your gunDB apps

Downloads

7

Readme

Reticle

Put a scope on gunDB.

npmTravis branchGitter

What it is

Reticle is a tool built for gunDB

By default, gun's data is global. If you use the same key by accident on a different app, both datasets will merge into one frankensteinian nightmare. Reticle solves this by namespacing your keys under a hashed string, preventing otherwise gruesome conflicts from ever happening.

How it works

You can scope your databases under a name, like Todo List, and Reticle will produce a hashed string ('7b3ozc') and automatically upgrade your context to use that new namespace.

Including

Node.js

To use Reticle in node, require('reticle') in your app. Reticle is version agnostic when it comes to gunDB, and since you may be using multiple versions of gun with node, Reticle needs an explicit reference to the constructor you want to extend.

var Gun = require('gun')

// reticle automatically upgrades gun
require('reticle')

Browser

To use Reticle in the browser, you can include it as a script tag.

<script src="reticle.min.js"></script>

Since Gun is exported to the global namespace, Reticle knows what version you're using and can automatically attach itself.

API

Reticle exposes two methods through Gun...

  • one on the constructor: Gun.scope
  • one on each instance: gun.scope

To set a scope for every gun instance you create, use the constructor method.

Gun.scope('Todo List')

// both are scoped under "Todo List"
var list = Gun().get('list')
var items = Gun().get('list/items')

To scope just one instance, use the instance method.

var gun = Gun().scope('Todo List').get('list/items');

Once the scope has been set, it will remain the same until changed again.

Scope names are case sensitive

Examples

Using two instances without collision

var fleetPlayers, tracePlayers;
fleetPlayers = Gun().scope('battlefleet').get('players')
tracePlayers = Gun().scope('trace').get('players')

fleetPlayers.put({
  'Player 0': 'Bob'
})
tracePlayers.put({
  'Player 0': 'Dave'
})
fleetPlayers.path('Player 0').val() // "Bob"
tracePlayers.path('Player 0').val() // "Dave"

Edge cases

Reticle will try to convert input to a string so it can hash it. If the value it's given is a isn't a string, Reticle will try to convert it. If the value is falsy, gun will revert to it's global behavior. For example, if you call .scope with null or empty string "", your namespace is global. There is no prefix.

Previous versions of gun have mixed support for the uuid option in the gun constructor. To be sure the UUIDs are scoped properly, the Gun.text.random function was overloaded. If you're using that function, you may notice the output being prepended with a scope.

Support

If you find any problems or know of a way to improve Reticle (or gun for that matter), send us a message on Gitter. We're almost always on that channel.