Skip to content

Commit

Permalink
Merge pull request #2 from nixgram/1-implement-jsdoc-support
Browse files Browse the repository at this point in the history
implemented jsDoc support #1
  • Loading branch information
sefatanam authored Nov 19, 2022
2 parents ec1c1b4 + 9f75831 commit 9dab7f4
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 24 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# Crypto Browser Storage
☢ A simple package for secure local storage data by encryption using Crypto.JS
☢ A simple package for secure local storage data by encryption using Crypto.JS. Project generated with angular version ```12.2.0```, sou must need an Angular Project ( ``version >= 12.2.x`` )

## How to use
* Must need an Angular Project ( ``version >= 12.x.x`` )
* Use ``npm i crypto-browser-storage``
* Inject your Component or Service as Dependency Injection
* Then you will be able to access `crypto-browser-storage`'s library function to set, retrieve & many more.
* Inject to your component or service as Dependency Injection
* Then you will be able to access `crypto-browser-storage`'s library functions,
- setCache
- getCache
- removeCacheByKey
- clearAllCache

<br>

## Sample Code Snippet
<br>


````
import { CryptoBrowserStorageService } from 'crypto-browser-storage';
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crypto-browser-storage",
"version": "0.0.0",
"version": "1.0.6",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down Expand Up @@ -36,5 +36,6 @@
"karma-jasmine-html-reporter": "~1.7.0",
"ng-packagr": "^12.1.1",
"typescript": "~4.3.5"
}
},
"license": "MIT"
}
15 changes: 11 additions & 4 deletions projects/crypto-browser-storage/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# Crypto Browser Storage
☢ A simple package for secure local storage data by encryption using Crypto.JS
☢ A simple package for secure local storage data by encryption using Crypto.JS. Project generated with angular version ```12.2.0```, sou must need an Angular Project ( ``version >= 12.2.x`` )

## How to use
* Must need an Angular Project ( ``version >= 12.x.x`` )
* Use ``npm i crypto-browser-storage``
* Inject your Component or Service as Dependency Injection
* Then you will be able to access `crypto-browser-storage`'s library function to set, retrieve & many more.
* Inject to your component or service as Dependency Injection
* Then you will be able to access `crypto-browser-storage`'s library functions,
- setCache
- getCache
- removeCacheByKey
- clearAllCache

<br>

## Sample Code Snippet
<br>


````
import { CryptoBrowserStorageService } from 'crypto-browser-storage';
Expand Down
151 changes: 149 additions & 2 deletions projects/crypto-browser-storage/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions projects/crypto-browser-storage/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crypto-browser-storage",
"version": "0.0.1",
"version": "1.0.6",
"description": "☢ A simple package for secure local storage data by encryption using Crypto.JS",
"author": {
"url": "https://github.com/nixgram",
Expand All @@ -23,5 +23,6 @@
"devDependencies": {
"@types/crypto-js": "^4.0.2",
"@types/node": "^16.11.6"
}
},
"license": "MIT"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Injectable} from '@angular/core';
import { Injectable } from '@angular/core';
import * as CryptoJS from "crypto-js";
import {KEY} from "./KEY";
import { KEY } from "./KEY";

const SecureStorage = require("secure-web-storage");

Expand Down Expand Up @@ -30,9 +30,13 @@ export class CryptoBrowserStorageService {
});


// Set local storage data via key
/**
* Set data to localstorage via key
* @param {any} key:string
* @param {any} data: any
* @returns {void} void
*/
public setCache(key: string, data: any): void {

try {
if (data) {
this.secureStorage.setItem(key, data);
Expand All @@ -44,26 +48,40 @@ export class CryptoBrowserStorageService {
}
}

// Get local storage data via key

/**
* Get localstorage data via key
* @param {any} key:string
* @returns {any} any: number | string | object | array
*/
public getCache(key: string) {
try {
return this.secureStorage.getItem(key);
} catch (error) {
console.log(`Error To Get ${key} Cache Data:`, error);
console.log('Key not found in localstorage or maybe wrong key.');
}
}


// Remove stored local storage data via key
/**
* It will remove stored local storage data via key
* @param {any} key:string
* @returns {void} void
*/

public removeCacheByKey(key: string) {
try {
this.secureStorage.removeItem(key);
} catch (error) {
console.log(`Error To Remove ${key} Cache Data:`, error);
console.error('Key not found in localstorage or maybe wrong key.');
}
}

// It remove all local storage stored data

/**
* It behave like native localstorage clear() function. It will clear all cache including pre-existing localstorage data.
* @returns {void} void
*/
public clearAllCache() {
localStorage.clear();
}
Expand Down

0 comments on commit 9dab7f4

Please sign in to comment.