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

chain-gun

v0.1.2

Published

Gun.js chain API extensions

Downloads

4

Readme

Chaingun

Chaingun

Common Gun.js chain extensions and utility functions.

Install

npm i -S chain-gun

Use

Assuming Babel or similar transpiler setup (2017)

To add all chain methods:

import Gun from 'gun/gun'
import chain from 'chain-gun'
chain(Gun)

To control which chain methods to add:

import {
  add
} from 'chain-gun'
add(Gun, 'date', 'fields')

Import individual chain modules

import {
  print,
  addPrint
} from 'chain-gun/dist/print'
addInspect(Gun.chain)

Require (Node.js)

Using require

const Gun = require('gun/gun')
require('chain-gun')(Gun)

API chain extensions

Also available as utility functions

  • count
  • date
  • each
  • fields
  • local
  • putAt
  • setAt
  • soul
  • timed
  • valueAt
  • value

each

Map and iterate over every value of a node. The second options argument can be called with an op option, which can be used to override the default map operation val. Remaining arguments can contain callback function etc.

each(node, {op}, ...args) or node.each({op}, ...args)

Examples

Utility function

each(node, {op: 'value'})

Chaining

node.each({op: 'value'})

Fine control

node.each({op: 'value'}, (data) => console.log(data))

count

Create a CRDT counter

count(numFun) or node.count(numFun)

date

Add a date field to a Gun node

date(dateValue) or node.date(dateValue)

node.date(new Date())

local

Store locally only (ie. no peer sync)

local(data, cb, opt)

no

no(cb)

value

Retrieve the node value (without _ metadata)

value(cb, opt) or node.value()

mark.value((data) => {
  t.is(data.name, 'mark')
})

valueAt

Retrieve value at the given path (no metadata) Shorthand for node.path('my/path').value(cb)

valueAt(node, path, cb, opt) or node.valueAt(path, cb)

mark.putAt(_path, amber)
mark.valueAt(_path, (spouse) => {
  t.is(spouse.name, 'amber')
})

valAt

Retrieve value at the given path (including _ metadata). Shorthand for node.path('my/path').val(cb)

valAt(node, path, cb, opt) or node.valAt(path, cb)

mark.putAt(_path, amber)
mark.valAt(_path, (spouse) => {
  t.is(spouse.name, 'amber')
})

setAt

set value at the given path. Shorthand for node.path('my/path').set(value)

setAt(node, path, cb, opt) or node.setAt(path, cb, opt)

mark.setAt(_path, amber)
mark.valueAt(_path, (spouse) => {
  t.is(spouse.name, 'amber')
})

putAt

put value at the given path, shorthand for node.path('my/path').set(value)

.putAt(path, cb, opt)

mark.putAt(_path, amber)
mark.valueAt(_path, (spouse) => {
  t.is(spouse.name, 'amber')
})

localFields

localFields() - get list of local field names (keys) in the bucket

let fieldNames = mark.localFields()

fields

Retrieve the names of all fields of the node value (ie. Object keys)

node.fields(cb) or fields(node, cb)

mark.fields((keys) => {
  console.log(keys)
})

soul

soul() retrieve the soul (ID) of the node

let id = mark.soul()

print

print(label) - print value to console (no meta). Note: You can set Gun.log, by default: console.log

amber.print()
mark.print('mark') // with label

Useful internal Gun functions

Gun.obj.copy(val) - copy a value Gun.obj.map(data, function(val, field){ ... } - map over a node Gun.fn.is - check if something is a function Gun.text.random() - generate random text Gun.is.node.soul(data) - test if data has a soul (ie. is a Gun node) Gun.node.soul(data) - return id of Gun node

Please add more internal Gun functions to this list for reference ;)

Useful chain methods

node.back() - go one level back/up in the graph

Contributing

Install dependency modules/packages

npm i

Compile/Build

The project includes a gulpfile configured to use Babel 6. All /src files are compiled to /dist including source maps.

Scripts:

  • start: npm start
  • build: npm run build (ie. compile)
  • watch and start: npm run watch
  • watch and build: npm run watch:b

Run Tests

npm test or simply ava test

License

MIT Kristian Mandrup