Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve README.md #3

Merged
merged 2 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 53 additions & 22 deletions README.MD → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,52 @@ The `Encrypt Storage` is a `wrapper` for native `Storage` of browser.

Using the `crypto-js` library as an encryption engine, it saves the encrypted data on the `selected storage` in the same way as the native `Storage`.

- [Encrypt Storage](#encrypt-storage)
- [Features](#features)
- [Installing](#installing)
- [Example](#example)
- [CommonJS](#commonjs)
- [JS Import (es6)](#js-import-es6)
- [Parameters](#parameters)
- [secretKey](#secretkey)
- [options](#options)
- [Usage](#usage)
- [setItem](#setitem)
- [getItem](#getitem)
- [removeItem](#removeitem)
- [clear](#clear)
- [key](#key)
- [length](#length)
## Table of Contents

- [Features](#features)
- [Installing](#installing)
- [Examples](#examples)
- [CommonJS](#commonjs)
- [JS Import (es6)](#js-import-es6)
- [Conventions](#conventions)
- [Parameters](#parameters)
- [secretKey](#secretkey)
- [options](#options)
- [Usage](#usage)
- [setItem](#setitem)
- [getItem](#getitem)
- [removeItem](#removeitem)
- [clear](#clear)
- [key](#key)
- [length](#length)
- [License](#License)

## Features
- Save encrypted data in `localStorage` and `sessionStorage`
- Recover encrypted data
- Use in the same way as native Storage
- Use with `stateManagement` persisters (`vuex-persist` and `redux-persist`)


## Installing

> To run this project in the development mode, you'll need to have a basic environment with NodeJs and Yarn installed.

Using npm:

```bash
$ npm install encrypt-storage
```
Using yarn:

Or yarn:

```bash
$ yarn add encrypt-storage
```

## Example
## Examples

### CommonJS

```typescript
const { EncryptStorage } = require('encrypt-storage');

Expand All @@ -50,11 +60,13 @@ module.exports = encryptStorage
```

### JS Import (es6)

```typescript
import { EncryptStorage } from 'encrypt-storage';

export const encryptStorage = EncryptStorage('secret_key', options);
```
### Conventions

Create a file in your utils folder or a folder of your choice. But I advise you to use it as a singleton, so to speak, for better use.

Expand All @@ -65,14 +77,18 @@ Create a file in your utils folder or a folder of your choice. But I advise you
┗ 📜 index.ts
```

> Directory Layout

```typescript
// const { EncryptStorage } = require('encrypt-storage');

export const encryptStorage = EncryptStorage('secret_key', options)
```

## Parameters

### secretKey

The `secretKey` parameter is a `string` you encrypt your data. If you use a `framework` like `ReactJS` or `VueJS` prefer to store this data in your application's `.env` file:

```typescript
Expand All @@ -82,9 +98,11 @@ export const encryptStorage = EncryptStorage(process.env.SECRET_KEY, options)
```

### options
The options object is made up of the following properties:

The options object consists of the following properties:

*prefix*: default `null` - is optional and is the prefix of all keys used in the selected storage as shown below:

```typescript
//...
export const encryptStorage = EncryptStorage('secret_key', {
Expand All @@ -95,11 +113,12 @@ export const encryptStorage = EncryptStorage('secret_key', {

in your storage:

![storageKeyValue](./.github/images/storageKeyValue.png)
![storageKeyValue](./docs/resources/storageKeyValue.png)

*stateManagementUse*: default `false` - is a `boolean` value that, when true allows the use of it with `vuex-persist` and `redux-persist`:

**redux-persist**

```typescript
...
const persistConfig = {
Expand All @@ -111,6 +130,7 @@ const persistConfig = {
```

**vuex-persist**

```typescript
...
const vuexLocal = new VuexPersistence({
Expand All @@ -129,6 +149,7 @@ export const encryptStorage = EncryptStorage('secret_key', {
```

## Usage

The usage follows the premise that encryptStorage has been "instantiated" in another file. In the example, the utils folder is used and JS imports.

### setItem
Expand All @@ -150,31 +171,41 @@ const decryptedData = encryptStorage.getItem('user');
```

### removeItem

Remove an item from `selectedStorage`

```typescript
...
encryptStorage.removeItem('user');
```

### clear

Clear all data from `selectedStorage`

```typescript
...
encryptStorage.clear();
```

### key

Returns a key of `index` param or `null` if not exists

```typescript
...
encryptStorage.key(0);
```

### length

Returns a `quantity` of `keys` existents in `selectedStorage`

```typescript
...
encryptStorage.key(0);
```

Sorry for my english 😢
# License

[MIT License](/LICENSE)