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

twister-lib-js

v0.4.1

Published

A javascript library for twister (see twister.net.co)

Downloads

20

Readme

twister-lib-js

A Twister Library in JavaScript

Scope of this Project

twister-lib-js handles all querying and manipulation of the Twister P2P network, given the availability of a (remote or local) twisterd JSON-RPC endpoint. This includes managing the network resource, by bundleing queries and by caching. This also includes the ability sign posts and to encrypt and decrypt direct messages locally.

twister-lib-js should be compilable for as many platforms as possible including:

  • All popular Browsers (for web apps as well as firefoxOS)
  • node-js (for server-side functionality)
  • The iOS Javascript VM (for building native iOS apps)
  • The Android Javascript VM (for building native android apps)

A techdemo of twister-lib-js combined with react-js can be found at http://github.com/Tschaul/twister-react

Implementation Status

Resource | query | manipulate (client side wallet) | manipulate (server side wallet) ------|-----|-----|------| Posts | ✓ | ✓ | ✓ Replies | ✓ | ✓ | ✓ Retwists | ✓ | ✓ | ✓ Profile | ✓ | ✓ | ✓ Avatar | ✓ | ✓ | ✓ Followings | ✓ | ✓ | ✓ Mentions | ✓ | ✓ | - Hashtags | ✓ | ✓ | - Promoted Posts| ✓ | - | - Direct Messages| - | - | ✓ Group Messages| - | - | -

Todo

Next Version

  • Implement methods to create or import accounts.
  • Implement group chats

At Some Point

  • Implement bind-methods (e.g. bindProfile(...) ) that repeatedly queries the resource and invokes a callback function for every update.
  • When posting a new resource revision (status, profile, avatar...) add the updated resource to the cache but flag it as "dirty" and rollback if the resource is not confirmed after a certain time.
  • Implement get...Promise(...) functions (e.g. getProfilePromise(...) ) that work with https://github.com/yortus/asyncawait to avoid callback hells
  • Implement code specific error functions (e.g. "errorfunc_32052" catches errors with code 32052)

Usage

In a Node Project

From inside the project folder run

npm install twister-lib-js

Then inside your code import the library using

Twister = require('twister-lib-js');

In a Webapp

Download the twister-lib.js file into you project folder. Link to it inside html using

<script src="path/to/twister-lib.js"></script>

Code Examples

Display the content of the latest post of user tschaul:

Twister.getUser("tschaul").doStatus(function(post){
  console.log(post.getContent());  
});

For more code examples in tutorial form, see /examples

Error Codes

twister-lib-js passes through all JSON-RPC errors. Internal errors are thrown in the same format with codes ranging between 32050 and 32099:

  • 32050: DHT resource signature could not be verified.
  • 32051: Unknown query setting was requested.
  • 32052: DHT resource is empty. (Only thrown for status, post, profile and avatar resources.)
  • 32060: Post signature could not be verified.
  • 32061: Public key not available on server.
  • 32062: Signature of retwisted post could not be verified.
  • 32063: Post could not be decrypted.
  • 32064: Private key is in conflict with public key.
  • 32080: Unsupported wallet type.
  • 32081: No wallet users found on the server.
  • 32082: Torrent inactive. Activate torrent first!
  • 32090: Host not reachable.
  • 32091: Request was not processed successfully (http error: HTTP_ERROR_CODE).
  • 32092: An error occurred while parsing the JSON response body.

Change Log

0.3.0

  • New query setting queryId. Can be used to mark multiple queries with a common id. With the Twister.onQueryComplete(...) function a handler can be registered that is triggered when the last query is completed. see examples/021_deep_fetching.js

0.2.1

  • Better handling of http/connection errors. Error codes: 32090-32092

0.2.0

  • Resources can now remove themselves from the cache using their own trim() function.
  • New function Twister.trimCache(timestamp) deletes every resource from the cache that is older than the timestamp, or has not been accessed since the timestamp. Needed to manage localStorage size in browsers.
  • Resources with invalid signatures now get removed from the cache.