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

sloth-bucket

v1.4.3

Published

A persistent indexed item service for app users. User gets a 'slot' to store whatever. Values are allocated and deallocated in fixed, indexed order. New items are stored in the next unallocated slot

Downloads

11

Readme

Sloth Bucket

A simple, persistent user slot system to store data sequentially with allocate/deallocate functions.

Get started

  1. Install and run redis.
  2. We have provided a Dockerfile that will create a simple redis server container
  • sudo docker build -t <your namespace>/redis .
  • sudo docker run -d -p 6379:6379 <your namespace>/redis
  1. Install sloth-bucket
  • npm install sloth-bucket --save
  1. For using sloth-bucket in production, you can easily configure the underlying redis store:
var sloth = require('sloth-bucket');

var options = {
 host: '192.168.2.45',
 port: 8034,
 socket_keepalive: true
}
sloth.init(options);

Usage

var sloth = require('sloth-bucket');
var username = 'marvin';

//initialize the slots with a starting buffer:
sloth.createUserSlots(username, 1200, 'infantryUnits');

var hitPoints = '5';
//assign variable value above to a new slot:

sloth.allocateSlotId(username, hitPoints, 'infantryUnits').then((result) => {
  var newId = parseInt(result);
  console.log('NEW ID: ', newId);
});

//deallocate a slot at index 3 for user 'marvin':
sloth.deallocateSlotId(username, 3, 'infantryUnits').then((result) => {
  var newIndex = parseInt(result);
  console.log('DEALLOCATED USER DATA AT INDEX: ', newIndex);
});

sloth.getSlotContentsByIndex(username, 2, 'infantryUnits').then((result) => {
  console.log('GETTING USER DATA AT INDEX 2: ', result);
}

hitPoints = 3;
sloth.setSlotContentsByIndex(username, 2, hitPoints).then((result) => {
  console.log('SETTING USER DATA AT INDEX 2: ', result);
} 

Utilities

//reset all slots for a user:
sloth.deleteUserSlots(username);

//get next available slot id:
sloth.nextAllocationSlot(username, 'infantryUnits').then((result) => {
  console.log('NEXT AVAILABLE ID: ', result);
}); 

Configuration

For more redis configuration options, consult the redis documentation.

//configure underlying redis cache:
var options = {
  host: '192.168.2.45',
  port: 8034,
  socket_keepalive: true
}
sloth.init(options);

//set slot's hash index as non-zero based:
sloth.nonZeroBased();

Changes by release (all versions prior to 2.0 are beta)

v. 1.4.1

  • removed the slot prefixing, in favor of enabling multiple slots, like this:
sloth.createUserSlots(username, 1200, 'infantryUnits');
sloth.createUserSlots(username, 20, 'badgesEarned');

v. 1.3.12

  • new minor feature: nonZeroBased() configures non-zero based hash of slots
  • new minor feature: get/setSlotValue() function to get/set slot data

v. 1.2.11

  • added nextAvailableSlotId() function for retrieving next unallocated slot Id

Tests

Set up

  1. Install redis on the computer on which you want to run the tests.
  2. We have provided a Dockerfile that will create a simple redis server container
  • sudo docker build -t <your namespace>/redis .
  • sudo docker run -d -p 6379:6379 <your namespace>/redis
  1. Install the redis-cli package:
  • :$ npm install redis-cli -g

Run

  1. Sloth-bucket tests are simple scripts with no dependencies on unit testing frameworks or test runners.
    Get over it, cd into the /test folder, run:

    • node test
    • node test1
    • node test2
  2. Any time you want to check in on what the tests are producing, run the redis CLI:

  • :$ redis-cli
  • :$ HGETALL user:steve
  1. Bask in the [sloth-bucket] goodness! :)
  2. run node clean to delete the user slots, or:
  • :$ redis-cli
  • :$ DEL user:steve