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

write-pointers

v1.2.0

Published

A simple class to manage indices to a data store with an autonumber indexing system and a lazy erase algorithm

Downloads

26

Readme

WritePointers Module.

This module is intended to provide write pointer autonumber indices for use in a data store that uses a lazy delete functionality. When a record is deleted, the index of the deleted record is recovered and re-used for the next available new record.


NOTE: Version 1.2.0 fixed multiple delete bug.

You should obviate all earlier versions.



NOTE: Version 1.0.0 small change to delete function return value.

In version 1.0.0, a delete command will return the id that was deleted OR -1 if no record can be found to be deleted.
In version 0.5.x, the return values were true or false. This should be a minor change to any using code OR you can just continue with the 0.5.x version.


The Write Pointer functionality is provided as a class so that it can be embedded within a larger module or class and so multiple instances can be embedded in one structure if needed.

WritePointers contains two classes. WritePointer and WritePointerSafe. WritePointer will do no validation of the params for the inUse and delete functions. WritePointerSafe will ensure datatype for these. Use WritePointerSafe during development OR when your WritePointer instance is intended to be used by using authors or other end users.

WritePointers also contains a function ( writePointerAttachAsMixin) to attach a WritePointer or WritePointerSafe instance as a mixin to another class or object.

Commands:

next: gets the next available id
inUse: checks to see if an id is in use
idsInUse: shows all the ids currently in use as an array. delete: deletes an id from the system and makes it available for the next function for reuse
count: checks to see how many ids are in use OR the number of ids in use + those that have been deleted.

Usage

Instantiation:

import { WritePointer } from 'write-pointers';
writePointer = new WritePointer('dataPointers');
// or to start the index at a specific value ( MUST BE >=0 )
writePointer = new WritePointer('dataPointers', 20);
// or to do the same things with id validation.
import { WritePointerSafe } from 'write-pointers';
writePointer = new WritePointerSafe('dataPointersSafe');

Next Available Write Id:

let newId = writePointer.next()

Delete an in-use Write Id:

// returns the id that was deleted if an in-use record was deleted, 
// OR false if no record to be deleted 
let didThisDelete = writePointer.delete();

Check if an Id is being used for a record:

// if id === true runs idsInUse command shown just below. 
let isThisInUse = writePointer.inUse(<id>);

Show all the Ids in use

let idsInUse = writePointer.inUse(<id>);

How Many Records are in this system.

// return the number of records that are in use.
let count = writePointer.count();

// return the number of ALL records including ones that were deleted.
let count = writePointer.count(false);

Use as a Mixin

writePointerAttachAsMixin function will attach the four api commands to a parent or target class as public function proxy calls to the writePointer instance. The functions will appear on the parent class. By default, camelCase will be used, but underscore notation is also possible.

To use with CamelCase:

const writePointer = new WritePointer('index');
class targetClass {}
writePointerAttachAsMixin(writePointer, targetClass, <camelCase> = true);
/* 
	writePointer.next  .... targetClass.indexNext;
	writePointer.delete  .... targetClass.indexDelete;
	writePointer.inUse  .... targetClass.indexInUse;
	writePointer.count  .... targetClass.indexCount;
*/

To use with underscore:

const writePointer = new WritePointer('index');
class targetClass {}
writePointerAttachAsMixin(writePointer, targetClass, false);
/* 
	writePointer.next  .... targetClass.index_next;
	writePointer.delete  .... targetClass.index_delete;
	writePointer.inUse  .... targetClass.index_inUse;
	writePointer.count  .... targetClass.index_count;
*/