hyperstorage-js 5.0.3 → 5.0.5
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 +11 -10
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# HyperStorage: Storage Manager for JavaScript/TypeScript
|
|
2
2
|
|
|
3
|
-
A lightweight wrapper for Storage interfaces (e.g., `localStorage` or `sessionStorage`) with **efficient caching** and **type-preserving serialization**.
|
|
3
|
+
A lightweight wrapper for Storage interfaces (e.g., `localStorage` or `sessionStorage`) with **efficient caching** and **type-preserving serialization**.
|
|
4
4
|
|
|
5
5
|
The biggest burdens of working with the **Storage API** is verifying values on every read, providing proper default values and only being able to store strings, having to `JSON.stringify()` and `JSON.parse()` manually everytime. This package eliminates all of this by providing a safe and automatic wrapper that handles everything at once. You can read/store numbers and objects without any extra steps and lose no performance.
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ The biggest burdens of working with the **Storage API** is verifying values on e
|
|
|
8
8
|
[](https://www.npmjs.com/package/hyperstorage-js)
|
|
9
9
|
[](https://www.jsdelivr.com/package/npm/hyperstorage-js)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
<br>
|
|
12
12
|
|
|
13
13
|
## Features
|
|
14
14
|
|
|
@@ -18,7 +18,7 @@ The biggest burdens of working with the **Storage API** is verifying values on e
|
|
|
18
18
|
- 🔒 **Optional encoding/decoding** hooks to obfuscate data.
|
|
19
19
|
- 🌐 **Custom storage**: works with any object implementing the standard Storage API. (`localStorage`, `sessionStorage`, ...)
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
<br>
|
|
22
22
|
|
|
23
23
|
## Installation
|
|
24
24
|
|
|
@@ -33,7 +33,7 @@ pnpm add hyperstorage-js
|
|
|
33
33
|
yarn add hyperstorage-js
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
<br>
|
|
37
37
|
|
|
38
38
|
## Constructor Syntax
|
|
39
39
|
|
|
@@ -51,7 +51,7 @@ class StorageManager<T> {
|
|
|
51
51
|
}
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
<br>
|
|
55
55
|
|
|
56
56
|
## Usage
|
|
57
57
|
|
|
@@ -130,7 +130,8 @@ console.log(sessionStore.storage) // Storage {sessionData: 'hN0IEUdoqmJ/', leng
|
|
|
130
130
|
|
|
131
131
|
```js
|
|
132
132
|
sessionStore.reset()
|
|
133
|
-
console.log(sessionStore.
|
|
133
|
+
console.log(sessionStore.defaultValue) // 'none'
|
|
134
|
+
console.log(sessionStore.value) // 'none'
|
|
134
135
|
```
|
|
135
136
|
|
|
136
137
|
### Removing Values
|
|
@@ -143,7 +144,7 @@ console.log(sessionStore.value) // undefined
|
|
|
143
144
|
console.log(sessionStore.storage) // Storage {length: 0}
|
|
144
145
|
```
|
|
145
146
|
|
|
146
|
-
|
|
147
|
+
<br>
|
|
147
148
|
|
|
148
149
|
## TypeScript Usage
|
|
149
150
|
|
|
@@ -166,7 +167,7 @@ const current = userStore.sync() // (method): Settings | undefined
|
|
|
166
167
|
console.log(current.theme) // { theme: 'light' }
|
|
167
168
|
```
|
|
168
169
|
|
|
169
|
-
|
|
170
|
+
<br>
|
|
170
171
|
|
|
171
172
|
## API
|
|
172
173
|
|
|
@@ -241,13 +242,13 @@ console.log(userStore.value) // { theme: 'blue' }
|
|
|
241
242
|
console.log(userStore.storage) // Storage {userSettings: '\x00{"theme":"blue"}', length: 1}
|
|
242
243
|
```
|
|
243
244
|
|
|
244
|
-
|
|
245
|
+
<br>
|
|
245
246
|
|
|
246
247
|
## Source
|
|
247
248
|
|
|
248
249
|
[GitHub Repository](https://github.com/Khoeckman/HyperStorage)
|
|
249
250
|
|
|
250
|
-
|
|
251
|
+
<br>
|
|
251
252
|
|
|
252
253
|
## License
|
|
253
254
|
|
package/dist/index.cjs
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
class HyperStorage {
|
|
11
11
|
/** Version of the library, injected via Rollup replace plugin. */
|
|
12
|
-
static version = "5.0.
|
|
12
|
+
static version = "5.0.5";
|
|
13
13
|
/** Key name under which the data is stored. */
|
|
14
14
|
itemName;
|
|
15
15
|
/** Default value used when the key does not exist in storage. */
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
class HyperStorage {
|
|
9
9
|
/** Version of the library, injected via Rollup replace plugin. */
|
|
10
|
-
static version = "5.0.
|
|
10
|
+
static version = "5.0.5";
|
|
11
11
|
/** Key name under which the data is stored. */
|
|
12
12
|
itemName;
|
|
13
13
|
/** Default value used when the key does not exist in storage. */
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).StorageManager=t()}(this,function(){"use strict";return class{static version="5.0.
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).StorageManager=t()}(this,function(){"use strict";return class{static version="5.0.5";itemName;defaultValue;encodeFn;decodeFn;storage;#e;constructor(e,t,i={}){const{encodeFn:n,decodeFn:s,storage:o=window.localStorage}=i;if("string"!=typeof e)throw new TypeError("itemName is not a string");if(this.itemName=e,this.defaultValue=t,n&&"function"!=typeof n)throw new TypeError("encodeFn is defined but is not a function");if(this.encodeFn=n||(e=>e),s&&"function"!=typeof s)throw new TypeError("decodeFn is defined but is not a function");if(this.decodeFn=s||(e=>e),!(o instanceof Storage))throw new TypeError("storage must be an instance of Storage");this.storage=o,this.sync()}set value(e){let t;this.#e=e,t="string"==typeof e?"\0"===e[0]?"\0"+e:e:void 0===e||"number"==typeof e&&(isNaN(e)||e===1/0||e===-1/0)?String(e):"\0"+JSON.stringify(e),this.storage.setItem(this.itemName,this.encodeFn(t))}get value(){return this.#e??this.defaultValue}set(e){return this.value=e(this.value)}sync(e=this.decodeFn){let t=this.storage.getItem(this.itemName);if("string"!=typeof t)return this.reset();try{t=e(t)}catch(e){return console.error(e),this.reset()}return"\0"!==t[0]?this.value=t:(t=t.slice(1),"\0"===t[0]?this.value=t:this.value="undefined"===t?void 0:"NaN"===t?NaN:"Infinity"===t?1/0:"-Infinity"===t?-1/0:JSON.parse(t))}reset(){return this.value=this.defaultValue}remove(){this.#e=void 0,this.storage.removeItem(this.itemName)}clear(){this.#e=void 0,this.storage.clear()}isDefault(){return this.#e===this.defaultValue}}});
|
package/package.json
CHANGED