Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

appdata

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

appdata

AppData is a minimalistic Node.js framework for accessing, writing and manipulating datasets in the users AppData (or Homedata) folder. It has a simple API and helps you saving persistent data for e.g. an electron desktop application.

  • 1.1.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

AppData is a minimalistic Node.js framework for accessing, writing and manipulating datasets in the users AppData (or Homedata) folder. It has a simple API and helps you saving persistent data for e.g. an electron desktop application.

Installation

npm install --save appdata

# or via git
git clone https://github.com/janbiasi/appdata.git

Usage

Setup

First off you need to create a new AppData Storage object. The AppData module exports a function which takes one argument, an optional custom settings object. If you are wondering which options are supported, take a look at TODO.

const appdata = require('appdata');
Selecting a Database

Next, you will have to select your database by a name. If the database does not exists a new set will be created by the system itself. There are only lower-, uppercase letters, numbers, hyphens and underscores allowed!

const database = appdata.connect('database-name', {
    /* options here */
});
Signature
connect(name: String [, options: Object]): Interface
Inserting data

Inserting data is as simple as setting new variables! The key must be a string and not an integer. But the value can be whatever you'd like to insert.

database.set('hello', 'world!');
database.set('mynum', 1923);
database.set('coll', [ 0, undefined, 'hey' ]);
Signature
set(key: String, value: <T>): <T>
Reading data

Like inserting, reading is very simple. Grab the key you'd like to find the value for and you'll get the result (or undefined in case the key does not exist).

database.all(); // { hello: "world!" ... }
database.get('hello'); // world!
database.get('mynum'); // 1923
Signature
get(key: String): <T>
Deleting and dropping

Datasets can be deleted by key or can be totally removed by the .drop() method. The methods are pretty simple to use, just look at the example below.

let name = storage.delete('name');
storage.get('name') === name; // false
storage.drop(); // {}
Signature
drop(): <T>
Eventhandling

The Interface inherits from the EventEmitter class, so it implements its own events. All possible events execute on the storage are listed below with a description and its paramters.

EventDescriptionParamter
connectEmitted when connected to the databaseDatabase-name
syncEmitted on sync actionBoolean or data synced
setEmitted when setting a new key-value pairKey and value
getEmitted when getting a key-value pairKey and value
hasEmitted when checking if a key existsKey and if exists (Boolean)
deleteEmitted when deleting a key-value pairKey and the deleted value
dropEmitted when dropping the database-
Signature
on(event: String, handler: Function): void
Services

Services can be created and published as node modules for adding custom functionallity to the interface of the AppData module. Services can be used e.g. for filtering, querying, exporting data and much more. Inside the service itself there is an interface property, which will provide you all methods which are listed above! Here is a short example how you can create your own service;

var Service = require('appdata').Service;
var MyService = new Service();

MyService.filter = function(data, options) {
    var data = this.interface.all();
    // ... add your filter logic here
    return [];
};

// Attach the service to your store instance
storage.service(MyService);

License

This project is licensed under the Apache 2.0 License.

FAQs

Package last updated on 21 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc