@degreesign/storage 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,53 +8,59 @@ Install using `yarn add @degreesign/storage` or `npm install @degreesign/storage
|
|
|
8
8
|
```typescript
|
|
9
9
|
import {
|
|
10
10
|
configureStorage,
|
|
11
|
+
saveData,
|
|
12
|
+
readData,
|
|
13
|
+
saveSecure,
|
|
14
|
+
readSecure,
|
|
11
15
|
} from "@degreesign/storage";
|
|
12
|
-
|
|
13
|
-
// configure storage system
|
|
14
|
-
await configureStorage({
|
|
15
|
-
storageKey: 'newAppData',
|
|
16
|
-
dbName: 'myDatabase',
|
|
17
|
-
storeName: 'users',
|
|
18
|
-
encryptionKey: 'my-secret-key-123'
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// quick save/read (unencrypted) only suitable for smaller data
|
|
22
|
-
const user: UserData = { id: `1`, name: 'Hasn', email: 'hasn@example.com' };
|
|
23
|
-
saveData({ key: `userData`, data: user });
|
|
24
|
-
const storedUser = readData<UserData>(`userData`);
|
|
25
|
-
console.log('Storage data:', storedUser);
|
|
26
|
-
saveData({ key: `userData` }); // Removes the key and data
|
|
27
|
-
|
|
28
|
-
// secure save/read (encrypted) useful for larger data
|
|
29
|
-
await saveSecure({ key: `userData`, data: user });
|
|
30
|
-
const dbUser = await readSecure<UserData>(`userData`);
|
|
31
|
-
console.log('Database data:', dbUser);
|
|
32
|
-
await saveSecure({ key: `userData` }); // Removes the key and data
|
|
33
16
|
```
|
|
34
17
|
|
|
35
18
|
## Browser Integration
|
|
36
19
|
Use in browsers through CDN
|
|
37
20
|
`<script src="https://cdn.jsdelivr.net/npm/@degreesign/storage@1.0.0/dist/browser/degreesign.min.js"></script>`
|
|
38
21
|
|
|
22
|
+
```typescript
|
|
23
|
+
const {
|
|
24
|
+
configureStorage,
|
|
25
|
+
saveData,
|
|
26
|
+
readData,
|
|
27
|
+
saveSecure,
|
|
28
|
+
readSecure,
|
|
29
|
+
} = window.stored;
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
39
34
|
```typescript
|
|
40
35
|
// configure storage system
|
|
41
|
-
await
|
|
42
|
-
storageKey: '
|
|
43
|
-
dbName: '
|
|
44
|
-
storeName: '
|
|
45
|
-
encryptionKey: '
|
|
36
|
+
await configureStorage({
|
|
37
|
+
storageKey: 'app_name',
|
|
38
|
+
dbName: 'database_name',
|
|
39
|
+
storeName: 'dataset_name',
|
|
40
|
+
encryptionKey: 'encryption_key'
|
|
46
41
|
});
|
|
47
42
|
|
|
48
|
-
//
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
console.log(
|
|
59
|
-
|
|
43
|
+
// sample data
|
|
44
|
+
const
|
|
45
|
+
key = `sample_key`,
|
|
46
|
+
data: SampleType = { id: `1`, name: 'Hasn', email: 'hasn@example.com' };
|
|
47
|
+
|
|
48
|
+
/** quick unencrypted, only suitable for smaller data */
|
|
49
|
+
// save
|
|
50
|
+
saveData({ key, data });
|
|
51
|
+
// read
|
|
52
|
+
const unsecureData = readData<SampleType>(key);
|
|
53
|
+
console.log(`unsecureData`, unsecureData);
|
|
54
|
+
// clear
|
|
55
|
+
saveData({ key });
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
/** secure, useful for larger data */
|
|
59
|
+
// save
|
|
60
|
+
await saveSecure({ key, data });
|
|
61
|
+
// read
|
|
62
|
+
const secureData = await readSecure<SampleType>(key);
|
|
63
|
+
console.log(`secureData`, secureData);
|
|
64
|
+
// clear
|
|
65
|
+
await saveSecure({ key });
|
|
60
66
|
```
|