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-fetch

v3.7.7

Published

Fetch with GunDB

Downloads

203

Readme

gun-fetch

Fetch With GunDB

const path = require('path')
const options = {file: path.resolve('./storage'), relay: false}
// file: path where data will be saved
// relay: boolean, truthy means that gun-fetch will connect to relays, falsy means that gun-fetch will not connect to any relays

const gunFetch = require('gun-fetch')

const fetch = gunFetch(options)

let test = await fetch('gun://hello/test/testing', {method: 'GET'})

let testText = await test.text()

// show the data
console.log(testText)

this readme will be updated soon, there has been a lot of changes, the method HEAD is now supported

special characters

gun-fetch uses special characters to make specific types of queries | Character | Type | | ------------- |:-------------:| | _ | special queries | | - | hex encoded |

usage

METHODS

HEAD:

someHostName or someHostName/somePath, if data is found then code 200 is returned, no body is returned

_someHostName or _someHostName/somePath, if data is found then code 200 is returned, no body is returned

_, only headers are used with a request, no body is returned

HEADERS:

Authorization, hostname must be _someUser or _someUser/somePath, makes a query for a user that is logged in and returns with a code 200 if the data is found

X-Node, hostname must be _, should contain a string which will be the url for the gundb relay, returns X-Node header and code 200 if gun-fetch is connected to the relay

X-Nodes, hostname must be _, should contain a stringified javascript array which will contain the urls of gun relays, returns X-Nodes and code 200 if gun-fetch is connected to all of the relays

X-Peer, hostname must be _, should contain a string which will be the url for the gundb relay, returns X-Peer header and code 200 if gun-fetch connects to the relay

X-Peers, hostname must be _, should contain a stringified javascript array which will contain the urls of gun relays, returns X-Peers and code 200 if gun-fetch connects to all of the relays

more to come

fetch('gun://_', {method: 'HEAD', headers: {'X-Node': 'https://some-gun.relay/gun'}}) | if the method is HEAD and the hostname is only _, then | gun.get(~@someuser)\

fetch('gun://_someuser') | if the text after _ does not contain special characters, then this will be a user/relay query | gun.get(~@someuser)\

fetch('gun://_some.gun-key_here') | if the text after the _ contains special characters, then it will be a public key query | gun.get(~some.pub-key_here)\

fetch('gun://_', {method: 'PUT', body: JSON.stringify({user: 'someuser', pass: 'somepass'})}) | if there is only _ without any text, then this will be a user register/login query | gun.user()\

fetch('gun://somedata') | if there is no _ with text, then it will be a regular query | gun.get(somedata)

fetch('gun://somedata/someotherdata') | if there is no _ with text, then it will be a regular query | gun.get(somedata).get(someotherdata)

fetch('gun://-736f6d657465737474657874') | if there is a - then it will decode the hex encoded query | - means decode 74657374696e67 which decodes into "testing", which means it will be gun.get(testing)

fetch('gun://_', {method: 'GET', headers: {'X-Alias': 'someAliasHere'}}) | if the headers have a headers['X-Alias'] key then it will return whether that alias is logged in or not

fetch('gun://some/data/to/paginate', {method: 'GET', headers: {'X-Paginate': 'someGunDBPaginateObject'}}) | if the headers have a headers['X-Alias'] key then it will return whether that alias is logged in or not

fetch('gun://some/data/to/check', {method: 'GET', headers: {'X-Not': 'true'}}) | if the headers have a headers['X-Alias'] key then it will return whether that alias is logged in or not

fetch('gun://_', {method: 'PUT', headers: {'X-Create': 'someAliasHere'}, body: 'somePasswordHere'}) | if the headers have a headers['X-Create'] key then a new user will be created like gun.user().create()

fetch('gun://_', {method: 'PUT', headers: {'X-Login': 'someAliasHere'}, body: 'somePasswordHere'}) | if the headers have a headers['X-Auth'] key then the user will be logged in like gun.user().auth()

fetch('gun://somedata/some/path/to/data', {method: 'PUT', headers: {'X-Set'}, body: JSON.stringify({message: 'message', data: 'data'})}) | if the headers have a headers['X-Set'] key then the data will be used in a gundb set query like gun.get('somedata').get('some').get('path').get('to').get('data').set({message: 'message', data: 'data'})

fetch('gun://somedata/some/path/to/data', {method: 'PUT', headers: {}, body: JSON.stringify({message: 'message', data: 'data'})}) | if the headers does not have a headers['X-Set'] key then the data will be used in a gundb put query like gun.get('somedata').get('some').get('path').get('to').get('data').put({message: 'message', data: 'data'})

fetch('gun://somedata/some/path/to/data', {method: 'DELETE', headers: {'X-Unset': 'true'}, body: JSON.stringify({message: 'message', data: 'data'})}) | if the headers have a headers['X-Set'] key then the data will be used in a gundb unset query like gun.get('somedata').get('some').get('path').get('to').get('data').unset({message: 'message', data: 'data'})

fetch('gun://somedata/some/path/to/data', {method: 'DELETE', headers: {}, body: JSON.stringify({message: 'message', data: 'data'})}) | if the headers does not have a headers['X-Unset'] key then the data will be null in a gundb put query like gun.get('somedata').get('some').get('path').get('to').get('data').put(null)

fetch('gun://_', {method: 'DELETE', headers: {'X-Logout': 'someAliasHere'}}) | if the headers have a headers['X-Logout'] key then the alias will be logged out like gun.user().leave()

fetch('gun://_', {method: 'DELETE', headers: {'X-Delete': 'somePasswordHere'}, body: 'somePasswordHere'}) | if the headers ave a headers['X-Delete'] key then the alias will be deleted like gun.user().delete()

notes

more to come