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-user-settings

v0.2.0

Published

[![Build Status](https://travis-ci.org/jvandemo/angular-user-settings.png?branch=master)](https://travis-ci.org/jvandemo/angular-user-settings)

Downloads

5

Readme

Angular User Settings

Build Status

Easily manage persistent user-specific settings in your AngularJS application:

  • very lightweight (~2KB)
  • no external dependencies
  • no database or backend required
  • works out-of-the-box, no configuration required
  • settings are automatically persisted across browser sessions using localStorage
  • gracefully falls back to non-persistent settings when localStorage is not available

From both your scripts and views!

Usage

First install the module using bower:

$ bower install angular-user-settings

and add the library to your application:

<script src="angular-user-settings.min.js"></script>

Then add the angularUserSettings module to the dependencies of your AngularJS application module:

angular.module('yourApp', ['angularUserSettings']);

Now you can access the user's settings using the $userSettings service in script:

ngModule.controller('YourController', function($userSettings){
  
  $userSettings.set('foo', true);
  $userSettings.get('foo'); // => true
  
  $userSettings.set('foo', 'bar');
  $userSettings.get('foo'); // => 'bar'
  
  $userSettings.set('foo', { foo: 'bar' });
  $userSettings.get('foo'); // => { foo: 'bar' }
  
});

or using the user-settings directive in your views:

<!-- adding the user-settings attribute to an element -->
<!-- conveniently exposes the $userSettings service in your view -->
<section user-settings>

  <a ng-click="$userSettings.set('foo', 'bar')">Set foo to bar</a>
  
  <p>Foo: {{ $userSettings.get('foo') }}</p>
  
</section>

To keep the markup as DRY as possible, there is a user-setting attribute available to grab an individual setting and expose it using $userSetting to the child elements:

<!-- instead of exposing all settings, we grab an individual setting -->
<!-- that is exposed as $userSetting -->
<section user-setting="debug-mode">

  <!-- if the setting is enabled -->
  <div ng-if="$userSetting.enabled">
    <p>Debug mode is enabled<p>
    <a href="$userSetting.disable()">Disable debug mode</a>
  </div>
  
  <!-- if the setting is disabled -->
  <div ng-if="$userSetting.disabled">
    <p>Debug mode is enabled<p>
    <a href="$userSetting.enable()">Enable debug mode</a>
  </div>
  
</section>

The $userSettings service

The following methods are available on the $userSettings service:

$userSettings.get(key)

Get setting for key.

Arguments

None.

Returns

Any.

$userSettings.set(key, value)

Set value for key.

Arguments

None.

Returns

$userSettings

$userSettings.enable(key)

Set value for key to true.

Arguments

None.

Returns

$userSettings

$userSettings.disable(key)

Set value for key to false.

Arguments

None.

Returns

$userSettings

$userSettings.enabled(key)

Check if setting is truthy or not.

Arguments

None.

Returns

boolean.

$userSettings.disabled(key)

Check if setting is falsy or not.

Arguments

None.

Returns

boolean.

Contribute

To update the build in the dist directory:

$ gulp

To run the unit tests using the src files:

$ gulp test-src

To run the unit tests using the unminified library:

$ gulp test-dist-concatenated

To run the unit tests using the minified library:

$ gulp test-dist-minified

Change log

v0.2.0

  • Added $userSetting directive
  • Added unit tests
  • Added initial documentation

v0.1.0

  • Added $userSettings service
  • Added storage service
  • Added userSettings directive
  • Added unit tests
  • Added initial documentation