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

mstorage

v1.3.4

Published

special data storages

Downloads

2

Readme

mstorage

npm i -S mstorage

Special serializer and deserializer for mstorage: mstorage-restore

import { KV } from 'mstorage'
import assert from 'assert'

var kv = new KV()
var key = { a: 'a' }
var val = [ 1, 2 ]
kv.set(key, val)

console.log(kv.has(key))
console.log(kv.hasByValue(val))
console.log(kv.get(key))
console.log(kv.getByValue(val))
import { Queue } from 'mstorage'
import assert from 'assert'

var q = new Queue()
var id1 = q.add({ 1: 1 })
var id2 = q.add({ 2: 2 })
q.toTail(id1)
var next = q.next()
assert.deepEqual(next, { 2: 2 })
import { HashVault } from 'mstorage'
import assert from 'assert'

var array = []
for (var index = 0; index !== 1e6; index++) 
    array.push({ 1: index })

var hv = new HashVault(array)
assert(hv.exists({ 1: 100 }))
assert(hv.exists({ 1: 10000 }))
assert(hv.exists({ 1: 10000000 }))

Methods

KV

Queue

HashVault

KV

Key-Value storage

drop - erase storage [🛨]

var kv = new KV()
kv.set('a', 1)
kv.drop()
assert.equal(kv.size(), 0)

copy [🛨]

var kv1 = new KV()
var kv2 = new KV()

kv1.set('a', 1)
kv2.copy(kv1)

assert.deepEqual(kv1.keys(), kv2.keys())

dump & restore [🛨]

var kv1 = new KV()
var kv2 = new KV()

kv1.set('a', 1)
var str = JSON.stringify(kv1.dump())
// or just call JSON.stringify(kv1)
kv2.restore(JSON.parse(str))
// WARNING! all null keys and values will be replaced to undefined

assert.deepEqual(kv1.keys(), kv2.keys())

keys - return list of keys [🛨]

var kv = new KV()
kv.set('a', 1)
assert.deepEqual(kv.keys(), [ 'a' ])

values - return list of values [🛨]

var kv = new KV()
kv.set('a', 1)
assert.deepEqual(kv.values(), [ 1 ])

has [🛨]

var kv = new KV()
kv.set('a', 1)
assert(kv.has('a'))

hasByValue alias for exists [🛨]

var kv = new KV()
kv.set('a', 1)
assert(kv.hasByValue(1))

get [🛨]

var kv = new KV()
kv.set('a', 1)
assert.equal(kv.get('a'), 1)

getByValue alias for id [🛨]

var kv = new KV()
kv.set('a', 1)
assert.equal(kv.getByValue(1), 'a')

set alias for add [🛨]

var kv = new KV()
kv.set('a', 1)
assert.equal(kv.get('a'), 1)

del [🛨]

var kv = new KV()
kv.set('a', 1)
kv.del('a')
assert.equal(kv.size(), 0)

delByValue [🛨]

var kv = new KV()
kv.set('a', 1)
kv.delByValue(1)
assert.equal(kv.size(), 0)

size [🛨]

var kv = new KV()
kv.set('a', 1)
assert.equal(kv.size(), 1)

Queue

drop [🛨]

var q = new Queue()
q.add(1)
q.drop()
assert.equal(q.size(), 0)

copy [🛨]

var q1 = new Queue()
var q2 = new Queue()

q1.add(1)
q2.copy(q1)

assert.deepEqual(q1.all(), q2.all())

dump & restore [🛨]

var q1 = new Queue()
var q2 = new Queue()

q1.add(1)
var str = JSON.stringify(q1.dump())
// or just call JSON.stringify(q1)
q2.restore(JSON.parse(str))
// WARNING! all null values will be replaced to undefined

assert.deepEqual(q1.all(), q2.all())

each alias for forEach [🛨]

var q = new Queue()
q.add(1)
q.add(2)
q.each(console.log)

map [🛨]

