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

ngx-storage-utils

v1.0.2

Published

Angular package for streamlined management of local storage and cookies in both SSR and CSR environments.

Downloads

8

Readme

Ngx Storage Utils

npm version License: MIT

NgxStorageUtils is an npm package designed to simplify cookie and storage management in Angular applications, especially in Server-Side Rendering (SSR) environments.

Features

  • Manage cookies and storage in Angular SSR applications effortlessly.
  • Compatible with Angular Universal for SSR setups.
  • Provides a simple API for setting, getting, and removing cookies and storage items.
  • Supports both client-side and server-side execution.
  • Encrypts data stored in local storage for enhanced security.

Installation

Install the package via npm:

npm install ngx-storage-utils

Usage

Usage in Components or Services

Inject and use CookiesService or StorageService in your Angular components or services:

import { Component } from '@angular/core';
import { CookiesService, StorageService } from 'ngx-storage-utils';

@Component({
  selector: 'app-root',
  template: `<h1>ngx-storage-utils</h1>`,
})
export class AppComponent {
  cookiesService = inject(CookiesService);
  storageService = inject(StorageService);
}

API

StorageService API

  • clear(): void: Clears all items from local storage.

  • getTypedItem<T = unknown>(key: string, encryptionKey: string = '', validate: boolean = true): T | null: Retrieves and parses an item by key.

  • getStorageItem(key: string, validate: boolean): StorageObject | null: Retrieves the storage item as StorageObject associated with the key.

  • getItem(key: string, validate: boolean = true): string | null: Retrieves the string value associated with the key.

  • key(index: number): string | null: Retrieves the key of the storage item at the specified index.

  • removeItem(key: string): void: Removes the storage item associated with the key.

  • setItem(key: string, value: string, options?: StorageSetOptions): void: Sets the value of the storage item associated with the key.

  • validate(): void: Validates and removes expired storage items.

StorageObject Interface

Represents an object stored in local storage.

Properties

  • value: string: The value stored in the local storage.

  • isEncrypted?: boolean: (Optional) Indicates whether the stored item is encrypted.

  • isExpirable?: boolean: (Optional) Indicates whether the stored item is expirable.

  • expires?: Date: (Optional) The expiration date of the stored item.


CookiesService API

Methods

  • check(name: string): boolean: Check if a cookie exists.
  • get(name: string): string: Get the value of a cookie.
  • getAll(): { [key: string]: string }: Get all cookies.
  • set(name: string, value: string, options?: CookieOptions): void: Set a cookie.
  • delete(name: string, path?: string, domain?: string, secure?: boolean, sameSite: 'Lax' | 'Strict' | 'None' = 'Lax'): void: Delete a cookie.
  • deleteAll(path?: string, domain?: string, secure?: boolean, sameSite: 'Lax' | 'None' | 'Strict' = 'Lax'): void: Delete all cookies.

CookieOptions

  • expires?: number | Date: Expiration date of the cookie. If not set, the cookie is a session cookie.
  • path?: string: Path for which the cookie is valid.
  • domain?: string: Domain for which the cookie is valid.
  • secure?: boolean: If true, the cookie will only be sent over HTTPS.
  • sameSite?: 'Lax' | 'Strict' | 'None': SameSite attribute of the cookie.

License

This project is licensed under the MIT License - see the LICENSE file for details.