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

ng-vault

v0.4.0

Published

Helper methods wrapped over angular $cacheFactory

Downloads

26

Readme

ng-vault npm version

=========== ng-vault wraps over angular's $cacheFactory to provide few nifty ways to save and retrieve data. ng-vault contains these two parts:

  • $vault factory which has methods for storing and retrieving data.
  • $vaultConfigProvider for configuring the behaviour of $vault factory.

Installation

###Via yarn or npm:

# yarn (recommended)
$ yarn add ng-vault

#npm
$ npm install ng-vault --save

Then use it as:

var angular = require('angular');
angular.module('mainApp', [ require('ng-vault') ]);

###Via bower:

$ bower install ng-augment-native-scroll --save

Then use it as:

var angular = require('angular');
var ngAugmentNativeScroll = require('./bower_components/ng-vault/src');

angular.module('mainApp', ['ng-vault']);

You can also include it in the old fashion way as:

<script src="/bower_components/ng-vault/dist/ng-vault.js"></script>
<!-- or -->
<script src="/bower_components/ng-vault/dist/ng-vault.min.js"></script>

Provider Configuration

Normally we may not need to configure the behaviour of $vault. Still he is an example of how we can do it:

angular.module('mainApp')
    .config(function ($vaultConfigProvider) {
        $vaultConfigProvider.set({
            id: 'starwars',
            limitTypes: {
                isArray: true,
                isDate: true,
                isFunction: true,
                isNumber: true,
                isObject: true,
                isString: true
            },
            putUptoMins: 5
        });
    });

id - type:String - default:$vault

The unique name with which the internal store of ng-vault will be created.

limitTypes - type:Array - default:[]

By default we can save any type of data into $cacheFactory, $vault can be configured to accept only the configured types. This can be help control $vault usage. Skip this to allow $vault to save all type of data. The key names in options, isArray, isDate... are the same methods available on angular. Internally $vault uses angular.<key name> to check types. Using plain typeof type === typeof vaule can produce inconsistent results.

putUpto - type:Number - default:3

Using when we put some data in, it will be retained as long as it's not removed. But sometime we may want to retain data only for a short while. It should be removed once the time is up. We can use putUpto method to put data with an additional mins argument. Here putUptoMins can be set as the default value to be used, in case putUpto is not provided with an additional mins argument.

Usage

Now we can inject $vault into any other part of our code to put and get values. Here are the list of all methods that $vault packs:

put

To put data in, only defined data. It will check the data type with the set limitTypes. If it passed it will saved. If not it will display a console warn.

Param | Type | Required | Details --- | :--- | :--- | :--- key | String | yes | Name of the key value | Any | yes | Value to be saved

$vault.put('episode-4', 'A New Hope');

putUpto

Put for certain time, after which it will be removed

Param | Type | Required | Details --- | :--- | :--- | :--- key | String | yes | Name of the key value | Any | yes | Value to be saved mins | Number | no | Mins after which the data should be removed

$vault.putUpto('episode-5', 'The Empire Strikes Back', 5);

// after 5 mins (5 * 1000 * 60)
$vault.has('episode-5');
// false

putOnce

Put value and remove once it's retrieved.

Param | Type | Required | Details --- | :--- | :--- | :--- key | String | yes | Name of the key value | Any | yes | Value to be saved

$vault.putOnce('episode-6', 'Return of the Jedi');

$vault.get('episode-6');
// Return of the Jedi

$vault.has('episode-6');
// false

get

Get a stored data. If not found it will return undefined.

Param | Type | Required | Details --- | :--- | :--- | :--- key | String | yes | Name of the key

$vault.get('episode-2');
// Attack of the Clones

has

Check if a particular key exist. Returns true or false.

Param | Type | Required | Details --- | :--- | :--- | :--- key | String | yes | Name of the key

$vault.has('episode-3');
// true

remove

Remove a key from $vault

Param | Type | Required | Details --- | :--- | :--- | :--- key | String | yes | Name of the key

$vault.remove('episode-1');

info

Retrieve information regarding the store - id and size

$vault.info();
// {
//     id: 'starwars',
//     size: 5
// }

removeAll

Remove everything from $vault

$vault.removeAll();

TODO

Testing and code-coverage

#Future Data is still stored in memory. Add methods to save them to localStorage or indexedDB.