var q = new Queue()
q.add(1)
q.add(2)
q.map(el => el+1)
assert.deepEqual(q.all(), [ 2, 3 ])

add [🛨]

var q = new Queue()
q.add(1)
assert.equal(q.size(), 1)

replace [🛨]

var q = new Queue()
var id1 = q.add(1)
q.replace(id1, 2)
assert.equal(q.get(id1), 2)

del [🛨]

var q = new Queue()
var id = q.add(1)
q.del(id)
assert.equal(q.size(), 0)

delByValue [🛨]

var q = new Queue()
q.add(1)
q.delByValue(1)
assert.equal(q.size(), 0)

has [🛨]

var q = new Queue()
var id = q.add(1)
assert(q.has(id))

hasByValue alias for exists [🛨]

var q = new Queue()
q.add(1)
assert(q.hasByValue(1))

get [🛨]

var q = new Queue()
var id = q.add(1)
assert.equal(q.get(id), 1)

getByValue alias for id [🛨]

var q = new Queue()
var id = q.add(1)
assert.equal(q.getByValue(1), id)

all [🛨]

var q = new Queue()
q.add(1)
q.add(2)
assert.deepEqual(q.all(), [ 1, 2 ])

shuffle [🛨]

var q = new Queue()
q.add(1)
q.add(2)
console.log(q.shuffle())

next alias for shift [🛨]

var q = new Queue()
q.add(1)
q.add(2)
assert.equal(q.next(), 1)
assert.equal(q.next(), 2)
assert.equal(q.size(), 0)

last alias for pop [🛨]

var q = new Queue()
q.add(1)
q.add(2)
assert.equal(q.last(), 2)
assert.equal(q.last(), 1)
assert.equal(q.size(), 0)

toTail [🛨]

var q = new Queue()
var id1 = q.add(1)
var id2 = q.add(2)
q.toTail(id1)
assert.equal(q.next(), 2)

toHead [🛨]

var q = new Queue()
var id1 = q.add(1)
var id2 = q.add(2)
q.toHead(id2)
assert.equal(q.next(), 2)

size [🛨]

var q = new Queue()
q.add(1)
assert.equal(q.size(), 1)

HashVault

storage of sorted hashes

init [🛨]

var hv = new HashVault()
var array = [ 1, 2, 3, 4, 5 ]
hv.init(array)
assert.equal(hv.size(), array.length)

drop [🛨]

var hv = new HashVault()
hv.add(1)
hv.drop()
assert.equal(hv.size(), 0)

copy alias for restore [🛨]

var hv1 = new HashVault()
var hv2 = new HashVault()

hv1.add(1)
hv1.add(2)

hv2.copy(hv1)
assert.equal(hv1.size(), hv2.size())

dump & restore [🛨]

var hv1 = new HashVault()
var hv2 = new HashVault()

hv1.add(1)
hv1.add(2)

var str = JSON.stringify(hv1.dump())
// or just call JSON.stringify(hv1)
hv2.copy(JSON.parse(str))

assert.ok(hv2.exists(1))
assert.ok(hv2.exists(2))

getByValue alias for id [🛨]

var hv = new HashVault()
var id = hv.add(1)
assert.equal(hv.getByValue(1), id)

add [🛨]

var hv = new HashVault()
hv.add(1)
assert.equal(hv.size(), 1)

del [🛨]

var hv = new HashVault()
var id = hv.add(1)
hv.del(id)
assert.equal(hv.size(), 0)

delByValue [🛨]

var hv = new HashVault()
hv.add(1)
hv.delByValue(1)
assert.equal(hv.size(), 0)

has [🛨]

var hv = new HashVault()
var id = hv.add(1)
assert(hv.has(id))

hasByValue alias for exists [🛨]

var hv = new HashVault()
hv.add(1)
assert(hv.hasByValue(1))

size [🛨]

var hv = new HashVault()
hv.add(1)
assert.equal(hv.size(), 1)