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-local-storage-ci-dev

v0.3.3

Published

An Angular module that gives you access to the browsers local storage

Downloads

9

Readme

angular-local-storage-ci-dev

An Angular module that gives you access to the browsers local storage

A forked version for our project CI, add new features such as expiry support for localStorage and so on to meet our demand.

Install

$ npm install angular-local-storage-ci-dev
var angularLocalStorage = require('angular-local-storage-ci-dev');

angular.module('app', [
    angularLocalStorage
  ]);

##Configuration ###setPrefix You could set a prefix to avoid overwriting any local storage variables from the rest of your app Default prefix: ls.<your-key>

myApp.config(function (localStorageServiceProvider) {
  localStorageServiceProvider
    .setPrefix('yourAppName');
});

###setStorageType You could change web storage type to localStorage or sessionStorage Default storage: localStorage

myApp.config(function (localStorageServiceProvider) {
  localStorageServiceProvider
    .setStorageType('sessionStorage');
});

###setStorageCookie Set cookie options (usually in case of fallback) cookieOptions: options cookieOptions.path the web path the cookie represents. default: '/'

myApp.config(function (localStorageServiceProvider) {
  localStorageServiceProvider
    .setStorageCookie(45, '<path>');
});

###setNotify

Configure whether events should be broadcasted on $rootScope for each of the following actions: setItem , default: true, event "LocalStorageModule.notification.setitem" removeItem , default: false, event "LocalStorageModule.notification.removeitem"

myApp.config(function (localStorageServiceProvider) {
  localStorageServiceProvider
    .setNotify(true, true);
});

###Configuration Example Using all together

myApp.config(function (localStorageServiceProvider) {
  localStorageServiceProvider
    .setPrefix('newci')
    .setStorageType('sessionStorage')
    .setNotify(true, true)
});

##API Documentation ##isSupported Checks if the browser support the current storage type(e.g: localStorage, sessionStorage).
Returns: Boolean

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  if(localStorageService.isSupported) {
    //...
  }
  //...
});

###getStorageType Returns: String

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  var storageType = localStorageService.getStorageType(); //e.g localStorage
  //...
});

###set Directly adds a value to local storage. If local storage is not supported, use cookies instead. Returns: Boolean

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  function submit(key, val) {
   // expiry: milliseconds, this value will be expired in `expiry` milliseconds, if not set, and `localStorageService.expiry.alwaysExpire` is true, it will expire in the default expiry time.
   // expireTimeStamp: TimeStamp, this value will be expired after this absolute time.
   return localStorageService.set(key, val, expiry, expireTimeStamp);
  }
  //...
});

###get Directly get a value from local storage. If local storage is not supported, use cookies instead. Returns: value from local storage

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  function getItem(key) {
   // expiry: Number, if this value hasn't been wrapped by us, we will wrap them by using this expiry time.
   return localStorageService.get(key, expiry);
  }
  //...
});

###keys Return array of keys for local storage, ignore keys that not owned. Returns: value from local storage

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  var lsKeys = localStorageService.keys();
  //...
});

###remove Remove an item(s) from local storage by key. If local storage is not supported, use cookies instead. Returns: Boolean

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  function removeItem(key) {
   return localStorageService.remove(key);
  }
  //...
  function removeItems(key1, key2, key3) {
   return localStorageService.remove(key1, key2, key3);
  }
});

###clearAll Remove all data for this app from local storage. If local storage is not supported, use cookies instead. Note: Optionally takes a regular expression string and removes matching. Returns: Boolean

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  function clearNumbers(key) {
   return localStorageService.clearAll(/^\d+$/);
  }
  //...
  function clearAll() {
   return localStorageService.clearAll();
  }
});

###bind Bind $scope key to localStorageService.
Usage: localStorageService.bind(scope, property, value[optional], key[optional])
key: The corresponding key used in local storage
Returns: deregistration function for this listener.

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  localStorageService.set('property', 'oldValue');
  $scope.unbind = localStorageService.bind($scope, 'property');

  //Test Changes
  $scope.update = function(val) {
    $scope.property = val;
    $timeout(function() {
      alert("localStorage value: " + localStorageService.get('property'));
    });
  }
  //...
});
<div ng-controller="MainCtrl">
  <p>{{property}}</p>
  <input type="text" ng-model="lsValue"/>
  <button ng-click="update(lsValue)">update</button>
  <button ng-click="unbind()">unbind</button>
</div>

###deriveKey Return the derive key
Returns String

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  localStorageService.set('property', 'oldValue');
  //Test Result
  console.log(localStorageService.deriveKey('property')); // ls.property
  //...
});

###length Return localStorageService.length, ignore keys that not owned.
Returns Number

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  var lsLength = localStorageService.length(); // e.g: 7
  //...
});

##Cookie Deal with browser's cookies directly. ##cookie.isSupported Checks if cookies are enabled in the browser.
Returns: Boolean

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  if(localStorageService.cookie.isSupported) {
    //...
  }
  //...
});

###cookie.set Directly adds a value to cookies. Note: Typically used as a fallback if local storage is not supported. Returns: Boolean

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  function submit(key, val) {
   return localStorageService.cookie.set(key, val);
  }
  //...
});

Cookie Expiry Pass a third argument to specify number of days to expiry

    localStorageService.cookie.set(key,val,10)

sets a cookie that expires in 10 days. ###cookie.get Directly get a value from a cookie. Returns: value from local storage

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  function getItem(key) {
   return localStorageService.cookie.get(key);
  }
  //...
});

###cookie.remove Remove directly value from a cookie. Returns: Boolean

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  function removeItem(key) {
   return localStorageService.cookie.remove(key);
  }
  //...
});

###cookie.clearAll Remove all data for this app from cookie. Returns: Boolean

myApp.controller('MainCtrl', function($scope, localStorageService) {
  //...
  function clearAll() {
   return localStorageService.cookie.clearAll();
  }
});