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

angular-marshall.storage

v0.2.1

Published

A simple localStorage service for angular.

Downloads

156

Readme

Angular LocalStorage Service

This service provides a simple a eloquent interface to the localStorage API.

Examples

angular
    .module('example', ['marshall.storage'])
    .run(function (storageService) {
        var storage = storageService('example.');

        storage.set('foobar', 'Hello World!');

        console.log(storage.get('foobar')); // 'Hello World!'
    });
angular
    .module('example', ['marshall.storage'])
    .run(function () {
        var storage = storageService('example.');

        // Number
        storage.set('foobar', 123);

        console.log(storage.get('foobar')); // '123' (String)
        console.log(storage.get('foobar', Number)); // 123 (Number)

        // JSON
        storage.set('foobar', JSON.stringify({ one: 'two' }));

        console.log(storage.get('foobar')); // '{"one":"two"}' (String)
        console.log(storage.get('foobar', JSON.parse)); // { one: 'two' } (Object)
    });
angular
    .module('example', ['marshall.storage'])
    .run(function (storageService) {
        var storage = storageService('example.');

        var watcher = storage.watch('foobar', function (key, value) {
            console.log('%s => %s', key, value); // 'foobar => Hello World!'
        });

        storage.set('foobar', 'Hello World!');

        console.log(storage.keys()); // ['foobar']
    });

API

StorageService([String:prefix]) StorageService

Creates a new StorageService instance, with an optional prefix.

The prefix is used to isolate local storage items to a specific key. All methods on the StorageService look at this prefix. For example; with a StorageService of ‘foobar.’, the StorageService#clear method will only remove all items that start with ‘foobar.’.

StorageService#get(String:key [, Function:parser]) *

Returns the string value of an item within local storage.

StorageService#set(String:key, String:value)

Sets an item in local storage.

StorageService#has(String:key) Boolean

Returns whether there is an item in local storage with the given key.

StorageService#remove(String:key)

Removes a specific item in local storage, by key.

StorageService#clear()

Removes all the items in local storage.

StorageService#json(String:key [, Object/Array:value]) Object/Array/undefined

Gets or sets an item in local storage; automatically stringifying them, and parsing them out.

StorageService#watch(String:pattern, Function:callback [, Boolean:initial]) Function

Watches local storage for any changes to specific items. The callback is fired whenever a piece of code (within the same tab, or another tab) sets/removes/changes the value of a local storage item.

The pattern argument is a string that can optionally include regular expression code. For simplicity, the * key will automatically be translated into (.*) which matches anything. This allows you to pass in a string, such as; ‘example.foo.*.id’, which will match ‘example.foo.andrew.id’, ‘example.foo.max.id’ (etc).

An optional third argument can be passed through to invoke the callback for all the existing items with their current values.

StorageService#keys() Array

Returns an array of keys within local storage.

StorageService#sub(String:prefix) StorageService

Spawns a child StorageService which is prefixed with the prefix the parent has.