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

@plurid/plurid-data-structures

v0.0.0-11

Published

Plurid Data Structures

Downloads

27

Readme

Contents

About

The package contains the following data structures

Batcher

Runs a batched action of size at certain time after pushing into the Batcher.

import {
    Batcher,
} from '@plurid/plurid-data-structures';


const batcher = new Batcher<string>(
    (batch) => {
        console.log(batch);
    },
    {
        size: 2,
    },
);

batcher.push('one');
batcher.push('two');
batcher.push('three');

Cacher

Caches by id a generic T data structure.

import {
    Cacher,
} from '@plurid/plurid-data-structures';


const cache = new Cacher<string>();

const a = cache.get('one') // undefined
cache.set('one', 'two'); // true
const b = cache.get('one') // 'two'

cache.unset('one') // true
cache.reset(); // true

CacherManager

A Cacher which runs a cache get after a cache miss and a cache unset at cleanup.

import {
    CacherManager,
} from '@plurid/plurid-data-structures';


const cacherManager = new CacherManager<string, any>(
    // An array of cacher calls executed in order until one or none fills the cache request.
    [
        (
            index: string,
            context?: any,
        ) => {
            // return based on index value
            if (Math.random() < 0.5) {
                return 'one';
            }

            return;
        },
        async (
            index: string,
            context?: any,
        ) => {
            // return based on index value
            // runs asynchronously
            return 'two';
        },
    ],
    [
        (
            index: string,
            cache: string,
            context?: any,
        ) => {
            // unset cleanup
        },
    ],
    {}, // `Cacher` options
);


cacherManager.get('one'); // 0.5 chance of getting `'one'` or `Promise<'two'>`.
cacherManager.getAsynchronous('one'); // 0.5 chance of getting `'one'` or `'two'`.
cacherManager.getAsynchronous('one', { context: 'data' });

Stepper

The Stepper debounces the incrementation and decrementation of numerical values.

const id = 'one';
const stepper = new Stepper();

stepper.define(
    id,
    async (value) => {
        // use value asynchronously
        // the value will be 2
    },
); // the value is 0

stepper.step(
    id,
    1,
); // the value is 0 + 1 = 1
stepper.step(
    id,
    -1,
); // the value is 1 - 1 = 0
stepper.step(
    id,
    2,
); // the value is 0 + 2 = 2

DeposedString

Computes differences between strings after each push and stores them as internal stages. At get the string is recomposed starting from the initial string following through all the steps of the stages.

The name, deposed string, stands for differentially composable string.

The DeposedString is intended for efficient persistent storage of historic changes to a text (a simple note, a comment, or even a long-form text).

import {
    DeposedString,
} from '@plurid/plurid-data-structures';


const deposedString = new DeposedString('');

deposedString.push('a1b2c3');
deposedString.push('a1c3');
deposedString.push('13d4');

const a = deposedString.get(0); // 'a1b2c3'
const b = deposedString.get(1); // 'a1c3'
const c = deposedString.get(2); // '13d4'
console.log('a, b, c', a, b, c);

const unload = deposedString.unload(); // extract the stages
console.log('unload', JSON.stringify(unload, null, 4));
// unload -> {
//     initial: '',
//     stages: [
//         [
//             [ '+', 0, 'a1b2c3' ],
//         ],
//         [
//             [ '-', 2, 2 ],
//         ],
//         [
//             [ '-', 0, 1 ],
//             [ '-', 1, 1 ],
//             [ '+', 2, 'd4' ],
//         ],
//     ],
// }

const freshDeposedString = new DeposedString('');
freshDeposedString.load(unload.stages); // load the stages into a new DeposedString

const freshC = freshDeposedString.get(2); // '13d4'
console.log('freshC', freshC);

LinkedList

LinkedList implementation.

import {
    LinkedList,
} from '@plurid/plurid-data-structures';


const linkedList = new LinkedList();
linkedList.add(10);
linkedList.add(20);

PieceTable

PieceTable implementation.

import {
    PieceTable,
} from '@plurid/plurid-data-structures';

const pieceTable = new PieceTable('original string');
pieceTable.insert(' text', 15); // insert at index 15, the end
pieceTable.delete(8, 1); // delete at index 8, the space between 'original' and 'string'
const text = pieceTable.stringAt(0, 19); // 'originalstring text'

Packages

@plurid/plurid-data-structures

Codeophon