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

@mcbe/store

v2.0.8

Published

It's `Map<string, Map<string, number>>` style storage with auto-saving It will keep every stored values Si, It can write/read without any delay It uses prefix to avoid duplication

Downloads

17

Readme

About this

It's Map<string, Map<string, number>> style storage with auto-saving It will keep every stored values
Si, It can write/read without any delay
It uses prefix to avoid duplication

Example

import { realTime } from '@mcbe/timer/realtime';
realTime.install(); // install timer to use setTimeout/setInterval
// It needs timer supports, it saves modified fields after 1sec

import { Store } from '@mcbe/store';

const chest = new Store('chest');

Store.onLoad.then(loaded=>{ // wait loading, It will read all of scoreboard
    loaded.scoreboards; // string array, player names that not in store
        
    const chest1 = chest.create('x_y_z'); // player name of scoreboard is chest_x_y_z
    const chest2 = chest.create('1_2_3'); // player name of scoreboard is chest_1_2_3
    // player name length is no limited, I tested over 4*1024*1024 characters

    const chest1_item1 = chest1.get('item1'); // get 'item1'
    // 'item1' is objective, it will auto generated
    // objective name has length limit (16 characters)

    chest1.add('item1', 1); // increase item1 count
    chest2.set('item2', chest1_item1 || 0);
    
    setTimeout(()=>{
        say("chest1_item1-old: "+chest1_item1);
        say("chest1_item1-new: "+chest1.get('item1'));
        say("chest2_item2: "+chest2.get('item2'));
    }, 5000);
});

@mcbe/event dependency

@mcbe/event will freeze system object to prevent modifiying initialize update shutdown functions.

// please use
import events from "@mcbe/event_server";
events.initialize.on(()=>{ /* codes */ });
events.update.on(()=>{ /* codes */ });
events.shutdown.on(()=>{ /* codes */ });
// instead of 
system.initialize = ()=>{ /* codes */ };
system.update = ()=>{ /* codes */ };
system.shutdown = ()=>{ /* codes */ };

References


// Map<string, Map<string, number>> style storage that will store scoreboard
class Store
{
    private static readonly all = new Map<string, Store>();
    private readonly data = new Map<string, Storage>();

    // it will name scoreboard player as [prefix]_[name]
    constructor(public readonly prefix:string);

    // create storage
    // it will get storage if it already exists
    create(name:string):Storage;

    // get storage
    // it will return null if not found
    get(name:string):Storage|null;

    // dispose storage with name
    dispose(name:string):void;

    // get all entries as [name, storage]
    // name is without prefix
    * entires():IterableIterator<[string, Storage]>;

    // get all storages
    * values():IterableIterator<Storage>;
    
    // get all names
    // this name is without prefix
    * keys():IterableIterator<string>;

    // save contained storages without waiting
    saveNow():void;

    // save all storages across all store
    static saveNowAll():boolean;

    // read all storages from scoreboard
    // it will return scoreboard player list which contains non-store scoreboard players
    static async updateAll():Promise<StoreLoaded>;

    // on load all storages
    // it have scoreboard player list which contains non-store scoreboard players
    public static readonly onLoad:Promise<StoreLoaded>;
}

// kind of event object
class StoreLoaded
{
    // non-store scoreboard players
    scoreboards:string[];

    // filter for 'this.scoreboards'
    // if return true, it will removed from scoreboards, ordering will twist for performance
    use(cb:(name:string)=>boolean):void;
}

// Map<string, numbe> style storage that will store scoreboard
class Storage
{
    // rename storage
    // it will repeat remove & set
    // this storage will be destroyed
    // and return renamed storage
    rename(newname:string):Storage|null;

    // get field count
    size():number;
    
    // clear all fields
    clear():void;

    // remove this storage
    dispose():void;

    // get value
    // key is cannot be longer than SCORE_LIMIT
    get(key:string):number|undefined

    // set number if field is undefined
    setDefault(key:string, value:number):void;
    
    // set number to field
    set(key:string, value:number):void;
    
    // add number to field
    add(key:string, value:number):number;

    // subtract number to field    
    remove(key:string, value:number):number;

    // delete field
    delete(key:string):void;

    // update specific field
    async update(key:string):Promise<void>;

    // update all objectives
    async updateAll():Promise<void>;

    entires():IterableIterator<[string, number]>;

    keys():IterableIterator<string>;
    
    values():IterableIterator<number>;
}