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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@spider-baby/ssr-storage

v2.0.1

Published

An Angular service that provides a Server-Side Rendering (SSR) compatible wrapper for localStorage. It safely accesses localStorage in browser environments and provides no-op implementations for server-side rendering to prevent errors.

Readme

@spider-baby/ssr-storage

Angular NX TypeScript

A lightweight Angular service that provides a wrapper around the browser's localStorage API with built-in support for Server-Side Rendering (SSR).

Features

  • 🔄 Full localStorage API implementation
  • 🛡️ Type-safe methods for working with objects
  • 🖥️ Server-side rendering compatible
  • ⚠️ Error handling for all storage operations
  • 🪶 Zero dependencies beyond Angular

Installation

npm i @spider-baby/ssr-storage

Usage

Basic operations

import { Component } from '@angular/core';
import { SsrLocalStorage } from '@spider-baby/ssr-storage';

@Component({
  selector: 'app-example',
  template: `<div>{{ storedValue }}</div>`
})
export class ExampleComponent {

private storage = inject(SsrLocalStorage)

  storedValue: string;

  constructor() {
    // Store a value
    this.storage.setItem('greeting', 'Hello, World!');
    
    // Retrieve a value
    this.storedValue = this.storage.getItem('greeting');
    
    // Remove a value
    this.storage.removeItem('oldKey');
    
    // Clear all values
    // this.storage.clear();
  }
}

Working with objects

import { SsrLocalStorage } from '@spider-baby/ssr-storage';

interface User {
  id: number;
  name: string;
  email: string;
}

// Store an object
const user: User = { id: 1, name: 'John Doe', email: '[email protected]' };
this.storage.setItemObject<User>('currentUser', user);

// Retrieve an object
const storedUser = this.storage.getItemObject<User>('currentUser');

Error handling

try {
  const value = this.storage.getItem('key');
  // Use the value
} catch (error) {
  console.error('Storage operation failed:', error);
  // Handle the error appropriately
}

API Reference

SsrLocalStorage

Basic Methods

| Method | Description | Parameters | Return | |--------|-------------|------------|--------| | getItem(key: string) | Retrieves an item from storage | key: Storage key | string \| null | | setItem(key: string, value: string) | Stores a string value | key: Storage keyvalue: String to store | void | | removeItem(key: string) | Removes an item from storage | key: Storage key | void | | clear() | Clears all storage | None | void | | key(index: number) | Gets the key at the specified index | index: Numeric position | string \| null | | length() | Gets the number of items in storage | None | number |

Object Methods

| Method | Description | Parameters | Return | |--------|-------------|------------|--------| | getItemObject<T>(key: string) | Retrieves and parses a JSON object | key: Storage key | T \| null | | setItemObject<T>(key: string, value: T) | Stringifies and stores an object | key: Storage keyvalue: Object to store | void |

SSR Considerations

When running in server-side rendering mode, the service automatically return null on all 'gets' and skips all 'sets'. This ensures your application works seamlessly in both client and server environments without modifications.

Examples

Usage with Angular Services

@Injectable({
  providedIn: 'root'
})
export class UserService {
  
  private storage = inject(SsrLocalStorage)
  
  saveUserPreferences(prefs: UserPreferences): void {
    this.storage.setItemObject('userPreferences', prefs); //<UserPreferences> can be omitted because TypeScript infers the type from the value
  }
  
  getUserPreferences(): UserPreferences | null {
    return this.storage.getItemObject<UserPreferences>('userPreferences');
  }
}

Observable Pattern

@Injectable({
  providedIn: 'root'
})
export class ThemeService {

  
  private storage = inject(SsrLocalStorage)


  private themeSubject = new BehaviorSubject<string>('light');
  public theme$ = this.themeSubject.asObservable();
  
  constructor() {
    const savedTheme = this.storage.getItem('theme') || 'light';
    this.themeSubject.next(savedTheme);
  }
  
  setTheme(theme: string): void {
    this.storage.setItem('theme', theme);
    this.themeSubject.next(theme);
  }
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

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