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

shirokuma

v0.1.3

Published

TypeScript SDK to easily write p2panda applications

Downloads

2

Readme

This library provides all tools required to write an p2panda application in TypeScript, running in any modern web browser.

Installation

To install shirokuma run:

npm i shirokuma

Example

import { KeyPair, Session, initWebAssembly } from 'shirokuma';

// This method needs to be run once before to initialise the embedded
// WebAssembly code in this package
await initWebAssembly();

// This example uses the "chat" schema at which this hash is pointing
const CHAT_SCHEMA =
  'chat_message_0020a654068b26617ebd6574b1b03853193ccab2295a983bc85a5891793422832655';

// Create a key pair
const keyPair = new KeyPair();

// Open a long running connection to a p2panda node and configure it so all
// calls in this session are executed using that key pair
const session = new Session('http://localhost:2020/graphql').setKeyPair(keyPair);

// Compose your operation payload, according to chosen schema
const fields = {
  message: 'Hi there',
};

// Create and send a new chat message to the node
await session.create(fields, { schemaId: CHAT_SCHEMA });

Usage

shirokuma runs both in NodeJS and web browsers and comes as a ES and CommonJS module. It can easily be integrated into Webpack, Rollup or other tools.

Since shirokuma contains WebAssembly code, it is necessary to initialise it before using the methods in the Browser. This initialisation step is not required in NodeJS contexts.

To make this step a little bit easier shirokuma inlines the WebAssembly code as a base64 string which gets decoded automatically during initialisation. For manual initialisation the package also comes with "slim" versions where you need to provide a path to the ".wasm" file yourself.

Browser

To quickly get started, you can run shirokuma in any modern browser as an ES module like that. Note that this uses the bundled version, with all 3rd party dependencies included plus the WebAssembly code itself:

<script type="module">
  import { initWebAssembly, KeyPair } from 'https://cdn.jsdelivr.net/npm/[email protected]/lib/esm-bundle/index.min.js';

  initWebAssembly().then(() => {
    const keyPair = new KeyPair();
    console.log(keyPair.publicKey());
  });
</script>

NodeJS

import { KeyPair } from 'shirokuma';
const keyPair = new KeyPair();
console.log(keyPair.publicKey());

Bundlers

import { initWebAssembly, KeyPair } from 'shirokuma';

// This only needs to be done once before using all `shirokuma` methods
await initWebAssembly();

const keyPair = new KeyPair();
console.log(keyPair.publicKey());

Manually load .wasm

Running shirokuma automatically inlines the WebAssembly inside the JavaScript file, encoded as a base64 string. While this works for most developers, it also doubles the size of the imported file. To avoid larger payloads and decoding times you can load the .wasm file manually by using a "slim" version. For this you need to initialise the module by passing the path to the file into initWebAssembly:

// Import from `slim` module to manually initialise WebAssembly code
import { initWebAssembly, KeyPair } from 'shirokuma/slim';
import wasm from 'shirokuma/p2panda.wasm';

// When running shirokuma in the browser, this method needs to run once
// before using all other methods
await initWebAssembly(wasm);

const keyPair = new KeyPair();
console.log(keyPair.publicKey());

Development

# Install dependencies
npm install

# Check code formatting
npm run lint

# Run tests
npm test

# Bundle js package
npm run build

Documentation

# Generate documentation
npm run docs

# Show documentation in browser
npx serve ./docs

License

GNU Affero General Public License v3.0 AGPL-3.0-or-later

Supported by

This project has received funding from the European Union’s Horizon 2020 research and innovation programme within the framework of the NGI-POINTER Project funded under grant agreement No 871528