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

@sittingbool/angular-safeguard

v3.0.0

Published

angular library for managing session, locker and cookie storage, has backup for in-memory if none are supported

Downloads

15

Readme

angular-safeguard

Build Status

Code Climate

Note: This library was renamed from angular2-locker to angular-safeguard

Wrapper around sessionStorage, localStorage and cookies for angular. If both are unavailable will use an in memory storage.

Expiry is also implemented for all drivers not just cookies

Breaking Changes in 2.0:

With 2.0 this library supports AoT. As a result there was two options, one to create a storage type for each different storage, and two to change set/get and other methods to explicitly use a driver. The latter means we can still provide in-memory fallback without the hassle of you writing conditions everywhere. All methods on locker now have an extra param for storage type such as get(DRIVERS.SESSION, 'key')

Getting Started

$ npm i --save angular-safeguard
import {NgModule} from '@angular/core'
import {LockerModule, Locker, DRIVERS} from 'angular-safeguard'

@Component({
  selector: 'app',
  template: `...`
})
class App {
  constructor(locker: Locker) {
    locker.set(DRIVERS.SESSION, 'something', value)
  }
}

@NgModule({
  imports: [LockerModule],
  declarations: [App],
  bootstrap: [App]
})
class AppModule {
  constructor(private locker: Locker) {}
}

With Custom Config

import {LockerModule, LockerConfig, DRIVERS} from 'angular-safeguard'

// to set a single driver
const lockerConfig = {
  driverNamespace: 'nameSpace',
  driverFallback: DRIVERS.MEMORY,
  namespaceSeperator: '-'
}

// to set fallback drivers in order of preference, pass in an Array of Driver
const lockerConfig = {
  driverNamespace: 'nameSpace',
  driverFallback: [DRIVERS.LOCAL, DRIVERS.SESSION, DRIVERS.COOKIE],
  namespaceSeperator: '-'
}

@NgModule({
  imports: [LockerModule.withConfig(lockerConfig)]
  ...
})
class SomeModule {

}

Methods

get

locker.get(DRIVERS.SESSION, 'myKey')

set

locker.set(DRIVERS.SESSION, 'myKey', 'value')
locker.set(DRIVERS.SESSION, 'myKey', {object: 'value'})

const expiry = new Date()

expiry.setHours(expiry.getHours() + 1)

locker.set(DRIVERS.SESSION, 'myKey', 'value', {expiry}) // will work with every driver type

// You can also use set to pass options for cookies like maxAge and such

key

locker.set(DRIVERS.COOKIES, 'key', 'value')

locker.key(DRIVERS.COOKIES, 0) // 'key'

has

locker.has(DRIVERS.LOCAL, 'key')

setNamespace

locker.setNamespace('myName')
locker.setNamespace() // Resets to lockerConfig default

setSeparator

locker.setSeparator('myName')
locker.setSeparator() // Resets to lockerConfig default

remove

locker.remove(DRIVERS.SESSION, 'key')

clear

locker.clear(DRIVERS.SESSION)

Static Methods

DRIVERS

These are the types of drivers available. If you try to set it to a (single) driver that is unsupported it will fallback to the memory driver. To set fallback drivers, pass in an Array of drivers in the order or preference:

Again, if every driver in Array is unsupported, it will fall back to memory driver.

Types are available from import {DRIVERS} from 'angular-safeguard'

  • DRIVERS.SESSION - Session Cache
  • DRIVERS.LOCAL - Local Storage
  • DRIVERS.MEMORY - Memory Storage
  • DRIVERS.COOKIE - Cookies

FAQ

Why is my data getting set to {data: myDataHere} instead of just myDataHere?: angular-safeguard provides expiry on more than just cookies, to do this it's necessary to create a bit of a more complex object so we can store expiry and more