API Docs for: 0.3.0
Show:

Store Class

Defined in: lib/store/index.js:8
Module: store

An abstraction for keeping track of content against some keys (e.g. original source, instrumented source, coverage objects against file names). This class is both the base class as well as a factory for Store implementations.

Usage

 var Store = require('istanbul').Store,
     store = Store.create('memory');

 //basic use
 store.set('foo', 'foo-content');
 var content = store.get('foo');

 //keys and values
 store.keys().forEach(function (key) {
     console.log(key + ':\n' + store.get(key);
 });
 if (store.hasKey('bar') { console.log(store.get('bar'); }


 //syntactic sugar
 store.setObject('foo', { foo: true });
 console.log(store.getObject('foo').foo);

 store.dispose();

Constructor

Store

(
  • options
)

Parameters:

  • options Object

    Optional. The options supported by a specific store implementation.

Item Index

Methods

create

(
  • type
  • opts
)
Store static

returns a store implementation of the specified type.

Parameters:

  • type String

    the type of store to create

  • opts Object

    Optional. Options specific to the store implementation

Returns:

Store:

a new store of the specified type

dispose

()

lifecycle method to dispose temporary resources associated with the store

get

(
  • key
)
String

returns the content associated to a specific key or throws if the key was not set

Parameters:

  • key String

    the key for which to get the content

Returns:

String:

the content for the specified key

getObject

(
  • key
)
Object

sugar method to return an object associated with a specific key. Throws if the content set against the key was not a valid JSON string.

Parameters:

  • key String

    the key for which to return the associated object

Returns:

Object:

the object corresponding to the key

hasKey

(
  • key
)

returns true if the key is one for which a get() call would work.

Parameters:

  • key String

Returns:

true if the key is valid for this store, false otherwise

keys

() Array

returns a list of all known keys

Returns:

Array:

an array of seen keys

register

(
  • constructor
)
static

registers a new store implementation.

Parameters:

  • constructor Function

    the constructor function for the store. This function must have a TYPE property of type String, that will be used in Store.create()

set

(
  • key
  • contents
)

sets some content associated with a specific key. The manner in which duplicate keys are handled for multiple set() calls with the same key is implementation-specific.

Parameters:

  • key String

    the key for the content

  • contents String

    the contents for the key

setObject

(
  • key
  • object
)

sugar method to set an object against a specific key.

Parameters:

  • key String

    the key for the object

  • object Object

    the object to be stored