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

ipfs-mini

v1.1.5

Published

A super tiny module for querying an IPFS node that works in nodejs and the browser.

Downloads

2,021

Readme

ipfs-mini

A super tiny module for querying an IPFS node, that works in the browser and in Node. Only 2.76 kB compressed!

This module was inspired by browser-ipfs.

Install

npm install --save ipfs-mini

Usage

const IPFS = require('ipfs-mini');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.add('hello world!').then(console.log).catch(console.log);

// result null 'QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j'

ipfs.cat('QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j', (err, result) => {
  console.log(err, result);
});

// result null 'hello world!'

ipfs.addJSON({ somevalue: 2, name: 'Nick' }, (err, result) => {
  console.log(err, result);
});

// result null 'QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j'

ipfs.catJSON('QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j').then(console.log).catch(console.log);

// result null { somevalue: 2, name: 'Nick' }

About

A very simple module for querying an IPFS node. This module works for both nodejs and in the browser. It's extremly light, <3 kB when compressed.

This module uses the js-ipfs-api module for the adding operations on nodejs. However, in the browser, it uses a very light FormData Blob handling proceedure which was designed by Pelle Braendgaard, in his browser-ipfs module.

Examples

An example of the module in use for the browser, can be found in ./example.

Inside is a single, no configuration required, HTML file using the ipfs-mini module.

Browser Usage

ipfs-mini is completely browserifiable and webpack ready. The main export found in our distributions dist folder is IPFS. There you will find two builds of ipfs-mini, one compressed and minified ipfs-mini.min.js and one uncompressed ipfs-mini.js.

<html>
  <body>
    <script type="text/javascript" src="ipfs-mini.min.js">
    <script type="text/javascript">
      var ipfs = new IPFS({ provider: 'ipfs.infura.io', protocol: 'https' });

      // ...
    </script>
  </body>
</html>

Webpack Figures

2.76 kB compressed (not gzipped)

Hash: 55d261679ea2edac14af                                                         
Version: webpack 2.1.0-beta.15
Time: 612ms
        Asset     Size  Chunks             Chunk Names
    ipfs-mini.js  9.55 kB       0  [emitted]  main
ipfs-mini.js.map    11 kB       0  [emitted]  main
    + 3 hidden modules

Hash: 20584eb8548f596cd97d                                                         
Version: webpack 2.1.0-beta.15
Time: 737ms
        Asset     Size  Chunks             Chunk Names
ipfs-mini.min.js  2.76 kB       0  [emitted]  main
    + 3 hidden modules

API Design

constructor

index.js:ipfs-mini

Intakes a single provider object, outputs an ipfs instance.

Parameters

  • provider Object a single provider object, see setProvider for more details

Result output ipfs Object instance.

const IPFS = require('ipfs-mini');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.cat('QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j', (err, result) => {
  console.log(err, result);
});

setProvider

index.js:ipfs-mini

Sets the IPFS instance provider.

Parameters

  • provider Object a single provider object.

    default: { host: 'localhost', port: 5001, protocol: 'http', base: '/api/v0' }

No result output.

const IPFS = require('ipfs-mini');
const ipfs = new IPFS();

ipfs.setProvider({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.cat('QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j', cb);

add

index.js:ipfs-mini

Queries /add and adds a single String or Buffer data to IPFS, returns an IPFS hash.

Parameters

  • input String|Buffer the input data to be added to IPFS.

Result output ipfsHash String.

const IPFS = require('ipfs-mini');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.add('hello world!', (err, result) => {
  console.log(err, result);
});

// result null 'QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j'

addJSON

index.js:ipfs-mini

Queries /add and adds stringified JSON to IPFS, returns a single ipfs hash.

Parameters

  • input Object the input data to be added to IPFS.

Result output ipfsHash String.

const IPFS = require('ipfs-mini');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.addJSON({ somevalue: 2, name: 'Nick' }, (err, result) => {
  console.log(err, result);
});

// result null 'QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j'

cat

index.js:ipfs-mini

Queries a /cat request, returns data as a String.

Parameters

  • ipfsHash String the ipfs hash string.

Result output data String.

const IPFS = require('ipfs-mini');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.cat('QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j', (err, result) => {
  console.log(err, result);
});

// result null 'Hello world!'

catJSON

index.js:ipfs-mini

Queries a /cat request, returns data as a parsed JSON object.

Parameters

  • ipfsHash String the ipfs hash string.

Result output data Object.

const IPFS = require('ipfs-mini');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.catJSON('QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j', (err, result) => {
  console.log(err, result);
});

// result null { somevalue: 2, name: 'Nick' ...}

stat

index.js:ipfs-mini

Queries a /object/stat request, returns data stats object.

Parameters

  • ipfsHash String the ipfs hash string.

Result output stats data Object.

const IPFS = require('ipfs-mini');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.stat('QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j', (err, result) => {
  console.log(err, result);
});

/* result null {
  BlockSize: 14595
  CumulativeSize: 14595
  DataSize: 14592
  Hash: "QmbhrsdhbvQy3RyNiDdStgF4YRVc4arteS3wL5ES5M6cVd"
  LinksSize: 3
  NumLinks: 0
}
*/

Contributing

Please help better the ecosystem by submitting issues and pull requests to default. We need all the help we can get to build the absolute best linting standards and utilities. We follow the AirBNB linting standard and the unix philosophy.

Help out

There is always a lot of work to do, and will have many rules to maintain. So please help out in any way that you can:

  • Create, enhance, and debug silentcicero rules (see our guide to "Working on rules").
  • Improve documentation.
  • Chime in on any open issue or pull request.
  • Open new issues about your ideas for making ipfs-mini better, and pull requests to show us how your idea works.
  • Add new tests to absolutely anything.
  • Create or contribute to ecosystem tools, like modules for encoding or contracts.
  • Spread the word.

Please consult our Code of Conduct docs before helping out.

We communicate via issues and pull requests.

Important documents

Licence

This project is licensed under the MIT license, Copyright (c) 2016 Nick Dodson. For more information see LICENSE.md.

The MIT License

Copyright (c) 2016 Nick Dodson. nickdodson.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.