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

vano

v0.1.4

Published

small and flexible collection storage for nodejs

Downloads

150

Readme

npm version types size coverage vulnerabilities dependencies devDependencies License

small and flexible collection storage library suitable for small projects.

Installation

$ npm i vano

Usage

import vano, {file} from 'vano';

(async () => {
    const db = vano({adapter: file('./storage')});

    const characters = db.collection('characters', {
        name: '',
        age: 0,
    });
    
    characters.add({name: "john doe", age: 30});

    await characters.write();
})()

API

  • vano(config)
  • file(base)
  • memory()
  • db.collection(name[, schema])
  • col.read()
  • col.write()
  • col.add(item)
  • col.all()
  • col.count()
  • col.get(id)
  • col.remove(id)
  • col.update(id, update)
  • col.query()
  • col.reset()
  • col.on(event, listener)
  • col.off(event, listener)
  • query.eq(key, value)
  • query.neq(key, value)
  • query.gt(key, value)
  • query.gte(key, value)
  • query.lt(key, value)
  • query.lte(key, value)
  • query.skip(n)
  • query.limit(n)
  • query.get(n)

Library

vano(config: Config)

Config

| | required | default | description | |:----------|:--------:|:--------|:--------------------------------------------------------------------------------------------------------------------------------------------------| | adapter | ✓ | | interface for the communication between vano and io system. it can be file, memory or a custom function. adapter |

Creates a new vano instance.

import vano, {memory} from 'vano';

const db = vano({adapter: memory()});

Adapter

file(base)

Reads/writes the collections as JSON file to the provided base directory.

import vano, {file} from 'vano';

const db = vano({adapter: file('./collections')});

memory()

Keeps all collections in the memory.

import vano, {memory} from 'vano';

const db = vano({adapter: memory()});

Custom

Custom adapters can be used to read and write collections from and in different formats. These have to adhere the Adapter interface and return a function with four of the following sub-functions:

| function | parameter | return | description | |:--------------|:---------------------------|:----------------|:----------------------------------------------------------------------------------| | read | key: string | Promise<any> | resource reading logic. should return anything deserialize is comfortable with. | | write | key: string, data: any | void | resource saving logic. data is previously by serialize processed. | | serialize | data: any | Promise<any> | transform data into a processable form for write. | | deserialize | data: any | Promise<any> | transform data into a processable form for read. |

Example:
const adapterFactory = (someLibrary, someSerializer) => {
  const read = (key) => {
    return someLibrary.loadByKey(key);
  }

  const write = (key, value) => {
    someLibrary.saveByKey(key, value);
  }

  const serialize = (data) => {
    return someSerializer.serialize(data);
  }

  const deserialize = (data) => {
    return someSerializer.deserialize(data);
  }
}

Collection

db.collection(name[, schema])

Creates a collection with:

  • name (only alphanumeric)
  • optional schema (rough shape of every collection item)

vano uses schema for autocompletion and can be omitted if not necessary.

const col = db.collection('users', {name: "", age: 0});

col.read()

Asynchronously loads a collection into the memory via adapter, given a previously written collection exists.

col.read();

col.write()

Asynchronously saves a collection from the memory via adapter.

col.write();

col.add(item)

Adds an item to the collection and returns the unique id of the item inside the collection.

const id = col.add({name: "john doe", "age": 30});

col.all()

Returns all items from the collection.

const items = col.all();

col.count()

Returns the count of all items in the collection.

const count = col.count();

col.get(id)

Returns the item from the collection via id.

const item = col.get('ID');

col.remove(id)

Removes the item from the collection via id.

col.remove('ID');

col.update(id, update)

Updates the values of an item by an id and update object.

col.update('ID', {name: "max mustermann"});

col.reset()

Removes all items from the collection.

col.reset();

col.on(event, listener[, {once: bool])

Binds an event listener to one of the following actions add | update | remove.

const onAdd = (data) => console.log(data);
col.on('add', onAdd);

col.off(event, listener)

Unbinds the previously bound event listener.

const onAdd = (data) => console.log(data);
col.off('add', onAdd);

col.query()

Returns a query function for basic querying. See query.

const query = col.query();

Query

query.eq(key, value)

Selects items where item[key] is equal value and returns a new query function. Value can also be a regular expression.

const query = query.eq('name', 'doe');

query.neq(key, value)

Selects items where item[key] is not equal value and returns a new query function. Value can also be a regular expression.

const query = query.neq('name', 'doe');

query.gt(key, value)

Selects items where item[key] is greater than value and returns a new query function.

const query = query.gt('age', 20);

query.gte(key, value)

Selects items where item[key] is greater than or equal value and returns a new query function.

const query = query.gte('age', 30);

query.lt(key, value)

Selects items where item[key] is lesser than value and returns a new query function.

const query = query.lt('age', 20);

query.lte(key, value)

Selects items where item[key] is lesser than or equal value and returns a new query function.

const query = query.lte('age', 30);

query.skip(n)

Sets an offset of n and returns a new query function.

const query = query.skip(2);

query.limit(n)

Sets a limit of n items and returns a new query function.

const query = query.limit(10);

query.get()

Returns the queried items as an array.

const items = query.get();

ToDo

  • autocompletion via schema in collection.query() and collection.update()

Licence

MIT License, see LICENSE