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

@eds-fw/storage

v3.0.2

Published

Tiny & Simply 'Map'-based storage: set(), get(), save() and more

Downloads

35

Readme

Tiny & Simply 'Map'/'Array'-based storage with .save() method

Features

  • VERY easy to use
  • "One File - One Storage Exemplar" mechanism (bugs & multi-load protection)
  • Safe asynchronous save() (protection from multi-saving)
  • "Exact key types": you can only use the specified keys, e.g. day ${number} (day 6, day 293, day 32, etc., but not hour 7)
  • Additional Map methods: hasValue(), getKey(), filter() & easy JSON convertion
  • Pretty JSON format (depth=1)

API

  • class Storage <V? extends JSONSupported, K? extends string> default export
  • extends Map<K, V>
  • constructor (path: string, autosave?: boolean | number)
  • field path: string
  • hasValue (value: V): boolean
  • getKey (value: V, single?: boolean): K[]
  • filter (callbackfn: (value: V, key: K, map: Map<K, V>) => boolean): Map<K, V>
  • async save (): Promise<void>
  • getter asJSON: string
  • [Symbol.toStringTag]: string
  • static create <V? extends JSONSupported, K? extends string> (...params: ConstructorParameters<typeof Storage>): Storage<V, K>
  • static asJSON (map: Map<string, JSONSupported>): string
  • static field oneFile_oneStorage: boolean
  • class ArrayStorage <V? extends JSONSupported>
  • extends Array<V>
  • private constructor ()
  • field path: string
  • async save (): Promise<void>
  • getter asJSON: string
  • [Symbol.toStringTag]: string
  • static create <V? extends JSONSupported> (path: string, autosave?: boolean | number): ArrayStorage<V>
  • static asJSON (arr: JSONSupported[]): string
  • static field oneFile_oneStorage: boolean

Requirements

  • NodeJS, recommended v18 or newer

Setup

  1. Install storage via npm:
npm i @eds-fw/storage
  1. Use storage:
//file.js, type: CJS
const { Storage } = require("@eds-fw/storage");
const scores = new Storage(
    "./scores_data.json", //Warning! Path is calculated from CWD
    60_000 //Autosave timeout. Will be saved automatically every minute
);
scores.set("me", 186);
scores.save();
scores.set("john", 231);
if (storage.has("peter"))
    storage.delete("peter");
console.log(storage.asJSON());
/* Output (pretty):
{
    "me": 186,
    "john": 231
}
*/

Or, using TypeScript and "exact key types":

//file.ts
import { Storage } from "@eds-fw/storage";
type Keys_t = `score_${string}` | `bestScore_${string}`;
const scores = new Storage<number, Keys_t>(
    "./scores.json",
    60_000
);
scores.set("score_me", 132); //OK
scores.set("score_john", 452); //OK
scores.set("bestScore_me", 972); //OK
scores.set("previousScore_me", 274); //TypeScript Error

Source (git)

Issues (git)