# @ruanitto/ngx-local-storage

> LocalStorageService for Angular with mostly the same API (and most of the code) from angular-local-storage

Latest version **22.0.0** (published 2026-08-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install @ruanitto/ngx-local-storage
pnpm add @ruanitto/ngx-local-storage
yarn add @ruanitto/ngx-local-storage
bun add @ruanitto/ngx-local-storage
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 22.0.0 |
| Published | 2026-08-21 |
| First published | 2023-12-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 46.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Craig Spence |
| Maintainers | ruanitto |
| Keywords | ngx, localStorage, sessionStorage, ruanitto, angular, angular22, localstorage |

## Links

- npm: https://www.npmjs.com/package/@ruanitto/ngx-local-storage
- Repository: https://github.com/ruanitto/ngx-local-storage
- Homepage: https://github.com/ruanitto/ngx-local-storage#readme
- Issues: https://github.com/ruanitto/ngx-local-storage/issues
- npm.io page: https://npm.io/package/@ruanitto/ngx-local-storage

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0
- [crypto-es](https://npm.io/package/crypto-es.md) ^2.1.0

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 22.0.0 (latest) — 2026-08-21
- 21.0.0 — 2026-08-21
- 20.0.0 — 2026-08-21
- 19.0.0 — 2026-08-21
- 18.0.0 — 2026-08-21
- 17.0.0 — 2026-08-21
- 1.3.9 — 2023-12-26
- 1.3.8 — 2023-12-22
- 1.3.7 — 2023-12-22
- 1.3.6 — 2023-12-11
- 1.3.5 — 2023-12-11
- 1.3.4 — 2023-12-11
- 1.3.3 — 2023-12-11
- 1.1.3 — 2023-12-11

## README

# @ruanitto/ngx-local-storage

LocalStorageService for Angular with mostly the same API (and most of the code) from [angular-local-storage](https://github.com/grevory/angular-local-storage).

AoT compatible. Compatible with Angular 22.* (Ivy partial compilation).

## Versioning

Following a versioning scheme similar to Angular itself, starting from `17.0.0` this package follows the major version of Angular it targets:

| Package version | Angular version |
| --------------- | --------------- |
| `22.x`          | `^22.0.0`       |
| `21.x`          | `^21.0.0`       |
| `20.x`          | `^20.0.0`       |
| `19.x`          | `^19.0.0`       |
| `18.x`          | `^18.0.0`       |
| `17.x`          | `^17.0.0`       |
| `< 17` (e.g. `1.3.6`) | `>=10 <17` (use previous releases) |

For Angular versions below 17, please use the previous package versions (e.g. `npm install @ruanitto/ngx-local-storage@1.3.6`).

## NEW Feature added

* Addeded feature to encrypt/decrypt storage data

## Differences

* No events broadcast on $rootScope - LocalStorageService exposes observables for `errors$`,`removeItems$`, `setItems$` and `warning$` if you really need something to happen when something happens.
* The `bind` function doesn't work anymore (there is a stub so this can still be a drop-in, but it'll do nothing).

## Install

`npm install @ruanitto/ngx-local-storage`

## Usage

You can optionally configure the module:

```typescript
import { LocalStorageModule } from '@ruanitto/ngx-local-storage';

@NgModule({
    imports: [
        LocalStorageModule.forRoot({
            prefix: 'my-app',
            storageType: 'localStorage',
            encrypt: true,
            encryptKey: 'securekey'
        })
    ],
    declarations: [
        ..
    ],
    providers: [
        ..
    ],
    bootstrap: [AppComponent]
})
export class AppModule { }
```

Or, for standalone apps (Angular 17 default), configure via `provideLocalStorage`:

```typescript
import { ApplicationConfig } from '@angular/core';
import { provideLocalStorage } from '@ruanitto/ngx-local-storage';

export const appConfig: ApplicationConfig = {
    providers: [
        provideLocalStorage({
            prefix: 'my-app',
            storageType: 'localStorage',
            encrypt: true,
            encryptKey: 'securekey'
        })
    ]
};
```

Then you can use it in a component:

```typescript
import { LocalStorageService } from '@ruanitto/ngx-local-storage';

@Component({
    // ...
})
export class SomeComponent {
    constructor (
        private localStorageService: LocalStorageService
    ) {
        // YAY!
    }
}

```

### Configuration options

`import { ILocalStorageServiceConfig } from '@ruanitto/ngx-local-storage';` for type information about the configuration object.

### Testing

For unit tests, use `provideMockLocalStorage` in your `TestBed` providers (or standalone app config). It defaults to a `test-app` prefix and can optionally back the service with an in-memory `Storage`, fully isolating tests from real persisted data:

```typescript
import { TestBed } from '@angular/core/testing';
import {
    provideMockLocalStorage,
    LOCAL_STORAGE_MOCK_STORAGE,
    LocalStorageService
} from '@ruanitto/ngx-local-storage';

describe('SomeComponent', () => {
    beforeEach(() => {
        TestBed.configureTestingModule({
            providers: [
                provideMockLocalStorage(
                    { prefix: 'test-app', storageType: 'localStorage' },
                    { inMemoryStorage: true }
                )
            ]
        });
    });

    it('isolates storage per test', () => {
        const service = TestBed.inject(LocalStorageService);
        const mock = TestBed.inject(LOCAL_STORAGE_MOCK_STORAGE); // inspect/clear between tests

        service.set('user', { name: 'Rafael' });

        expect(service.get('user')).toEqual({ name: 'Rafael' });
        expect(mock.length).toBe(1);
    });
});
```

Without `{ inMemoryStorage: true }` the helper behaves like `provideLocalStorage` with test-friendly defaults, using the environment's real storage.

The package ships its own specs (`npm test`) with 100% coverage; run them with:

```
npm run test
npm run test:coverage
```

---
_Source: https://npm.io/package/@ruanitto/ngx-local-storage · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
