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

spectrum-kit

v3.0.0

Published

spectrum of libraries for different needs

Downloads

268

Readme

CircleCI codecov NPM Downloads NPM License Twitter

Spectrum Kit

Spectrum Kit is a collection of TypeScript tools designed for various scenarios.

Table of Contents

Introduction

Spectrum Kit provides TypeScript classes to simplify common tasks in web development or your nodejs development, including managing browser history with the BrowserHistory class and working with double-linked lists using the DoubleLinkedListNode class and a Deque for managing complex data relationships.

BrowserHistory

The BrowserHistory class allows you to manage your application's navigation history effortlessly. Here's a quick example of how to use it:

import { BrowserHistory } from 'spectrum-kit';

const history = new BrowserHistory('homepage');

const page1 = history.visit('page1');
const page2 = history.visit('page2', 'foo');
const page3 = history.visit('page3');

 history.back(1); // => { pathname: page2, state: 'foo' }
 history.back(1); // => { pathname: page1, state: undefined }
 history.back(1); // => { pathname: homepage, state: undefined }
 history.forward(1); // => { pathname: page1, state: undefined }
 history.forward(1); // => { pathname: page2, state: 'foo' }
 history.forward(1); // => { pathname: page3, state: undefined }

Serialization

To store your BrowserHistory data in a database, IndexedDB, or localStorage, you can use the serializeDoubleLinkedList function to convert the history into a serializable format. This function returns an array of objects where each object represents a node in the doubly linked list.

// Import the serializeDoubleLinkedList function
import { serializeDoubleLinkedList } from 'spectrum-kit';

// Assuming you have a BrowserHistory instance called 'history'
const serializedData = history.serializeHistory();

// Now, you can store the 'serializedData' array in your preferred storage solution
// (e.g., IndexedDB, localStorage, or a database).

Deserialization

To retrieve and reconstruct your BrowserHistory data from storage, you can use the deserializeDoubleLinkedList function. This function takes the serialized data as input and reconstructs the doubly linked list, allowing you to continue using it.

import { BrowserHistory } from 'spectrum-kit';


// Retrieve the serialized data from your storage solution (e.g., IndexedDB or localStorage), must be serialized using
// serializeDoubleLinkedList in this repo
const storedData = /* Retrieve your data here */;

// Deserialize the data 
const history = new BrowserHistory('');

history.deserializeHistory(storedData);

DoubleLinkedListNode

The DoubleLinkedListNode class provides a versatile double-linked list node implementation. You can use it in various scenarios, such as implementing data structures or managing complex data relationships.

import { DoubleLinkedListNode } from 'spectrum-kit';

const node = new DoubleLinkedListNode('key', 'value');

console.log(node.key); // => 'key'
console.log(node.value); // => 'value'

Deque

The Deque class provides a double ended queue, similar to python's deque. You can use it in various scenarios, and achieve a time complexity of O(1) for popLeft() and appendLeft() as opposed to O(n) for array's shift() and unshift().

import { Deque } from 'spectrum-kit';

const deque = new Deque([1, 2, 3]);

deque.appendLeft(0);

deque.popLeft();
// 0

Installation

To install Spectrum Kit, you can use npm or yarn:

npm install spectrum-kit
# or
yarn add spectrum-kit

Usage

You can import and use the classes provided by Spectrum Kit as demonstrated in the introduction section above. Make sure to check the documentation for more details and usage examples.

Contributing

We welcome contributions from the open-source community. Before contributing, please read our contribution guidelines to understand the process.

If you encounter any issues or have ideas for improvements, please use our issue template to report bugs or suggest enhancements. If you'd like to submit a code change, follow our pull request template.

License

Spectrum Kit is licensed under the MIT License. See the LICENSE file for details.

Thank you for using Spectrum Kit! We hope it simplifies your TypeScript development tasks.