<commit_before># ngrx-store-localstorage
Simple syncing between ngrx store and local storage

## Dependencies
`ngrx-store-localstorage` depends on [@ngrx/store](https://github.com/ngrx/store) and [Angular 2](https://github.com/angular/angular).

## Usage
```bash
npm install ngrx-store-localstorage --save
```
1. Import `compose` and `combineReducers` from `@ngrx/store` and `@ngrx/core/compose`
2. Invoke the `localStorageSync` function after `combineReducers`, specifying the slices of state you would like to keep synced with local storage.
3. Optionally specify whether to rehydrate this state from local storage as `initialState` on application bootstrap.
4. Invoke composed function with application reducers as an argument to `StoreModule.provideStore`.
```ts
import { Store, StoreModule } from '@ngrx/store';
import { todos, visibilityFilter } from './reducers';
import { NgModule } from '@angular/core';
import { localStorageSync } from 'ngrx-store-localstorage';

@NgModule({
  imports: [
    BrowserModule,
    StoreModule.provideStore(
        compose(
            localStorageSync(['todos']),
            combineReducers
        )({todos, visibilityFilter})
    )
  ]
})
export class MyAppModule {}
```

## API
### `localStorageSync(keys : any[], rehydrateState : boolean = false, storage: Storage = localStorage) : Reducer`
Provide state (reducer) keys to sync with local storage. Optionally specify whether to rehydrate `initialState` from local storage on bootstrap.
*Returns a meta-reducer*

#### Arguments
* `keys` State keys to sync with local storage. The keys can be defined in two different formats:
    * \(*string[]*): array of strings representing the state (reducer) keys. Full state will be synced (e.g. `localStorageSync(['todos'])`).

    * \(*object[]*): Array of objects where for each object the key represents the state key and the value represents custom serialize/deserialize options.  This can be one of the following:

        * an array of properties which should be synced. This allows for the partial state sync (e.g. `localStorageSync([{todos: ['name', 'status'] }, ... ])`)

        * a reviver function as specified in the [JSON.parse documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)

        * an object with properties that specify one or more of the following:

            * serialize: a function that takes a state object and returns a plain json object to pass to json.stringify

            * deserialize: a function that takes that takes the raw JSON from JSON.parse and builds a state object

            * replacer: a replacer function as specified in the [JSON.stringify documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)

            * space: the space value to pass JSON.stringify

            * reviver: a reviver function as specified in the [JSON.parse documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)

            * filter: an array of properties which should be synced (same format as the stand-along array specified above)            

* `rehydrateState` \(*boolean? = false*): Pull initial state from local storage on startup

* `storage` \(*Storage? = localStorage*): Specify an object that conforms to the Storage interface to use, this will default localStorage <commit_msg>Adding localStorageSyncAndClean definition to readme and including some punctuation for better reading<commit_after># ngrx-store-localstorage
Simple syncing between ngrx store and local storage.

## Dependencies
`ngrx-store-localstorage` depends on [@ngrx/store](https://github.com/ngrx/store) and [Angular 2](https://github.com/angular/angular).

## Usage
```bash
npm install ngrx-store-localstorage --save
```
1. Import `compose` and `combineReducers` from `@ngrx/store` and `@ngrx/core/compose`.
2. Invoke the `localStorageSync` function after `combineReducers`, specifying the slices of state you would like to keep synced with local storage.
3. Optionally specify whether to rehydrate this state from local storage as `initialState` on application bootstrap.
4. Invoke composed function with application reducers as an argument to `StoreModule.provideStore`.
```ts
import { Store, StoreModule } from '@ngrx/store';
import { todos, visibilityFilter } from './reducers';
import { NgModule } from '@angular/core';
import { localStorageSync } from 'ngrx-store-localstorage';

@NgModule({
  imports: [
    BrowserModule,
    StoreModule.provideStore(
        compose(
            localStorageSync(['todos']),
            combineReducers
        )({todos, visibilityFilter})
    )
  ]
})
export class MyAppModule {}
```

## API
### `localStorageSync(keys: any[], rehydrateState: boolean = false, storage: Storage = localStorage, removeOnUndefined: boolean = false): Reducer`
Provide state (reducer) keys to sync with local storage. Optionally specify whether to rehydrate `initialState` from local storage on bootstrap.
*Returns a meta-reducer*.

#### Arguments
* `keys` State keys to sync with local storage. The keys can be defined in two different formats:
    * \(*string[]*): Array of strings representing the state (reducer) keys. Full state will be synced (e.g. `localStorageSync(['todos'])`).

    * \(*object[]*): Array of objects where for each object the key represents the state key and the value represents custom serialize/deserialize options. This can be one of the following:

        * An array of properties which should be synced. This allows for the partial state sync (e.g. `localStorageSync([{todos: ['name', 'status'] }, ... ])`).

        * A reviver function as specified in the [JSON.parse documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).

        * An object with properties that specify one or more of the following:

            * serialize: A function that takes a state object and returns a plain json object to pass to json.stringify.

            * deserialize: A function that takes that takes the raw JSON from JSON.parse and builds a state object.

            * replacer: A replacer function as specified in the [JSON.stringify documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).

            * space: The space value to pass JSON.stringify.

            * reviver: A reviver function as specified in the [JSON.parse documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).

            * filter: An array of properties which should be synced (same format as the stand-along array specified above).

* `rehydrateState` \(*boolean? = false*): Pull initial state from local storage on startup.
* `storage` \(*Storage? = localStorage*): Specify an object that conforms to the Storage interface to use, this will default localStorage.
* `removeOnUndefined` \(*boolean? = false*): Specify if the state is removed from the storage when the new value is undefined.

---
### `localStorageSyncAndClean(keys: any[], rehydrate: boolean = false, removeOnUndefined: boolean = false): Reducer`
A shorthand that wraps the functionalities of `localStorageSync` and asumes `localStorage` as the storage.

#### Arguments

* `keys` State keys to sync with local storage. The keys can be defined in two different formats:
    * \(*string[]*): Array of strings representing the state (reducer) keys. Full state will be synced (e.g. `localStorageSync(['todos'])`).

    * \(*object[]*): Array of objects where for each object the key represents the state key and the value represents custom serialize/deserialize options. This can be one of the following:

        * An array of properties which should be synced. This allows for the partial state sync (e.g. `localStorageSync([{todos: ['name', 'status'] }, ... ])`).

        * A reviver function as specified in the [JSON.parse documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).

        * An object with properties that specify one or more of the following:

            * serialize: A function that takes a state object and returns a plain json object to pass to json.stringify.

            * deserialize: A function that takes that takes the raw JSON from JSON.parse and builds a state object.

            * replacer: A replacer function as specified in the [JSON.stringify documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).

            * space: The space value to pass JSON.stringify.

            * reviver: A reviver function as specified in the [JSON.parse documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).

            * filter: An array of properties which should be synced (same format as the stand-along array specified above).
* `rehydrateState` \(*boolean? = false*): Pull initial state from local storage on startup.
* `removeOnUndefined` \(*boolean? = false*): Specify if the state is removed from the storage when the new value is undefined.
{'fraction_non_alphanumeric': 0.09992388822442101, 'fraction_numerical': 0.0010873110796999022, 'mean_word_length': 3.9134615384615383, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 13, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1929280', 'n_tokens_mistral': 2493, 'n_tokens_neox': 2404, 'n_words': 977}