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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@i4mi/ionic-storage-service

v0.0.3

Published

IONIC service for native and secure storage access

Downloads

4

Readme

Ionic-Storage-Service

USE AT OWN RISK - WIP -

Service lib to easily implement a storage service for your ionic project. Just install the lib and requeired plugins, import it and you are ready to go :)

Usage

1. Install package

npm i @i4mi/ionic-storage-service

## 2. Install dependencies

ionic cordova plugin add secure-storage-echo
ionic cordova plugin add nativestorage
ionic cordova plugin add cordova-open-native-settings

3. Add as provider

Add to your app.module.ts:

import { IonicStorageService } from '@i4mi/ionic-storage-service';

@NgModule({
  ...
  providers: [
    ...
    IonicStorageService,
    ...
  ],
  ...
})

4. Call init on app startup

Normally just call the init:

import { IonicStorageService } from '@i4mi/ionic-storage-service';
@Component({
    templateUrl: 'sample.html',
    styleUrls: ['sample.scss']
})
export class SamplePage {

    constructor(private _storageService: IonicStorageService) {}

    // Using lifecycle event to be sure page is loaded before the magic happens :)
    ionViewDidEnter() {
        this._storageService.init(
            'NAME',
            ['SECURE_KEY1', 'SECURE_KEY2'],
            ['NATIVE_KEY1', 'NATIVE_KEY2'], )
            .then(() => { 
                console.log('yeyy :)');
            }).catch((error) => {
                console.log(error);
            });
    }
}

If you want to open the native settings when a user has no secured device, call the open screen lock settings function

    ionViewDidEnter() {
        this._storageService.init(
            'NAME',
            ['SECURE_KEY1', 'SECURE_KEY2'],
            ['NATIVE_KEY1', 'NATIVE_KEY2'], )
            .then(() => { 
                console.log('yeyy :)');
            }).catch((error) => {
                // NOW CALLING OPEN SCREEN LOCK
                this._storageService.openScreenLockSettings(() => {
                    // HERE YOU CAN USE A HANDLER FUNCTION
                    // THIS DOES ONLY WORK ON ANDROÌD
                }
                console.log(error);
            });
    }

5. Using the functions

### save You can save an object or a value with the save method:

    awesomeSave() {
        const emptyObjectToSave = {};
        // SAVING TO SECURE STORAGE
        // 1: When key is was in init array
        this._storageService.save('SECURE_KEY1', emptyObjectToSave).then((obj) => {
            console.log(obj);
        }).catch((error) => {
            console.log(error);
        });
        // 2: When key was NOT in init array
        this._storageService.save('SOME_OTHER_SECURE_KEY', emptyObjectToSave, true).then((obj) => {
            console.log(obj);
        }).catch((error) => {
            console.log(error);
        });

        // SAVING TO NATIVE STORAGE
        // 1. When key was in init array
        this._storageService.save('NATIVE_KEY1', emptyObjectToSave).then((obj) => {
            console.log(obj);
        }).catch((error) => {
            console.log(error);
        });
        // 2. When key was NOT in init, DO THE SAME AS ABOVE OR...
        this._storageService.save('SOME_OTHER_NATIVE_KEY', emptyObjectToSave, false).then((obj) => {
            console.log(obj);
        }).catch((error) => {
            console.log(error);
        });
    }

get

Get the object or value stored in storage:

    awesomeGet() {
        // GET FROM SECURE STORAGE
        // 1: When key is was in init array
        this._storageService.get('SECURE_KEY1').then((obj) => {
            console.log(obj);
        }).catch((error) => {
            console.log(error);
        });
        // 2: When key was NOT in init array
        this._storageService.get('SOME_OTHER_SECURE_KEY', true).then((obj) => {
            console.log(obj);
        }).catch((error) => {
            console.log(error);
        });

        // SAVING TO NATIVE STORAGE
        // 1. When key was in init array
        this._storageService.get('NATIVE_KEY1').then((obj) => {
            console.log(obj);
        }).catch((error) => {
            console.log(error);
        });
        // 2. When key was NOT in init, DO THE SAME AS ABOVE OR...
        this._storageService.get('SOME_OTHER_NATIVE_KEY', false).then((obj) => {
            console.log(obj);
        }).catch((error) => {
            console.log(error);
        });
    }

remove

Remove an object or value with given key

    awesomeRemove() {
        // GET FROM SECURE STORAGE
        // 1: When key is was in init array
        this._storageService.remove('SECURE_KEY1').then((obj) => {
            console.log(obj);
        }).catch((error) => {
            console.log(error);
        });
        // 2: When key was NOT in init array
        this._storageService.remove('SOME_OTHER_SECURE_KEY', true).then((obj) => {
            console.log(obj);
        }).catch((error) => {
            console.log(error);
        });

        // SAVING TO NATIVE STORAGE
        // 1. When key was in init array
        this._storageService.remove('NATIVE_KEY1').then((obj) => {
            console.log(obj);
        }).catch((error) => {
            console.log(error);
        });
        // 2. When key was NOT in init, DO THE SAME AS ABOVE OR...
        this._storageService.remove('SOME_OTHER_NATIVE_KEY', false).then((obj) => {
            console.log(obj);
        }).catch((error) => {
            console.log(error);
        });
    }

### clear Cleans both storages:

    awesomeClear() {
       this._storageService.clear().then(() => {
           // do your stuff
        }).catch((error) => {
            console.log(error);
        }); 
    }

keys

Returns the keys of all saved objects or values of both storages:

    awesomeKeys() {
       this._storageService.keys().then((keys: Array<string>) => {
            console.log(keys);
        }).catch((error) => {
            console.log(error);
        }); 
    }