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

@newteq/ngx-local-storage

v1.0.1

Published

This is an angular library that provides a service to interact with local storage easily. Simply import the module and use NgxLocalStorageService to access local storage

Downloads

53

Readme

ngx-local-storage

NPM Version

This is an angular library that provides a service to interact with local storage easily. Simply import the module and use NgxLocalStorageService to access local storage.

Installation

Install via npm:

npm install @newteq/ngx-local-storage --save

Usage

1. Import NgxLocalStorageModule

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgxLocalStorageModule } from 'ngx-localstorage';

@NgModule({
    imports: [
        BrowserModule,
        NgxLocalStorageModule.forRoot()
    ],
    bootstrap: [AppComponent]
})
export class AppModule { }

OR

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgxLocalStorageModule } from 'ngx-localstorage';

@NgModule({
    imports: [
        BrowserModule,
        NgxLocalStorageModule.forRoot({
					prefix: 'my-prefix',
					defaultJsonConversion: false,
				})
    ],
    bootstrap: [AppComponent]
})
export class AppModule { }
Configuration (NgxLocalStorageModule.forRoot(localStorageConfig))
  • localStorageConfig
    • Type: NgxLocalStorageConfig
      • Optional
  • NgxLocalstorageConfig Interface
    • prefix
      • Type: string
      • Determines the key prefix.
      • Default: ngx-local-storage
    • defaultJsonConversion
      • Type: boolean
      • Determines if the data is stored as a JSON object. (i.e. it is stored with JSON.stringify() and loaded with JSON.parse())
      • Default: true
    • nullUndefinedIsTheSame
      • Type: boolean
      • Determines if the service should try null and undefined as the same type. Usually would you want this to be the case, but you can change it.
      • Default: true
    • allowNullStorage
      • Type: boolean
      • Determines if null can be stored against a key. If null is passed to the setItem method, and this flag is true, it will save null to that key. By default it will remove the item if null is passed it the setItem as the default value is false. This works in conjuction with the nullUndefinedIsTheSame property and if this is true, the same behaviour will happen if undefined is passed in and this is set to true. It will remove the item rather than presisting it.
      • Default: false

API

LocalStorageService

Methods

  • setItem(key: string, value: string): boolean: Adds tha value with the given key or updates an existing entry. Returns true if the item was added to the storage. Will return false if the item was not stored and was removed (as per the allowNullStorage property from the config)
  • getItem(key: string): T | any: Gets the entry specified by the given key.
  • removeItem(key: string): void: Removes the entry specified by the given key.
  • clear(): void: Clears all entries of the applications local storage.
Example
import { LocalStorageService } from '@newteq/ngx-local-storage';

@Component({
  selector: 'app-storage-access',
  template: './storage-access.component.html'
})
export class StorageAccessComponent implements OnInit {

  constructor(private localStorageService: LocalStorageService) {
  }
  
  ngOnInit(): void {
		this.localStorageService.set('key', 'value');
		console.log(this.localStorageService.get('key'));
		this.localStorageService.remove('key'); // or this.localStorageService.clear();
  }
}

Issues

If you have any issues that you would like to log, please log them here

Library

Library Information

This library was generated with Angular CLI version 7.2.0.