diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml new file mode 100644 index 0000000..6df8ceb --- /dev/null +++ b/.github/actions/setup-node/action.yml @@ -0,0 +1,29 @@ +name: Action for setting up node +description: Setup Node.js + +inputs: + node-version: + description: Node.js version + required: false + default: 18.x + +runs: + using: composite + steps: + - name: Use Node.js ${{ inputs.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.node-version }} + cache: npm + + - name: Cache NPM dependencies + uses: actions/cache@v3 + id: cache-npm-dependencies + with: + path: node_modules + key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }} + + - name: Install Dependencies + if: steps.cache-npm-dependencies.outputs.cache-hit != 'true' + shell: bash + run: npm ci diff --git a/.github/workflows/MANUAL_github-pages.yml b/.github/workflows/MANUAL_github-pages.yml index f0df10f..d5789b2 100644 --- a/.github/workflows/MANUAL_github-pages.yml +++ b/.github/workflows/MANUAL_github-pages.yml @@ -12,13 +12,7 @@ jobs: uses: actions/checkout@v3 - name: Setup node - uses: actions/setup-node@v2 - with: - node-version: '18' - cache: 'npm' - - - name: Install dependencies - run: npm i + uses: ./.github/actions/setup-node - name: Build the docs run: npm run docs @@ -26,7 +20,7 @@ jobs: - name: Upload Artifacts uses: actions/upload-pages-artifact@v1 with: - path: docs + path: docs/browser deploy: name: Deploys the artifact to Github Pages diff --git a/.github/workflows/RELEASE_github-pages.yml b/.github/workflows/RELEASE_github-pages.yml index 6abf677..b501280 100644 --- a/.github/workflows/RELEASE_github-pages.yml +++ b/.github/workflows/RELEASE_github-pages.yml @@ -14,13 +14,7 @@ jobs: uses: actions/checkout@v3 - name: Setup node - uses: actions/setup-node@v2 - with: - node-version: '18' - cache: 'npm' - - - name: Install dependencies - run: npm i + uses: ./.github/actions/setup-node - name: Build the docs run: npm run docs @@ -28,7 +22,7 @@ jobs: - name: Upload Artifacts uses: actions/upload-pages-artifact@v1 with: - path: docs + path: docs/browser deploy: name: Deploys the artifact to Github Pages diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 9cfb4fa..3aca7a9 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -7,27 +7,16 @@ on: jobs: build: runs-on: ubuntu-latest - strategy: - matrix: - node-version: [18.x] steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v3 - - name: Cache node modules - uses: actions/cache@v1 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - name: Node ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} + - name: Setup node + uses: ./.github/actions/setup-node - - name: Install dependencies - run: | - npm ci - npm run lint - npm run test + - name: Lint + run: npm run lint + + - name: Test + run: npm run test diff --git a/.gitignore b/.gitignore index 69957a2..18b6825 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,7 @@ Thumbs.db .angular -.nx/cache \ No newline at end of file +.nx/cache + +# NgDoc files +/ng-doc \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ab6bebf..2c3dbd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ + + +# [6.0.0](https://github.com/bohoffi/ngx-localstorage/compare/5.1.0...6.0.0) (2024-03-10) + +### 🚀 Features + +- add support for `formControl` ([68406fc](https://github.com/bohoffi/ngx-localstorage/commit/68406fc)) +- expose library version token ([8040c85](https://github.com/bohoffi/ngx-localstorage/commit/8040c85)) + +### BREAKING CHANGES + +- update to Angular 17 ([3942bee](https://github.com/bohoffi/ngx-localstorage/commit/3942bee)) + +### ❤️ Thank You + +- bohoffi @bohoffi + # [5.1.0](https://github.com/bohoffi/ngx-localstorage/compare/5.0.0...5.1.0) (2023-10-29) diff --git a/README.md b/README.md index 517d4c7..c2c6036 100644 --- a/README.md +++ b/README.md @@ -1,105 +1,25 @@ - - -[![npm version](https://img.shields.io/npm/v/ngx-localstorage.svg)](https://www.npmjs.com/package/ngx-localstorage) +
+ An Angular wrapper for localstorage/sessionstorage access
+
+ [![NPM][npm-shield]][npm-url]
+ [![License][license-shield]][license-url]
+ [![Release Workflow Status][build-shield]][build-url]
+
Import symbols from ngx-localstorage
LocalStorageService
-
-Provides a service to access the localstorage.
- -Name | -Description | -
---|---|
- |
- Configuration used by the service. - |
-
clear - | -|
---|---|
- Clears all entries of the applications local storage. - - |
-
count - | -|
---|---|
- Gets the number of entries in the applications storage. - - |
- |
Returns | -|
- number | undefined
- |
-
- - - - |
-
error - | -|
---|---|
- Triggers the service to emit the given error. - - |
- |
Parameters | -|
- - error -unknown
- |
-
-
-
- Error to emit through the service. - - |
-
get - | -|
---|---|
- Gets the entry specified by the given key if existing - otherwise |
- |
Parameters | -|
- - key -string
- |
-
-
-
- Key identifying the wanted entry. - - |
-
- - options? -ServiceOptions
- |
-
-
-
- Options for overwriting configuration with the following properties: -
|
-
Returns | -|
- T | null | undefined
- |
-
- - - - |
-
getKey - | -|
---|---|
- Returns the nth (defined by the index parameter) key in the storage. -The order of keys is user-agent defined, so you should not rely on it. - - |
- |
Parameters | -|
- - index -number
- |
-
-
-
- An integer representing the number of the key you want to get the name of. This is a zero-based index. - - |
-
Returns | -|
- string | null | undefined
- |
-
- - - - |
-
remove - | -|
---|---|
- Removes the entry specified by the given key. - - |
- |
Parameters | -|
- - key -string
- |
-
-
-
- Key identifying the entry to remove. - - |
-
- - prefix? -string
- |
-
-
-
- Optional prefix to overwrite the configured one. - - |
-
set - | -|
---|---|
- Adds the value with the given key or updates an existing entry. - - |
- |
Parameters | -|
- - key -string
- |
-
-
-
- Key identifying the wanted entry. - - |
-
- - value -T
- |
-
-
-
- Value to store. - - |
-
- - options? -ServiceOptions
- |
-
-
-
- Options for overwriting configuration with the following properties: -
|
-
LocalStorageDirective
-
-Provide a directive to directly interact with stored values.
- -- Selector: - - [ngxLocalStorage] - -
- Standalone: - true -
Name | -Description | -
---|---|
- @Input()
- |
- An optional transformer to handle falsy values. - |
-
- @Input()
- |
- The event to hook onto value changes. - |
-
- @Input()
- |
- Flag if the bound elements value should be initialized from storage. - |
-
@Input('ngxLocalStorage')
-
- |
- The key to use with localstorage. - |
-
- @Input()
- |
- The keys prefix to use. - |
-
- @Input()
- |
- An optional debounce for storage write access after value changes. - |
-
- @Input()
- |
- Provides a path to access the bound elements value property. - |
-
- @Output()
- |
- Event which gets fired when a bound value got stored. - |
-
NgxLocalstorageConfiguration
-Provides the configuration used by the service and directive.
-Name | -Description | -
---|---|
- |
- Determines if null | 'null' values should be stored. (Default: true) - |
-
- |
- Determines the delimiter, will used befoure key. (Default: _) - |
-
- |
- Determines the key prefix. (Default: null) - |
-
- |
- Determines the storage type. (Default: localStorage) - |
-
StorageSerializer
-Defines the librarys serializer.
-deserialize - | -|
---|---|
- Deserializes a stored value. - - |
- |
Parameters | -|
- - storedValue -string
- |
-
-
-
- stored value - - |
-
Returns | -|
- T
- |
-
- - - - |
-
serialize - | -|
---|---|
- Prepares the value to be stored as its string representation. - - |
- |
Parameters | -|
- - value -T
- |
-
-
-
- Value to be serialized - - |
-
Returns | -|
- string
- |
-
- - - - |
-
provideNgxLocalstorage
-Provides the basic configuration and optional additional features.
-
-const provideNgxLocalstorage: (configuration?: NgxLocalstorageConfiguration, ...features: SerializerFeature[]) => EnvironmentProviders;
-
-withSerializer
-Provides a custom serializer.
-
-const withSerializer: (serializer: Type<StorageSerializer>) => SerializerFeature;
-
-NGX_LOCAL_STORAGE_CONFIG
-Provides an injection token for the service configuration.
-
-const NGX_LOCAL_STORAGE_CONFIG: InjectionToken<NgxLocalstorageConfiguration>;
-
-STORAGE_SUPPORT
-Provides information if choosen stoarge is available.
-
-const STORAGE_SUPPORT: InjectionToken<boolean>;
-
-NGX_LOCAL_STORAGE_SERIALIZER
-Provides an injection token for the services serializer.
-
-const NGX_LOCAL_STORAGE_SERIALIZER: InjectionToken<StorageSerializer>;
-
-Using the 'ngxLocalStorage' directive you can bind template controls to localstorage values.
- -Result
- - - - -Binding a Checkbox
+ + +Binding a text Input
+ + +Binding a Checkbox
+ + +Binding a text Input
+ + +Subscribe to the `LocalStorageService` to receive storage updates.
- -Result (modify text or checkbox in another tab or in Chrome DevTools)
- -{ "key": "{{ e.key }}"; "oldValue": "{{ e.oldValue }}"; "newValue": "{{ e.newValue }}" }
-Try modifying the controls from the Directive demo in another browser tab.
+ @for (event of events | async; track $index) { +
+
+ Key: {{ event.key | json }}
+ NewValue {{ event.newValue | json }}
+ OldValue {{ event.oldValue | json }}
+
+
+ }
+{{ storedObject | json }}
diff --git a/apps/ngx-localstorage-demo/src/app/components/service/storage-service.component.ts b/apps/ngx-localstorage-demo/src/app/components/service/storage-service.component.ts
new file mode 100644
index 0000000..ffec3eb
--- /dev/null
+++ b/apps/ngx-localstorage-demo/src/app/components/service/storage-service.component.ts
@@ -0,0 +1,34 @@
+// snippet-from-file="./storage-service.component.ts"
+
+import { JsonPipe } from '@angular/common';
+import { Component, inject } from '@angular/core';
+import { LocalStorageService } from 'ngx-localstorage';
+
+interface StoredObject {
+ id: number;
+ name: string;
+}
+
+@Component({
+ standalone: true,
+ imports: [JsonPipe],
+ templateUrl: './storage-service.component.html'
+})
+export class StorageServiceComponent {
+ // snippet "Injecting the service"
+ protected readonly storageService = inject(LocalStorageService);
+ // snippet
+
+ // snippet "Reading from storage"
+ protected readonly storedObject = this.storageService.getThe service can be utilized to communicate with the storage.
- -Result
- - -The library is fully lazy-/feature-module capable.
- -Result
- - -