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

attostore

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

attostore

async json data store

  • 0.5.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by400%
Maintainers
1
Weekly downloads
 
Created
Source

attodom

small async json in-memory store with path events, ~3kb min, ~1kb gz

ExampleWhyAPILicense

Examples

import create from 'attostore'

var store = create({
  a: 'myInitValue',
  b:{c: 'myNestedValue'}
})

store.on('b/c', function(val, key, old) {
  console.log('key',key,'changed from',old.c,'to',val.c)
})

store.set({key: ['b', 'c'], val: 'newValue'}, function(err, act) {
  if (!err) console.log(!!act ? 'changed' : 'not changed')
})

store.set([{key: 'b/c', val:'anotherValue'}]).then(function(act) {
  if (act) console.log(act.length 'changes')
})

supports different environments

  • CJS: var create = require('attostore').createStore
  • ES modules: import {createStore} from 'attostore'
  • browser: var create = window.attostore.createStore

Features, Limitations, Gotcha

  • available in CommonJS, ES6 modules and browser versions
  • no Promise polyfill included. Not required if callbacks are provided to the set function
  • only the last item of an Array can be deleted to avoid shifting of keys
  • No Array splicing to keep the keys unchanged. additions and removals from the end only (eg. push pop)
  • only JSON types supported (Array, Object, string, number, boolean, null)
  • set triggers a deletion if the value is undefined and/or absent

API

attostore(initValue: any): Store

Store

.set(acts: Action|Actions, ondone: (err, acts) => void): void .set(acts: Action|Actions): Promise

.on(path: Path, handler: (val, key, old, key)=>void, [, context: any]): Ref .once(path: Path, handler: (val, key, old, key)=>void, [, context: any]): Ref .off(path: Path, handler: (val, key, old, key)=>void, [, context: any]): Ref

Acts

Simple patch format for atomic changes:

  • single or multiple changes: [{key: path, val: 'c'}], {key: path, val: 'c'}
  • set if a value is present, delete is the value is missing or undefined
  • the store is only changed if all actions pass without errors

Path

Array|string|number

  • 0, "0", [0], ["0"] are equivalent
  • '', null, undefined are equivalent
  • a/b, ["a", "b"] are equivalent

License

MIT © Hugo Villeneuve

Keywords

FAQs

Package last updated on 06 Jul 2017

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