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

b-cache

v0.3.3

Published

A graph like in memory data abstraction layer for complex data types

Downloads

9

Readme

B-Cache

CircleCI npm GitHub package version Language grade: JavaScript

A simple to use memory based storage for complex data types. Currently only a graph like implementation is avalible. This works by defining vertices and edges and adding them to an instance of a graph. At its heart this is a data abstraction layer that makes it simple to hold complex data types that may or may not be related in some way.

Installation

To install the package for use in your own project just use npm

npm install b-cache

Usage

Three copies are provided for convenience. A minified browser version, an es6 version, and an es5 version.

To use the browser version simply include b-cache/dist/bcache.min.js in a script tag and use it by referring to the class you need

var Vertex = bcache.Vertex;
var Edge = bcache.Edge;
var Graph = bcache.Graph;

for the es5 version (default) you can use

var Vertex = require("b-cache").Vertex;
var Edge = require("b-cache").Edge;
var Graph = require("b-cache").Graph;

And for es6

import { Vertex } from "b-cache/lib-esm/index";
import { Edge } from "b-cache/lib-esm/index";
import { Graph } from "b-cache/lib-esm/index";

Below is a simple use case writen in typescript. You can find other examples writen in both javascript and typescript in the examples folder of this repository.


// First lets extend vertex with our own class.

class Employee extends Vertex {

    /**
     * This edge defines a coworker as someone who works in the same team
     */
    public static coworkers = new Edge(
        (from, to) => from.team === to.team && from !== to,
    );

    /** An employee's manager is a member of the team the employee works in who
     * has the isManager designation. The false passed in the second argument
     * tells the graph that this will not return an Array of vertices but rather
     * a single vertex.
     */
    public static manager = new Edge(
        (from, to) => from.team === to.team && to.isManager,
        false,
    );

    // Define our instance attributes
    public team: string;
    public name: string;
    public isManager: boolean;

    constructor(id: number | string, team: string, name: string, isManager: boolean) {
        super(id);
        this.team = team;
        this.name = name;
        this.isManager = isManager;
    }
}

// Create a new graph
const graph = new Graph();

// Create some instances of our Employee Vertex
const employee1 = new Employee(1, "marketing", "Akbar Koya", false);
const employee2 = new Employee(2, "marketing", "Ann Mathews", false);
const employee3 = new Employee(3, "marketing", "David Boyle", true);

// Add the Employees to the graph
graph.add_vertex(employee1, employee2, employee3);

// The graph automatically populates the edges for us.
console.log(employee1.coworkers);    // [employee2, employee3]    Notice that this is an Array
console.log(employee1.manager.name);    // David Boyle    Notice that manager is a single edge

// We can also retrieve individual edges from the graph
console.log(graph.get_vertex({id: 2}).name)    // Ann Mathews

It is possible and often useful to have multiple sub-classes of Vertex and store them in the same graph. Since it is conceivable that in this case vertices might have the same id we can also specify a vertex type by passing a second string argument to the Vertex super class.

super(id, "employee");

In this way we can prevent collisions between our Employee vertices and, lets say, Department vertices which we want to store in the same graph so that we can define edges between them. By specifying the type of the vertices we can now store a Department with id 1 in the same graph as an employee also with id 1 as long as their vertex type is different.

To retrieve a vertex with from the graph which has a defined type we must also pass the type to the get_vertex function

console.log(graph.get_vertex({id: 2, type: "employee"}).name)    // Ann Mathews.

Getting Started

To get started you can download or clone the repository from github. You will also need typescript in order to compile the project.

Prerequisites

You only need typescript to get the project up and running

Installing

The easiest and simplest way to install the app is via npm and the CL interface. Navigte over to the project directory then call

npm install

This will install typescript for compiling the app as well as a few other dependencies for testing (mocha, chia, ts-node), building (webpack and ts-loader), documentation (typedoc) and linting (tslint)

Running the tests

To run the tests will additionally require mocha and chai and their typing information as well as ts-node. If you installed the app as noted above then you are already all set otherwise these can be installed via the CL

npm install --save-dev mocha chai ts-node @types/chai @types/mocha

You can now run the tests!

npm run test

Once the tests run you will get an annoying error about missing tslint. We use this to test compliance with the style guide. To fix the message read on.

Coding style tests

We use the tslint recomended style guide for coding. For more information you can visit the tslint website. The package can be installed using npm

npm install --save-dev tslint

you can then test that you are following the style by running

npm run lint

Deployment

This package can be used both in a browser and on Node.js. To build the package you will need a few more packages. If you installed the application as noted above then you are already all set otherwise you will additionally need to install webpack as well as the ts-loaded webpack plugin. This is easily done via npm and the CL interface.

npm install --save-dev webpack ts-loader

You can now build the package using

npm run build

This will build the package for you, though, you will get an annoying error at the end mentioning that the documentation could not be generated. To fix this install typedoc

npm install --save-dev typedoc

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Author

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • This README.md file was generated using the template at https://gist.github.com/PurpleBooth/109311bb0361f32d87a2