### File

`projects/app-base-library/src/lib/shared/util/storage.ts`

### Index

###### Methods

- Static flushLocalModel
- Static restoreLocalModel
- Static saveLocalModel

### Methods

Static flushLocalModel
`flushLocalModel(modelName: string)`
Defined in projects/app-base-library/src/lib/shared/util/storage.ts:24

Parameters :

Name | Type | Optional | Default value
modelName | `string` | no | `'model'`

Returns : `void`

Static restoreLocalModel
`restoreLocalModel(modelName: string)`
Defined in projects/app-base-library/src/lib/shared/util/storage.ts:13

Parameters :

Name | Type | Optional | Default value
modelName | `string` | no | `'model'`

Returns : `any`

Static saveLocalModel
`saveLocalModel(model: any, modelName: string)`
Defined in projects/app-base-library/src/lib/shared/util/storage.ts:3

Parameters :

Name | Type | Optional | Default value
model | `any` | no |
modelName | `string` | no | `'model'`

Returns : `void`

    export class Storage {

        static saveLocalModel(model: any, modelName: string = 'model') {
            if (typeof window !== 'undefined' && window.localStorage) {
                // window.localStorage.setItem(modelName , btoa(JSON.stringify(model)));
                window.localStorage.setItem(modelName , JSON.stringify(model));
                window.localStorage.setItem(modelName + '-changed', String(Math.round(+new Date() / 1000)));
            } else {
                console.error('localStorage not available: not running in a browser');
            }
        };

        static restoreLocalModel(modelName: string = 'model') {
            if (typeof window !== 'undefined' && window.localStorage) {
                if (localStorage.getItem(modelName)) {
                    // return JSON.parse(atob(localStorage.getItem(modelName)));
                    return JSON.parse(localStorage.getItem(modelName));
                }
            } else {
                console.error('localStorage not available: not running in a browser');
            }
        };

        static flushLocalModel(modelName: string = 'model') {
            if (typeof window !== 'undefined' && window.localStorage) {
                if (localStorage.getItem(modelName)) {
                    localStorage.removeItem(modelName);
                }
                if (localStorage.getItem(modelName + '-changed')) {
                    localStorage.removeItem(modelName + '-changed');
                }
            } else {
                console.error('localStorage not available: not running in a browser');
            }
        };

    }

# results matching ""

# No results matching ""