@alwatr/local-storage 7.0.9 → 8.0.0
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/dist/main.js +5 -0
- package/dist/main.js.map +11 -0
- package/package.json +12 -14
- package/src/facade.ts +28 -0
- package/src/local-storage.provider.ts +152 -0
- package/src/main.ts +3 -0
- package/src/type.ts +18 -0
- package/CHANGELOG.md +0 -484
- package/dist/main.cjs +0 -3
- package/dist/main.cjs.map +0 -7
- package/dist/main.mjs +0 -3
- package/dist/main.mjs.map +0 -7
package/dist/main.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/* 📦 @alwatr/local-storage v8.0.0 */
|
|
2
|
+
import{createLogger as z}from"@alwatr/logger";class j{static version="8.0.0";key__;logger_;constructor(x){this.logger_=z(`local-storage-provider: ${x.name}, v: ${x.schemaVersion}`),this.logger_.logMethodArgs?.("constructor",{config:x}),this.key__=j.getKey(x),j.clearPreviousStorageVersions(x)}static getKey(x){return`${x.name}.v${x.schemaVersion}`}static clearPreviousStorageVersions(x){if(x.schemaVersion<1)return;for(let b=0;b<x.schemaVersion;b++){let q=j.getKey({name:x.name,schemaVersion:b});localStorage.removeItem(q)}}static has(x){let b=j.getKey(x);return localStorage.getItem(b)!==null}has(){return localStorage.getItem(this.key__)!==null}read(){let x=null;try{x=localStorage.getItem(this.key__)}catch(b){this.logger_.error("read","read_local_storage_error",{err:b})}if(!x)return this.logger_.logMethod?.("read//no_value"),null;try{let b=JSON.parse(x);return this.logger_.logMethodFull?.("read//value",void 0,{parsedValue:b}),b}catch(b){return this.logger_.error("read","read_parse_error",{err:b}),null}}write(x){this.logger_.logMethodArgs?.("write",{value:x});let b;try{b=JSON.stringify(x)}catch(q){throw this.logger_.error("write","write_stringify_error",{err:q}),Error("write_stringify_error")}try{localStorage.setItem(this.key__,b)}catch(q){this.logger_.error("write","write_local_storage_error",{err:q})}}remove(){localStorage.removeItem(this.key__)}}function E(x){return new j(x)}export{E as createLocalStorageProvider,j as LocalStorageProvider};
|
|
3
|
+
|
|
4
|
+
//# debugId=4B65E5CEBC18851764756E2164756E21
|
|
5
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/local-storage.provider.ts", "../src/facade.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import {createLogger} from '@alwatr/logger';\n\nimport type {LocalStorageProviderConfig} from './type.js';\n\n/**\n * A provider class for managing a specific, versioned item in localStorage.\n * It encapsulates the logic for key generation, serialization, and migration.\n *\n * @example\n * ```typescript\n * const userSettings = new LocalStorageProvider({\n * name: 'user-settings',\n * version: 1\n * });\n *\n * // Write new settings\n * userSettings.write({ theme: 'dark', notifications: false });\n *\n * // Read the current settings\n * const currentSettings = userSettings.read();\n * console.log(currentSettings); // { theme: 'dark', notifications: false }\n * ```\n */\nexport class LocalStorageProvider<T extends JsonValue> {\n public static readonly version = __package_version__;\n\n private readonly key__: string;\n protected readonly logger_;\n\n constructor(config: LocalStorageProviderConfig) {\n this.logger_ = createLogger(`local-storage-provider: ${config.name}, v: ${config.schemaVersion}`);\n this.logger_.logMethodArgs?.('constructor', {config});\n this.key__ = LocalStorageProvider.getKey(config);\n LocalStorageProvider.clearPreviousStorageVersions(config);\n }\n\n /**\n * Generates the versioned storage key.\n * @param meta - An object containing the name and schemaVersion.\n * @returns The versioned key string.\n */\n public static getKey(config: LocalStorageProviderConfig): string {\n return `${config.name}.v${config.schemaVersion}`;\n }\n\n /**\n * Manages data migration by removing all previous versions of the item.\n */\n public static clearPreviousStorageVersions(config: LocalStorageProviderConfig): void {\n if (config.schemaVersion < 1) return;\n\n // Iterate from v1 up to the version just before the current one and remove them.\n for (let i = 0; i < config.schemaVersion; i++) {\n const oldKey = LocalStorageProvider.getKey({name: config.name, schemaVersion: i});\n localStorage.removeItem(oldKey);\n }\n }\n\n /**\n * Checks if a versioned item exists in localStorage for the given configuration.\n * This static method allows checking for the existence of a specific versioned item\n * without instantiating the provider.\n *\n * @param config - The configuration object containing the name and schemaVersion.\n * @returns `true` if the item exists in localStorage, otherwise `false`.\n *\n * @example\n * ```typescript\n * const exists = LocalStorageProvider.has({ name: 'user-form', schemaVersion: 1 });\n * ```\n */\n public static has(config: LocalStorageProviderConfig): boolean {\n const key = LocalStorageProvider.getKey(config);\n return localStorage.getItem(key) !== null;\n }\n\n /**\n * Checks if the current versioned item exists in localStorage.\n *\n * @returns `true` if the item exists in localStorage, otherwise `false`.\n *\n * @example\n * ```typescript\n * const provider = new LocalStorageProvider({ name: 'profile', schemaVersion: 2 });\n * if (provider.has()) {\n * // Item exists\n * }\n * ```\n */\n public has(): boolean {\n return localStorage.getItem(this.key__) !== null;\n }\n\n /**\n * Reads and parses the value from localStorage.\n * If the item doesn't exist or is invalid JSON, returns null.\n */\n public read(): T | null {\n let value: string | null = null;\n\n try {\n value = localStorage.getItem(this.key__);\n }\n catch (err) {\n this.logger_.error('read', 'read_local_storage_error', {err});\n }\n\n if (!value) {\n this.logger_.logMethod?.('read//no_value');\n return null;\n }\n\n try {\n const parsedValue = JSON.parse(value) as T;\n this.logger_.logMethodFull?.('read//value', undefined, {parsedValue});\n return parsedValue;\n }\n catch (err) {\n this.logger_.error('read', 'read_parse_error', {err});\n return null;\n }\n }\n\n /**\n * Serializes and writes a value to localStorage.\n */\n public write(value: T): void {\n this.logger_.logMethodArgs?.('write', {value});\n let valueStr: string;\n try {\n valueStr = JSON.stringify(value);\n }\n catch (err) {\n this.logger_.error('write', 'write_stringify_error', {err});\n throw new Error('write_stringify_error');\n }\n\n try {\n localStorage.setItem(this.key__, valueStr);\n }\n catch (err) {\n this.logger_.error('write', 'write_local_storage_error', {err});\n }\n }\n\n /**\n * Removes the item from localStorage.\n */\n public remove(): void {\n localStorage.removeItem(this.key__);\n }\n}\n",
|
|
6
|
+
"import {LocalStorageProvider} from './local-storage.provider.js';\n\nimport type {LocalStorageProviderConfig} from './type.js';\n\n/**\n * Factory function to create a new LocalStorageProvider.\n *\n * @param config - The configuration for the provider.\n * @returns An instance of LocalStorageProvider.\n *\n * @example\n * ```typescript\n * const userSettings = createLocalStorageProvider({\n * name: 'user-settings',\n * schemaVersion: 1\n * });\n *\n * // Write new settings\n * userSettings.write({ theme: 'dark', notifications: false });\n *\n * // Read the current settings\n * const currentSettings = userSettings.read();\n * console.log(currentSettings); // { theme: 'dark', notifications: false }\n * ```\n */\nexport function createLocalStorageProvider<T extends JsonValue>(config: LocalStorageProviderConfig): LocalStorageProvider<T> {\n return new LocalStorageProvider<T>(config);\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";AAAA,uBAAQ,uBAuBD,MAAM,CAA0C,OAC9B,SAAU,QAEhB,MACE,QAEnB,WAAW,CAAC,EAAoC,CAC9C,KAAK,QAAU,EAAa,2BAA2B,EAAO,YAAY,EAAO,eAAe,EAChG,KAAK,QAAQ,gBAAgB,cAAe,CAAC,QAAM,CAAC,EACpD,KAAK,MAAQ,EAAqB,OAAO,CAAM,EAC/C,EAAqB,6BAA6B,CAAM,QAQ5C,OAAM,CAAC,EAA4C,CAC/D,MAAO,GAAG,EAAO,SAAS,EAAO,sBAMrB,6BAA4B,CAAC,EAA0C,CACnF,GAAI,EAAO,cAAgB,EAAG,OAG9B,QAAS,EAAI,EAAG,EAAI,EAAO,cAAe,IAAK,CAC7C,IAAM,EAAS,EAAqB,OAAO,CAAC,KAAM,EAAO,KAAM,cAAe,CAAC,CAAC,EAChF,aAAa,WAAW,CAAM,SAiBpB,IAAG,CAAC,EAA6C,CAC7D,IAAM,EAAM,EAAqB,OAAO,CAAM,EAC9C,OAAO,aAAa,QAAQ,CAAG,IAAM,KAgBhC,GAAG,EAAY,CACpB,OAAO,aAAa,QAAQ,KAAK,KAAK,IAAM,KAOvC,IAAI,EAAa,CACtB,IAAI,EAAuB,KAE3B,GAAI,CACF,EAAQ,aAAa,QAAQ,KAAK,KAAK,EAEzC,MAAO,EAAK,CACV,KAAK,QAAQ,MAAM,OAAQ,2BAA4B,CAAC,KAAG,CAAC,EAG9D,GAAI,CAAC,EAEH,OADA,KAAK,QAAQ,YAAY,gBAAgB,EAClC,KAGT,GAAI,CACF,IAAM,EAAc,KAAK,MAAM,CAAK,EAEpC,OADA,KAAK,QAAQ,gBAAgB,cAAe,OAAW,CAAC,aAAW,CAAC,EAC7D,EAET,MAAO,EAAK,CAEV,OADA,KAAK,QAAQ,MAAM,OAAQ,mBAAoB,CAAC,KAAG,CAAC,EAC7C,MAOJ,KAAK,CAAC,EAAgB,CAC3B,KAAK,QAAQ,gBAAgB,QAAS,CAAC,OAAK,CAAC,EAC7C,IAAI,EACJ,GAAI,CACF,EAAW,KAAK,UAAU,CAAK,EAEjC,MAAO,EAAK,CAEV,MADA,KAAK,QAAQ,MAAM,QAAS,wBAAyB,CAAC,KAAG,CAAC,EAChD,MAAM,uBAAuB,EAGzC,GAAI,CACF,aAAa,QAAQ,KAAK,MAAO,CAAQ,EAE3C,MAAO,EAAK,CACV,KAAK,QAAQ,MAAM,QAAS,4BAA6B,CAAC,KAAG,CAAC,GAO3D,MAAM,EAAS,CACpB,aAAa,WAAW,KAAK,KAAK,EAEtC,CC9HO,SAAS,CAA+C,CAAC,EAA6D,CAC3H,OAAO,IAAI,EAAwB,CAAM",
|
|
9
|
+
"debugId": "4B65E5CEBC18851764756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/local-storage",
|
|
3
3
|
"description": "A modern, simple, and robust solution for managing versioned JSON objects in the browser's `localStorage`. This package provides a clean, class-based API with a factory function to ensure your application's data persistence is safe, maintainable, and future-proof.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "8.0.0",
|
|
5
5
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
|
|
6
6
|
"bugs": "https://github.com/Alwatr/nanolib/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@alwatr/logger": "
|
|
8
|
+
"@alwatr/logger": "7.0.0"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@alwatr/nano-build": "
|
|
12
|
-
"@alwatr/prettier-config": "
|
|
13
|
-
"@alwatr/tsconfig-base": "
|
|
14
|
-
"@alwatr/type-helper": "
|
|
11
|
+
"@alwatr/nano-build": "7.0.0",
|
|
12
|
+
"@alwatr/prettier-config": "7.0.0",
|
|
13
|
+
"@alwatr/tsconfig-base": "7.0.0",
|
|
14
|
+
"@alwatr/type-helper": "8.0.0",
|
|
15
15
|
"typescript": "^5.9.3"
|
|
16
16
|
},
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
19
|
"types": "./dist/main.d.ts",
|
|
20
|
-
"
|
|
21
|
-
"require": "./dist/main.cjs"
|
|
20
|
+
"default": "./dist/main.js"
|
|
22
21
|
}
|
|
23
22
|
},
|
|
24
23
|
"files": [
|
|
25
|
-
"**/*.{js,mjs,cjs,map,d.ts,html,
|
|
24
|
+
"**/*.{js,mjs,cjs,ts,map,d.ts,html,LEGAL.txt}",
|
|
25
|
+
"README.md",
|
|
26
26
|
"LICENSE",
|
|
27
27
|
"!demo/**/*",
|
|
28
28
|
"!**/*.test.js"
|
|
@@ -47,8 +47,6 @@
|
|
|
47
47
|
"versioning"
|
|
48
48
|
],
|
|
49
49
|
"license": "MPL-2.0",
|
|
50
|
-
"main": "./dist/main.cjs",
|
|
51
|
-
"module": "./dist/main.mjs",
|
|
52
50
|
"prettier": "@alwatr/prettier-config",
|
|
53
51
|
"publishConfig": {
|
|
54
52
|
"access": "public"
|
|
@@ -61,12 +59,12 @@
|
|
|
61
59
|
"scripts": {
|
|
62
60
|
"b": "bun run build",
|
|
63
61
|
"build": "bun run build:ts && bun run build:es",
|
|
64
|
-
"build:es": "nano-build --preset=module",
|
|
62
|
+
"build:es": "nano-build --preset=module src/main.ts",
|
|
65
63
|
"build:ts": "tsc --build",
|
|
66
64
|
"c": "bun run clean",
|
|
67
65
|
"cb": "bun run clean && bun run build",
|
|
68
66
|
"clean": "rm -rfv dist *.tsbuildinfo",
|
|
69
|
-
"d": "bun run build:es && bun
|
|
67
|
+
"d": "bun run build:es && bun",
|
|
70
68
|
"w": "bun run watch",
|
|
71
69
|
"watch": "bun run watch:ts & bun run watch:es",
|
|
72
70
|
"watch:es": "bun run build:es --watch",
|
|
@@ -75,5 +73,5 @@
|
|
|
75
73
|
"sideEffects": false,
|
|
76
74
|
"type": "module",
|
|
77
75
|
"types": "./dist/main.d.ts",
|
|
78
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "056102a1c8a563bbae8a290b6830450f467322a3"
|
|
79
77
|
}
|
package/src/facade.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {LocalStorageProvider} from './local-storage.provider.js';
|
|
2
|
+
|
|
3
|
+
import type {LocalStorageProviderConfig} from './type.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Factory function to create a new LocalStorageProvider.
|
|
7
|
+
*
|
|
8
|
+
* @param config - The configuration for the provider.
|
|
9
|
+
* @returns An instance of LocalStorageProvider.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const userSettings = createLocalStorageProvider({
|
|
14
|
+
* name: 'user-settings',
|
|
15
|
+
* schemaVersion: 1
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // Write new settings
|
|
19
|
+
* userSettings.write({ theme: 'dark', notifications: false });
|
|
20
|
+
*
|
|
21
|
+
* // Read the current settings
|
|
22
|
+
* const currentSettings = userSettings.read();
|
|
23
|
+
* console.log(currentSettings); // { theme: 'dark', notifications: false }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function createLocalStorageProvider<T extends JsonValue>(config: LocalStorageProviderConfig): LocalStorageProvider<T> {
|
|
27
|
+
return new LocalStorageProvider<T>(config);
|
|
28
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import {createLogger} from '@alwatr/logger';
|
|
2
|
+
|
|
3
|
+
import type {LocalStorageProviderConfig} from './type.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A provider class for managing a specific, versioned item in localStorage.
|
|
7
|
+
* It encapsulates the logic for key generation, serialization, and migration.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const userSettings = new LocalStorageProvider({
|
|
12
|
+
* name: 'user-settings',
|
|
13
|
+
* version: 1
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // Write new settings
|
|
17
|
+
* userSettings.write({ theme: 'dark', notifications: false });
|
|
18
|
+
*
|
|
19
|
+
* // Read the current settings
|
|
20
|
+
* const currentSettings = userSettings.read();
|
|
21
|
+
* console.log(currentSettings); // { theme: 'dark', notifications: false }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export class LocalStorageProvider<T extends JsonValue> {
|
|
25
|
+
public static readonly version = __package_version__;
|
|
26
|
+
|
|
27
|
+
private readonly key__: string;
|
|
28
|
+
protected readonly logger_;
|
|
29
|
+
|
|
30
|
+
constructor(config: LocalStorageProviderConfig) {
|
|
31
|
+
this.logger_ = createLogger(`local-storage-provider: ${config.name}, v: ${config.schemaVersion}`);
|
|
32
|
+
this.logger_.logMethodArgs?.('constructor', {config});
|
|
33
|
+
this.key__ = LocalStorageProvider.getKey(config);
|
|
34
|
+
LocalStorageProvider.clearPreviousStorageVersions(config);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Generates the versioned storage key.
|
|
39
|
+
* @param meta - An object containing the name and schemaVersion.
|
|
40
|
+
* @returns The versioned key string.
|
|
41
|
+
*/
|
|
42
|
+
public static getKey(config: LocalStorageProviderConfig): string {
|
|
43
|
+
return `${config.name}.v${config.schemaVersion}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Manages data migration by removing all previous versions of the item.
|
|
48
|
+
*/
|
|
49
|
+
public static clearPreviousStorageVersions(config: LocalStorageProviderConfig): void {
|
|
50
|
+
if (config.schemaVersion < 1) return;
|
|
51
|
+
|
|
52
|
+
// Iterate from v1 up to the version just before the current one and remove them.
|
|
53
|
+
for (let i = 0; i < config.schemaVersion; i++) {
|
|
54
|
+
const oldKey = LocalStorageProvider.getKey({name: config.name, schemaVersion: i});
|
|
55
|
+
localStorage.removeItem(oldKey);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Checks if a versioned item exists in localStorage for the given configuration.
|
|
61
|
+
* This static method allows checking for the existence of a specific versioned item
|
|
62
|
+
* without instantiating the provider.
|
|
63
|
+
*
|
|
64
|
+
* @param config - The configuration object containing the name and schemaVersion.
|
|
65
|
+
* @returns `true` if the item exists in localStorage, otherwise `false`.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const exists = LocalStorageProvider.has({ name: 'user-form', schemaVersion: 1 });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
public static has(config: LocalStorageProviderConfig): boolean {
|
|
73
|
+
const key = LocalStorageProvider.getKey(config);
|
|
74
|
+
return localStorage.getItem(key) !== null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Checks if the current versioned item exists in localStorage.
|
|
79
|
+
*
|
|
80
|
+
* @returns `true` if the item exists in localStorage, otherwise `false`.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const provider = new LocalStorageProvider({ name: 'profile', schemaVersion: 2 });
|
|
85
|
+
* if (provider.has()) {
|
|
86
|
+
* // Item exists
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
public has(): boolean {
|
|
91
|
+
return localStorage.getItem(this.key__) !== null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Reads and parses the value from localStorage.
|
|
96
|
+
* If the item doesn't exist or is invalid JSON, returns null.
|
|
97
|
+
*/
|
|
98
|
+
public read(): T | null {
|
|
99
|
+
let value: string | null = null;
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
value = localStorage.getItem(this.key__);
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
this.logger_.error('read', 'read_local_storage_error', {err});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!value) {
|
|
109
|
+
this.logger_.logMethod?.('read//no_value');
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
const parsedValue = JSON.parse(value) as T;
|
|
115
|
+
this.logger_.logMethodFull?.('read//value', undefined, {parsedValue});
|
|
116
|
+
return parsedValue;
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
this.logger_.error('read', 'read_parse_error', {err});
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Serializes and writes a value to localStorage.
|
|
126
|
+
*/
|
|
127
|
+
public write(value: T): void {
|
|
128
|
+
this.logger_.logMethodArgs?.('write', {value});
|
|
129
|
+
let valueStr: string;
|
|
130
|
+
try {
|
|
131
|
+
valueStr = JSON.stringify(value);
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
this.logger_.error('write', 'write_stringify_error', {err});
|
|
135
|
+
throw new Error('write_stringify_error');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
localStorage.setItem(this.key__, valueStr);
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
this.logger_.error('write', 'write_local_storage_error', {err});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Removes the item from localStorage.
|
|
148
|
+
*/
|
|
149
|
+
public remove(): void {
|
|
150
|
+
localStorage.removeItem(this.key__);
|
|
151
|
+
}
|
|
152
|
+
}
|
package/src/main.ts
ADDED
package/src/type.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type {} from '@alwatr/nano-build';
|
|
2
|
+
import type {} from '@alwatr/type-helper';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for a local storage provider.
|
|
6
|
+
*/
|
|
7
|
+
export interface LocalStorageProviderConfig {
|
|
8
|
+
/**
|
|
9
|
+
* The unique name for the storage item.
|
|
10
|
+
*/
|
|
11
|
+
name: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The version of the data structure.
|
|
15
|
+
* Start from 1 for production, 0 for development mode, and increment by 1 for each new data schema change.
|
|
16
|
+
*/
|
|
17
|
+
schemaVersion: number;
|
|
18
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,484 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
## [7.0.9](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.8...@alwatr/local-storage@7.0.9) (2026-03-16)
|
|
7
|
-
|
|
8
|
-
### 🔨 Code Refactoring
|
|
9
|
-
|
|
10
|
-
* migrate build scripts from yarn to bun across multiple packages ([d90e962](https://github.com/Alwatr/nanolib/commit/d90e962f15e5c951e191d5f02341279b6472abc3))
|
|
11
|
-
|
|
12
|
-
## [7.0.8](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.7...@alwatr/local-storage@7.0.8) (2026-02-18)
|
|
13
|
-
|
|
14
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
15
|
-
|
|
16
|
-
## [7.0.7](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.6...@alwatr/local-storage@7.0.7) (2025-12-23)
|
|
17
|
-
|
|
18
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
19
|
-
|
|
20
|
-
## [7.0.6](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.5...@alwatr/local-storage@7.0.6) (2025-12-13)
|
|
21
|
-
|
|
22
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
23
|
-
|
|
24
|
-
## [7.0.5](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.4...@alwatr/local-storage@7.0.5) (2025-12-10)
|
|
25
|
-
|
|
26
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
27
|
-
|
|
28
|
-
## [7.0.4](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.3...@alwatr/local-storage@7.0.4) (2025-11-18)
|
|
29
|
-
|
|
30
|
-
### 🔨 Code Refactoring
|
|
31
|
-
|
|
32
|
-
* remove unnecessary type declarations from tsconfig.json files ([89bcc7d](https://github.com/Alwatr/nanolib/commit/89bcc7db839807110b80f8ba34414ea9734d9c75))
|
|
33
|
-
|
|
34
|
-
## [7.0.3](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.2...@alwatr/local-storage@7.0.3) (2025-11-15)
|
|
35
|
-
|
|
36
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
37
|
-
|
|
38
|
-
## [7.0.2](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.1...@alwatr/local-storage@7.0.2) (2025-11-15)
|
|
39
|
-
|
|
40
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
41
|
-
|
|
42
|
-
## [7.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.0...@alwatr/local-storage@7.0.1) (2025-11-04)
|
|
43
|
-
|
|
44
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
45
|
-
|
|
46
|
-
## [7.0.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.3.4...@alwatr/local-storage@7.0.0) (2025-10-06)
|
|
47
|
-
|
|
48
|
-
### ⚠ BREAKING CHANGES
|
|
49
|
-
|
|
50
|
-
* api changed and defaultValue removed
|
|
51
|
-
|
|
52
|
-
### ✨ Features
|
|
53
|
-
|
|
54
|
-
* implement static method to check existence of versioned item in localStorage ([c622595](https://github.com/Alwatr/nanolib/commit/c622595bcd793746133733b22c7704463d50314d))
|
|
55
|
-
|
|
56
|
-
### 🔨 Code Refactoring
|
|
57
|
-
|
|
58
|
-
* enhance documentation for LocalStorageProviderConfig interface ([11407cd](https://github.com/Alwatr/nanolib/commit/11407cd80ee9def06bcb21c6bb426e92caa7d702))
|
|
59
|
-
* improve documentation for LocalStorageProvider's static methods ([145ac5c](https://github.com/Alwatr/nanolib/commit/145ac5c0d947c9d3f1e91a25e5ca749e0e56d85b))
|
|
60
|
-
* simplify LocalStorageProvider configuration and remove unused types ([b839299](https://github.com/Alwatr/nanolib/commit/b839299d3950f1662773fd8f3a0e6b2189c3d140))
|
|
61
|
-
|
|
62
|
-
### 🔗 Dependencies update
|
|
63
|
-
|
|
64
|
-
* bump the npm-dependencies group with 4 updates ([9825815](https://github.com/Alwatr/nanolib/commit/982581552bbb4b97dca52af5e93a80937f0c3109))
|
|
65
|
-
|
|
66
|
-
## [6.3.4](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.3.3...@alwatr/local-storage@6.3.4) (2025-09-27)
|
|
67
|
-
|
|
68
|
-
### 🧹 Miscellaneous Chores
|
|
69
|
-
|
|
70
|
-
* exclude test files from package distribution ([86f4f2f](https://github.com/Alwatr/nanolib/commit/86f4f2f5985845c5cf3a3a9398de7b2f98ce53e7))
|
|
71
|
-
|
|
72
|
-
## [6.3.3](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.3.2...@alwatr/local-storage@6.3.3) (2025-09-22)
|
|
73
|
-
|
|
74
|
-
### 🐛 Bug Fixes
|
|
75
|
-
|
|
76
|
-
* add constraint to createLocalStorageProvider generic type to extend JsonValue ([198ca49](https://github.com/Alwatr/nanolib/commit/198ca49042780aff15d3979bea3951bf094b3b15))
|
|
77
|
-
* add generic type constraint to LocalStorageProviderConfig to extend JsonValue ([9b97692](https://github.com/Alwatr/nanolib/commit/9b9769254613aac6ad94a0c2dd885c44e63b6ed2))
|
|
78
|
-
* refine generic type constraints in LocalStorageProvider to extend JsonValue ([6a05c12](https://github.com/Alwatr/nanolib/commit/6a05c12583326dbea8784f79f7c559b9a31d3cef))
|
|
79
|
-
* rename convertDataType method to convertDataType__ for consistency ([83ccb56](https://github.com/Alwatr/nanolib/commit/83ccb56a9ff95ba0c4e8e6a77cb67a010d60701a))
|
|
80
|
-
|
|
81
|
-
## [6.3.2](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.3.1...@alwatr/local-storage@6.3.2) (2025-09-22)
|
|
82
|
-
|
|
83
|
-
### 🐛 Bug Fixes
|
|
84
|
-
|
|
85
|
-
* remove unnecessary constraint from createLocalStorageProvider generic type ([960467f](https://github.com/Alwatr/nanolib/commit/960467fd161a80bf4e90cb3070054cee58182bfb))
|
|
86
|
-
|
|
87
|
-
## [6.3.1](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.3.0...@alwatr/local-storage@6.3.1) (2025-09-22)
|
|
88
|
-
|
|
89
|
-
### 🐛 Bug Fixes
|
|
90
|
-
|
|
91
|
-
* update convertDataType method to accept both raw and serialized data types ([1ca0256](https://github.com/Alwatr/nanolib/commit/1ca02563d0ce27f0b90572563eb8afb109ae2f07))
|
|
92
|
-
|
|
93
|
-
## [6.3.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.2.0...@alwatr/local-storage@6.3.0) (2025-09-22)
|
|
94
|
-
|
|
95
|
-
### ✨ Features
|
|
96
|
-
|
|
97
|
-
* make convertDataType public access ([f8b08e1](https://github.com/Alwatr/nanolib/commit/f8b08e1c81b97176f1dc1777434a17126651fdd3))
|
|
98
|
-
|
|
99
|
-
## [6.2.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.8...@alwatr/local-storage@6.2.0) (2025-09-22)
|
|
100
|
-
|
|
101
|
-
### ✨ Features
|
|
102
|
-
|
|
103
|
-
* move createLocalStorageProvider function to facade.ts and clean up main.ts ([5dd6164](https://github.com/Alwatr/nanolib/commit/5dd6164f908de9a6ceec70dd19cc6f67d8c22ad6))
|
|
104
|
-
|
|
105
|
-
### 🐛 Bug Fixes
|
|
106
|
-
|
|
107
|
-
* correct parameter name in createLocalStorageProvider example ([bc894a3](https://github.com/Alwatr/nanolib/commit/bc894a36e3d033244b81063dccb1dfedb86a0082))
|
|
108
|
-
* improve error handling in read and write methods of LocalStorageProvider ([845f37c](https://github.com/Alwatr/nanolib/commit/845f37cddd14f54a5bb50c3d902c7221d8fc9aef))
|
|
109
|
-
* refactor LocalStorageProvider constructor and methods for improved clarity and error handling ([da2c5b4](https://github.com/Alwatr/nanolib/commit/da2c5b476ff0184e476be2e2a8af87ba6364bfbd))
|
|
110
|
-
* update error logging in convertDataType__ method for improved clarity ([3e395e5](https://github.com/Alwatr/nanolib/commit/3e395e529aae1dcac5ad0b431070761b23e2d935))
|
|
111
|
-
* update return types in LocalStorageProvider methods for better type safety ([0abcb41](https://github.com/Alwatr/nanolib/commit/0abcb41b9440324a70e2b782b0643bb8a51e47c6))
|
|
112
|
-
|
|
113
|
-
## [6.1.8](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.7...@alwatr/local-storage@6.1.8) (2025-09-22)
|
|
114
|
-
|
|
115
|
-
### 🐛 Bug Fixes
|
|
116
|
-
|
|
117
|
-
* update version references to schemaVersion in README and code ([c51c115](https://github.com/Alwatr/nanolib/commit/c51c115ea431bba10a248fe6e4e37dcdff6da059))
|
|
118
|
-
|
|
119
|
-
## [6.1.7](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.6...@alwatr/local-storage@6.1.7) (2025-09-21)
|
|
120
|
-
|
|
121
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
122
|
-
|
|
123
|
-
## [6.1.6](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.5...@alwatr/local-storage@6.1.6) (2025-09-20)
|
|
124
|
-
|
|
125
|
-
### 🐛 Bug Fixes
|
|
126
|
-
|
|
127
|
-
* add sideEffects property to package.json files for better tree-shaking ([c7b9e74](https://github.com/Alwatr/nanolib/commit/c7b9e74e1920c8e35b438742de61883ca62da58c))
|
|
128
|
-
* add sideEffects property to package.json files for better tree-shaking ([e8402c4](https://github.com/Alwatr/nanolib/commit/e8402c481a14a1f807a37aaa862a936713d26176))
|
|
129
|
-
|
|
130
|
-
### 🧹 Miscellaneous Chores
|
|
131
|
-
|
|
132
|
-
* remove duplicate sideEffects property from multiple package.json files ([b123f86](https://github.com/Alwatr/nanolib/commit/b123f86be81481de2314aae9bb2eeb629743d24c))
|
|
133
|
-
|
|
134
|
-
## [6.1.5](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.4...@alwatr/local-storage@6.1.5) (2025-09-19)
|
|
135
|
-
|
|
136
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
137
|
-
|
|
138
|
-
## [6.1.4](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.3...@alwatr/local-storage@6.1.4) (2025-09-19)
|
|
139
|
-
|
|
140
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
141
|
-
|
|
142
|
-
## [6.1.3](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.2...@alwatr/local-storage@6.1.3) (2025-09-15)
|
|
143
|
-
|
|
144
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
145
|
-
|
|
146
|
-
## [6.1.2](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.1...@alwatr/local-storage@6.1.2) (2025-09-14)
|
|
147
|
-
|
|
148
|
-
### 🔨 Code Refactoring
|
|
149
|
-
|
|
150
|
-
* **package:** update keywords in package.json for debounce, local-storage, and synapse packages ([09c9cca](https://github.com/Alwatr/nanolib/commit/09c9cca3cd600e9ffaf600fb1926c0ee884a1aa8))
|
|
151
|
-
* remove types from tsconfig.json and adjust imports in type.ts ([ad2d3b3](https://github.com/Alwatr/nanolib/commit/ad2d3b3927db7bf3b5b54dcac5cdae751d00eb4a))
|
|
152
|
-
|
|
153
|
-
## [6.1.1](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.0...@alwatr/local-storage@6.1.1) (2025-09-13)
|
|
154
|
-
|
|
155
|
-
### 🐛 Bug Fixes
|
|
156
|
-
|
|
157
|
-
* remove duplicate "types" entry in package.json ([86dce1a](https://github.com/Alwatr/nanolib/commit/86dce1a88ad3c605fe03f335d4f4813aad573ed8))
|
|
158
|
-
|
|
159
|
-
## [6.1.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.0.0...@alwatr/local-storage@6.1.0) (2025-09-13)
|
|
160
|
-
|
|
161
|
-
### ✨ Features
|
|
162
|
-
|
|
163
|
-
* **local-storage:** add static version property to LocalStorageProvider ([267b4b6](https://github.com/Alwatr/nanolib/commit/267b4b6d5a7d4fb14fbea7fe3b5c11611c838170))
|
|
164
|
-
|
|
165
|
-
### 🧹 Miscellaneous Chores
|
|
166
|
-
|
|
167
|
-
* remove package-tracer dependency and related code from fetch package ([96fe4e9](https://github.com/Alwatr/nanolib/commit/96fe4e9552a205f218ceed187c55e4e904a07089))
|
|
168
|
-
* remove package-tracer dependency and related code from LocalStorageProvider ([84e2fc1](https://github.com/Alwatr/nanolib/commit/84e2fc1894a09908119b5456804a6404e5cdcbd3))
|
|
169
|
-
|
|
170
|
-
## [6.0.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.10...@alwatr/local-storage@6.0.0) (2025-09-13)
|
|
171
|
-
|
|
172
|
-
### ⚠ BREAKING CHANGES
|
|
173
|
-
|
|
174
|
-
* **local-storage:** The provider's constructor config shape and public methods have changed.
|
|
175
|
-
Existing callers must be updated to the new API:
|
|
176
|
-
- Update imports/instantiation to use the new LocalStorageProvider<T>(config: LocalStorageProviderConfig<T>).
|
|
177
|
-
- Replace any old config fields / method names with the new ones (e.g. versioned key handling, defaultValue handling).
|
|
178
|
-
- Data migration behavior changed: previous-version keys are automatically removed when version > 1.
|
|
179
|
-
- Update call sites that relied on prior serialization, error handling, or return semantics.
|
|
180
|
-
|
|
181
|
-
Suggested migration steps:
|
|
182
|
-
1. Inspect the new LocalStorageProviderConfig<T> type and adapt object literal passed to the constructor.
|
|
183
|
-
2. Replace old read/write/remove calls with the new method names and signatures.
|
|
184
|
-
3. Ensure stored values match the new serialization expectations (JSON-serializable).
|
|
185
|
-
4. Run tests and rehydrate any persisted data if necessary (previous keys are removed for versions >1).
|
|
186
|
-
|
|
187
|
-
### ✨ Features
|
|
188
|
-
|
|
189
|
-
* **local-storage:** add factory function to create LocalStorageProvider with detailed documentation ([eb4a04d](https://github.com/Alwatr/nanolib/commit/eb4a04de84d69497e7489b756c172ed2b0af008d))
|
|
190
|
-
* **local-storage:** add static method to check existence of versioned items in localStorage ([8e05938](https://github.com/Alwatr/nanolib/commit/8e059382d085aa691f296b2267a372925868f974))
|
|
191
|
-
|
|
192
|
-
### 🐛 Bug Fixes
|
|
193
|
-
|
|
194
|
-
* **local-storage:** correct typo in writeDefault method name ([c0b05c0](https://github.com/Alwatr/nanolib/commit/c0b05c0417ec75e7d9bc57c224380f34472ec467))
|
|
195
|
-
* **local-storage:** simplify read method by removing type check for parsed value ([23826ef](https://github.com/Alwatr/nanolib/commit/23826ef70eb22e6f092ba2c6ce11c28b3628f2f2))
|
|
196
|
-
* **local-storage:** standardize key naming convention in LocalStorageProvider ([043cf27](https://github.com/Alwatr/nanolib/commit/043cf27881b840d5adeb79ea4a840a15ea23e262))
|
|
197
|
-
|
|
198
|
-
### 🔨 Code Refactoring
|
|
199
|
-
|
|
200
|
-
* **local-storage:** complete API rewrite for LocalStorageProvider ([29d01d8](https://github.com/Alwatr/nanolib/commit/29d01d84fbb3ed405ce46d1870d1a929de1c838c))
|
|
201
|
-
* **local-storage:** enhance logging in read and write methods for better error tracking ([2cbf404](https://github.com/Alwatr/nanolib/commit/2cbf4042fcef74de016fd1ae80f8263f9de5c610))
|
|
202
|
-
* **local-storage:** rename private key variable and update its initialization method ([e25a8ea](https://github.com/Alwatr/nanolib/commit/e25a8ea4a4b75aeac0702fc0a9ef39a5f441e54c))
|
|
203
|
-
* **local-storage:** update key generation method to static and enhance documentation ([e36fd53](https://github.com/Alwatr/nanolib/commit/e36fd5355ad4b7fa7b4e629568b9a878ae868c3e))
|
|
204
|
-
* **types:** reorganize StorageMeta and LocalStorageProviderConfig interfaces ([d3d001e](https://github.com/Alwatr/nanolib/commit/d3d001ef041ea59981551204d84bee7635cfc192))
|
|
205
|
-
|
|
206
|
-
### 🧹 Miscellaneous Chores
|
|
207
|
-
|
|
208
|
-
* add @jest/globals dependency for testing ([a024449](https://github.com/Alwatr/nanolib/commit/a024449366e6b4aa246603528dde6586dda3379e))
|
|
209
|
-
|
|
210
|
-
## [5.5.10](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.9...@alwatr/local-storage@5.5.10) (2025-09-09)
|
|
211
|
-
|
|
212
|
-
### 🧹 Miscellaneous Chores
|
|
213
|
-
|
|
214
|
-
* remove trailing newlines from contributing sections in README files ([e8ab1bc](https://github.com/Alwatr/nanolib/commit/e8ab1bc43e0addea5ccd4c897c2cec597cb9e15f))
|
|
215
|
-
|
|
216
|
-
## [5.5.9](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.8...@alwatr/local-storage@5.5.9) (2025-09-06)
|
|
217
|
-
|
|
218
|
-
### 🐛 Bug Fixes
|
|
219
|
-
|
|
220
|
-
* support json primitive values ([0af6a75](https://github.com/Alwatr/nanolib/commit/0af6a75881073a586d89666679b1c2e351f48224))
|
|
221
|
-
|
|
222
|
-
### 🔨 Code Refactoring
|
|
223
|
-
|
|
224
|
-
* update type definitions for getItem and setItem to use JsonValue for consistency ([140cd09](https://github.com/Alwatr/nanolib/commit/140cd09c4c4cdab480fd2263f387bf9385b497ef))
|
|
225
|
-
|
|
226
|
-
## [5.5.8](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.7...@alwatr/local-storage@5.5.8) (2025-09-05)
|
|
227
|
-
|
|
228
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
229
|
-
|
|
230
|
-
## [5.5.7](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.6...@alwatr/local-storage@5.5.7) (2025-09-01)
|
|
231
|
-
|
|
232
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
233
|
-
|
|
234
|
-
## [5.5.6](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.5...@alwatr/local-storage@5.5.6) (2025-08-23)
|
|
235
|
-
|
|
236
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
237
|
-
|
|
238
|
-
## [5.5.5](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.3...@alwatr/local-storage@5.5.5) (2025-08-23)
|
|
239
|
-
|
|
240
|
-
### 🐛 Bug Fixes
|
|
241
|
-
|
|
242
|
-
* update license from AGPL-3.0-only to MPL-2.0 ([d20968e](https://github.com/Alwatr/nanolib/commit/d20968e60cc89b1dcdf9b96507178da6ed562f55))
|
|
243
|
-
* update package versions in multiple package.json files ([7638b1c](https://github.com/Alwatr/nanolib/commit/7638b1cafee2b4e0f97db7a89ac9fba6384b9b10))
|
|
244
|
-
|
|
245
|
-
### 🔨 Code Refactoring
|
|
246
|
-
|
|
247
|
-
* Updated all package.json files in the project to change dependency version specifiers from "workspace:^" to "workspace:*" for consistency and to allow for more flexible version resolution. ([db6a4f7](https://github.com/Alwatr/nanolib/commit/db6a4f76deec2d1d8039978144e4bc51b6f1a0e3))
|
|
248
|
-
|
|
249
|
-
### 🧹 Miscellaneous Chores
|
|
250
|
-
|
|
251
|
-
* reformat all package.json files ([ceda45d](https://github.com/Alwatr/nanolib/commit/ceda45de186667790474f729cb4b161a5148ce19))
|
|
252
|
-
|
|
253
|
-
### 🔗 Dependencies update
|
|
254
|
-
|
|
255
|
-
* update TypeScript and Jest versions across all packages to improve compatibility and performance ([31baf36](https://github.com/Alwatr/nanolib/commit/31baf366101e92e27db66a21c849fb101f19be47))
|
|
256
|
-
|
|
257
|
-
## [5.5.4](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.3...@alwatr/local-storage@5.5.4) (2025-08-23)
|
|
258
|
-
|
|
259
|
-
### Code Refactoring
|
|
260
|
-
|
|
261
|
-
* Updated all package.json files in the project to change dependency version specifiers from "workspace:^" to "workspace:*" for consistency and to allow for more flexible version resolution. ([db6a4f7](https://github.com/Alwatr/nanolib/commit/db6a4f76deec2d1d8039978144e4bc51b6f1a0e3)) by @alimd
|
|
262
|
-
|
|
263
|
-
## <small>5.5.3 (2025-04-15)</small>
|
|
264
|
-
|
|
265
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
266
|
-
|
|
267
|
-
## [5.5.2](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.1...@alwatr/local-storage@5.5.2) (2025-04-01)
|
|
268
|
-
|
|
269
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
270
|
-
|
|
271
|
-
## [5.5.1](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.0...@alwatr/local-storage@5.5.1) (2025-03-18)
|
|
272
|
-
|
|
273
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
274
|
-
|
|
275
|
-
## [5.5.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.4.0...@alwatr/local-storage@5.5.0) (2025-03-06)
|
|
276
|
-
|
|
277
|
-
### Miscellaneous Chores
|
|
278
|
-
|
|
279
|
-
* update username casing in changelog entries ([9722ac9](https://github.com/Alwatr/nanolib/commit/9722ac9a078438a4e8ebfa5826ea70e0e3a52ca6)) by @
|
|
280
|
-
|
|
281
|
-
### Dependencies update
|
|
282
|
-
|
|
283
|
-
* bump the development-dependencies group across 1 directory with 11 updates ([720c395](https://github.com/Alwatr/nanolib/commit/720c3954da55c929fe8fb16957121f4c51fb7f0c)) by @dependabot[bot]
|
|
284
|
-
|
|
285
|
-
## [5.4.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.8...@alwatr/local-storage@5.4.0) (2025-02-18)
|
|
286
|
-
|
|
287
|
-
## 5.3.0 (2025-02-03)
|
|
288
|
-
|
|
289
|
-
### Features
|
|
290
|
-
|
|
291
|
-
* **local-storage:** add setItem after getItem and add hasItem ([a1b845d](https://github.com/Alwatr/nanolib/commit/a1b845d8d9d207b514f9e06c37610220337b0235)) by @
|
|
292
|
-
|
|
293
|
-
### Miscellaneous Chores
|
|
294
|
-
|
|
295
|
-
* edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @
|
|
296
|
-
|
|
297
|
-
### Dependencies update
|
|
298
|
-
|
|
299
|
-
* bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @
|
|
300
|
-
* update typescript and @types/node to version 5.7.3 and 22.13.0 respectively across multiple packages ([ddab05b](https://github.com/Alwatr/nanolib/commit/ddab05b5d767c30191f36a065e4bc88744e8e3fe)) by @
|
|
301
|
-
|
|
302
|
-
## 5.0.0 (2024-11-02)
|
|
303
|
-
|
|
304
|
-
### ⚠ BREAKING CHANGES
|
|
305
|
-
|
|
306
|
-
* To simplify version management and ensure consistency, all nanolib packages now use the same version as @alwatr/nanolib. This may require updates to your project's dependencies.
|
|
307
|
-
|
|
308
|
-
### Code Refactoring
|
|
309
|
-
|
|
310
|
-
* use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
|
|
311
|
-
|
|
312
|
-
## [5.3.0](https://github.com/Alwatr/nanolib/compare/v5.2.1...v5.3.0) (2025-02-03)
|
|
313
|
-
|
|
314
|
-
### Features
|
|
315
|
-
|
|
316
|
-
* **local-storage:** add setItem after getItem and add hasItem ([a1b845d](https://github.com/Alwatr/nanolib/commit/a1b845d8d9d207b514f9e06c37610220337b0235)) by @ArmanAsadian
|
|
317
|
-
|
|
318
|
-
### Miscellaneous Chores
|
|
319
|
-
|
|
320
|
-
* edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @ArmanAsadian
|
|
321
|
-
|
|
322
|
-
### Dependencies update
|
|
323
|
-
|
|
324
|
-
* bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @dependabot[bot]
|
|
325
|
-
* update typescript and @types/node to version 5.7.3 and 22.13.0 respectively across multiple packages ([ddab05b](https://github.com/Alwatr/nanolib/commit/ddab05b5d767c30191f36a065e4bc88744e8e3fe)) by @alimd
|
|
326
|
-
|
|
327
|
-
## 5.0.0 (2024-11-02)
|
|
328
|
-
|
|
329
|
-
### ⚠ BREAKING CHANGES
|
|
330
|
-
|
|
331
|
-
* To simplify version management and ensure consistency, all nanolib packages now use the same version as @alwatr/nanolib. This may require updates to your project's dependencies.
|
|
332
|
-
|
|
333
|
-
### Features
|
|
334
|
-
|
|
335
|
-
* **local-storage:** If the version is greater than 1, remove the previous version. ([1fdff96](https://github.com/Alwatr/nanolib/commit/1fdff9696a9cf7f1ced0a4c905ea62eb4c422f7a)) by @
|
|
336
|
-
* **local-storage:** Rewrite local storage module ([5ed0f39](https://github.com/Alwatr/nanolib/commit/5ed0f39d090c027bb600a5d061ede887b4669198)) by @
|
|
337
|
-
* **local-storage:** separate package from `@alwatr/util` ([4cc22ed](https://github.com/Alwatr/nanolib/commit/4cc22eda8d89f291783eef3b8917434489b628e1)) by @
|
|
338
|
-
* use `package-tracer` ([cc3c5f9](https://github.com/Alwatr/nanolib/commit/cc3c5f9c1a3d03f0d81b46835665f16a0426fd0d)) by @
|
|
339
|
-
|
|
340
|
-
### Bug Fixes
|
|
341
|
-
|
|
342
|
-
* all dependeny topology ([1c17f34](https://github.com/Alwatr/nanolib/commit/1c17f349adf3e98e2a80ab2da4f0f81028dc9c5f)) by @
|
|
343
|
-
* **local-storage:** Remove unused dependency and update tsconfig references ([b1caaea](https://github.com/Alwatr/nanolib/commit/b1caaea8565cd497d31d91e4e2ea1becd84a82a4)) by @
|
|
344
|
-
|
|
345
|
-
### Code Refactoring
|
|
346
|
-
|
|
347
|
-
* **local-storage:** update removeItem method to use localStorage instead of window.localStorage ([9680a14](https://github.com/Alwatr/nanolib/commit/9680a141a4366d4bb146a73ffcd1bb63dd14f27c)) by @
|
|
348
|
-
* prevent side-effects ([01e00e1](https://github.com/Alwatr/nanolib/commit/01e00e191385cc92b28677df0c01a085916ae677)) by @
|
|
349
|
-
* use new type-helper global types and remove all import types ([08b5d08](https://github.com/Alwatr/nanolib/commit/08b5d08c03c7c315382337239de0426462f384b8)) by @
|
|
350
|
-
* use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
|
|
351
|
-
|
|
352
|
-
### Miscellaneous Chores
|
|
353
|
-
|
|
354
|
-
* include LICENSE and LEGAL files to publish ([09f366f](https://github.com/Alwatr/nanolib/commit/09f366f680bfa9fb26acb2cd1ccbc68c5a9e9ad8)) by @
|
|
355
|
-
* **local-storage:** change the license to AGPL-3.0 ([ef7ea07](https://github.com/Alwatr/nanolib/commit/ef7ea075094c88d90d2ddc6fb9612ae18d792225)) by @
|
|
356
|
-
* Update build and lint scripts ([392d0b7](https://github.com/Alwatr/nanolib/commit/392d0b71f446bce336b0256119a80f07aff794ba)) by @
|
|
357
|
-
* Update package.json exports for [@alwatr](https://github.com/alwatr) packages ([dacb362](https://github.com/Alwatr/nanolib/commit/dacb362b145e3c51b4aba00ff643687a3fac11d2)) by @
|
|
358
|
-
|
|
359
|
-
### Dependencies update
|
|
360
|
-
|
|
361
|
-
* bump the development-dependencies group across 1 directory with 10 updates ([9ed98ff](https://github.com/Alwatr/nanolib/commit/9ed98ffd0668d5a36e255c82edab3af53bffda8f)) by @
|
|
362
|
-
* bump the development-dependencies group with 10 updates ([fa4aaf0](https://github.com/Alwatr/nanolib/commit/fa4aaf04c907ecae06aa14000ce35216170c15ad)) by @
|
|
363
|
-
* upd ([451d025](https://github.com/Alwatr/nanolib/commit/451d0255ba96ed55f897a6f44f62cf4e6d2b12be)) by @
|
|
364
|
-
* update all dependencies ([1e0c30e](https://github.com/Alwatr/nanolib/commit/1e0c30e6a3a8e19deb5185814e24ab6c08dca573)) by @
|
|
365
|
-
* update all dependencies ([0e908b4](https://github.com/Alwatr/nanolib/commit/0e908b476a6b976ec2447f864c8cafcbb8a0f099)) by @
|
|
366
|
-
|
|
367
|
-
## [1.1.8](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.7...@alwatr/local-storage@1.1.8) (2024-11-02)
|
|
368
|
-
|
|
369
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
370
|
-
|
|
371
|
-
## [1.1.7](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.6...@alwatr/local-storage@1.1.7) (2024-10-25)
|
|
372
|
-
|
|
373
|
-
### Code Refactoring
|
|
374
|
-
|
|
375
|
-
* **local-storage:** update removeItem method to use localStorage instead of window.localStorage ([9680a14](https://github.com/Alwatr/nanolib/commit/9680a141a4366d4bb146a73ffcd1bb63dd14f27c)) by @alimd
|
|
376
|
-
|
|
377
|
-
## [1.1.6](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.5...@alwatr/local-storage@1.1.6) (2024-10-12)
|
|
378
|
-
|
|
379
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
380
|
-
|
|
381
|
-
## [1.1.5](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.4...@alwatr/local-storage@1.1.5) (2024-10-11)
|
|
382
|
-
|
|
383
|
-
### Code Refactoring
|
|
384
|
-
|
|
385
|
-
- prevent side-effects ([01e00e1](https://github.com/Alwatr/nanolib/commit/01e00e191385cc92b28677df0c01a085916ae677)) by @mohammadhonarvar
|
|
386
|
-
|
|
387
|
-
## [1.1.4](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.3...@alwatr/local-storage@1.1.4) (2024-10-11)
|
|
388
|
-
|
|
389
|
-
### Miscellaneous Chores
|
|
390
|
-
|
|
391
|
-
- include LICENSE and LEGAL files to publish ([09f366f](https://github.com/Alwatr/nanolib/commit/09f366f680bfa9fb26acb2cd1ccbc68c5a9e9ad8)) by @alimd
|
|
392
|
-
|
|
393
|
-
## [1.1.3](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.2...@alwatr/local-storage@1.1.3) (2024-10-11)
|
|
394
|
-
|
|
395
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
396
|
-
|
|
397
|
-
## [1.1.2](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.1...@alwatr/local-storage@1.1.2) (2024-10-10)
|
|
398
|
-
|
|
399
|
-
### Dependencies update
|
|
400
|
-
|
|
401
|
-
- bump the development-dependencies group with 10 updates ([fa4aaf0](https://github.com/Alwatr/nanolib/commit/fa4aaf04c907ecae06aa14000ce35216170c15ad)) by @dependabot[bot]
|
|
402
|
-
|
|
403
|
-
## [1.1.1](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.0...@alwatr/local-storage@1.1.1) (2024-10-08)
|
|
404
|
-
|
|
405
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
406
|
-
|
|
407
|
-
## [1.1.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.10...@alwatr/local-storage@1.1.0) (2024-09-29)
|
|
408
|
-
|
|
409
|
-
### Features
|
|
410
|
-
|
|
411
|
-
- **local-storage:** If the version is greater than 1, remove the previous version. ([1fdff96](https://github.com/Alwatr/nanolib/commit/1fdff9696a9cf7f1ced0a4c905ea62eb4c422f7a)) by @alimd
|
|
412
|
-
- use `package-tracer` ([cc3c5f9](https://github.com/Alwatr/nanolib/commit/cc3c5f9c1a3d03f0d81b46835665f16a0426fd0d)) by @mohammadhonarvar
|
|
413
|
-
|
|
414
|
-
### Bug Fixes
|
|
415
|
-
|
|
416
|
-
- all dependeny topology ([1c17f34](https://github.com/Alwatr/nanolib/commit/1c17f349adf3e98e2a80ab2da4f0f81028dc9c5f)) by @mohammadhonarvar
|
|
417
|
-
|
|
418
|
-
### Code Refactoring
|
|
419
|
-
|
|
420
|
-
- use new type-helper global types and remove all import types ([08b5d08](https://github.com/Alwatr/nanolib/commit/08b5d08c03c7c315382337239de0426462f384b8)) by @alimd
|
|
421
|
-
|
|
422
|
-
### Miscellaneous Chores
|
|
423
|
-
|
|
424
|
-
- **local-storage:** change the license to AGPL-3.0 ([ef7ea07](https://github.com/Alwatr/nanolib/commit/ef7ea075094c88d90d2ddc6fb9612ae18d792225)) by @ArmanAsadian
|
|
425
|
-
- Update build and lint scripts ([392d0b7](https://github.com/Alwatr/nanolib/commit/392d0b71f446bce336b0256119a80f07aff794ba)) by @alimd
|
|
426
|
-
|
|
427
|
-
## [1.0.10](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.9...@alwatr/local-storage@1.0.10) (2024-09-21)
|
|
428
|
-
|
|
429
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
430
|
-
|
|
431
|
-
## [1.0.9](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.8...@alwatr/local-storage@1.0.9) (2024-09-15)
|
|
432
|
-
|
|
433
|
-
### Dependencies update
|
|
434
|
-
|
|
435
|
-
- bump the development-dependencies group across 1 directory with 10 updates ([9ed98ff](https://github.com/Alwatr/nanolib/commit/9ed98ffd0668d5a36e255c82edab3af53bffda8f)) by @dependabot[bot]
|
|
436
|
-
|
|
437
|
-
## [1.0.8](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.7...@alwatr/local-storage@1.0.8) (2024-08-31)
|
|
438
|
-
|
|
439
|
-
### Miscellaneous Chores
|
|
440
|
-
|
|
441
|
-
- Update package.json exports for [@alwatr](https://github.com/alwatr) packages ([dacb362](https://github.com/Alwatr/nanolib/commit/dacb362b145e3c51b4aba00ff643687a3fac11d2)) by @
|
|
442
|
-
|
|
443
|
-
## [1.0.7](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.6...@alwatr/local-storage@1.0.7) (2024-08-31)
|
|
444
|
-
|
|
445
|
-
### Dependencies update
|
|
446
|
-
|
|
447
|
-
- update all dependencies ([1e0c30e](https://github.com/Alwatr/nanolib/commit/1e0c30e6a3a8e19deb5185814e24ab6c08dca573)) by @alimd
|
|
448
|
-
|
|
449
|
-
## [1.0.6](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.5...@alwatr/local-storage@1.0.6) (2024-07-04)
|
|
450
|
-
|
|
451
|
-
### Dependencies update
|
|
452
|
-
|
|
453
|
-
- update all dependencies ([0e908b4](https://github.com/Alwatr/nanolib/commit/0e908b476a6b976ec2447f864c8cafcbb8a0f099)) by @
|
|
454
|
-
|
|
455
|
-
## [1.0.5](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.4...@alwatr/local-storage@1.0.5) (2024-05-12)
|
|
456
|
-
|
|
457
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
458
|
-
|
|
459
|
-
## [1.0.4](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.3...@alwatr/local-storage@1.0.4) (2024-04-25)
|
|
460
|
-
|
|
461
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
462
|
-
|
|
463
|
-
## [1.0.3](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.2...@alwatr/local-storage@1.0.3) (2024-03-28)
|
|
464
|
-
|
|
465
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
466
|
-
|
|
467
|
-
## [1.0.2](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.1...@alwatr/local-storage@1.0.2) (2024-01-31)
|
|
468
|
-
|
|
469
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
470
|
-
|
|
471
|
-
## [1.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.0...@alwatr/local-storage@1.0.1) (2024-01-24)
|
|
472
|
-
|
|
473
|
-
**Note:** Version bump only for package @alwatr/local-storage
|
|
474
|
-
|
|
475
|
-
## 1.0.0 (2024-01-16)
|
|
476
|
-
|
|
477
|
-
### Features
|
|
478
|
-
|
|
479
|
-
- **local-storage:** Rewrite local storage module ([5ed0f39](https://github.com/Alwatr/nanolib/commit/5ed0f39d090c027bb600a5d061ede887b4669198)) by @alimd
|
|
480
|
-
- **local-storage:** separate package from `@alwatr/util` ([4cc22ed](https://github.com/Alwatr/nanolib/commit/4cc22eda8d89f291783eef3b8917434489b628e1)) by @njfamirm
|
|
481
|
-
|
|
482
|
-
### Bug Fixes
|
|
483
|
-
|
|
484
|
-
- **local-storage:** Remove unused dependency and update tsconfig references ([b1caaea](https://github.com/Alwatr/nanolib/commit/b1caaea8565cd497d31d91e4e2ea1becd84a82a4)) by @alimd
|
package/dist/main.cjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/** 📦 @alwatr/local-storage v7.0.9 */
|
|
2
|
-
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var main_exports={};__export(main_exports,{LocalStorageProvider:()=>LocalStorageProvider,createLocalStorageProvider:()=>createLocalStorageProvider});module.exports=__toCommonJS(main_exports);var import_logger=require("@alwatr/logger");var LocalStorageProvider=class _LocalStorageProvider{static{this.version="7.0.9"}constructor(config){this.logger_=(0,import_logger.createLogger)(`local-storage-provider: ${config.name}, v: ${config.schemaVersion}`);this.logger_.logMethodArgs?.("constructor",{config});this.key__=_LocalStorageProvider.getKey(config);_LocalStorageProvider.clearPreviousStorageVersions(config)}static getKey(config){return`${config.name}.v${config.schemaVersion}`}static clearPreviousStorageVersions(config){if(config.schemaVersion<1)return;for(let i=0;i<config.schemaVersion;i++){const oldKey=_LocalStorageProvider.getKey({name:config.name,schemaVersion:i});localStorage.removeItem(oldKey)}}static has(config){const key=_LocalStorageProvider.getKey(config);return localStorage.getItem(key)!==null}has(){return localStorage.getItem(this.key__)!==null}read(){let value=null;try{value=localStorage.getItem(this.key__)}catch(err){this.logger_.error("read","read_local_storage_error",{err})}if(!value){this.logger_.logMethod?.("read//no_value");return null}try{const parsedValue=JSON.parse(value);this.logger_.logMethodFull?.("read//value",void 0,{parsedValue});return parsedValue}catch(err){this.logger_.error("read","read_parse_error",{err});return null}}write(value){this.logger_.logMethodArgs?.("write",{value});let valueStr;try{valueStr=JSON.stringify(value)}catch(err){this.logger_.error("write","write_stringify_error",{err});throw new Error("write_stringify_error")}try{localStorage.setItem(this.key__,valueStr)}catch(err){this.logger_.error("write","write_local_storage_error",{err})}}remove(){localStorage.removeItem(this.key__)}};function createLocalStorageProvider(config){return new LocalStorageProvider(config)}0&&(module.exports={LocalStorageProvider,createLocalStorageProvider});
|
|
3
|
-
//# sourceMappingURL=main.cjs.map
|
package/dist/main.cjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/main.ts", "../src/local-storage.provider.ts", "../src/facade.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './local-storage.provider.js';\nexport * from './facade.js';\nexport type * from './type.js';\n", "import {createLogger} from '@alwatr/logger';\n\nimport type {LocalStorageProviderConfig} from './type.js';\n\n/**\n * A provider class for managing a specific, versioned item in localStorage.\n * It encapsulates the logic for key generation, serialization, and migration.\n *\n * @example\n * ```typescript\n * const userSettings = new LocalStorageProvider({\n * name: 'user-settings',\n * version: 1\n * });\n *\n * // Write new settings\n * userSettings.write({ theme: 'dark', notifications: false });\n *\n * // Read the current settings\n * const currentSettings = userSettings.read();\n * console.log(currentSettings); // { theme: 'dark', notifications: false }\n * ```\n */\nexport class LocalStorageProvider<T extends JsonValue> {\n public static readonly version = __package_version__;\n\n private readonly key__: string;\n protected readonly logger_;\n\n constructor(config: LocalStorageProviderConfig) {\n this.logger_ = createLogger(`local-storage-provider: ${config.name}, v: ${config.schemaVersion}`);\n this.logger_.logMethodArgs?.('constructor', {config});\n this.key__ = LocalStorageProvider.getKey(config);\n LocalStorageProvider.clearPreviousStorageVersions(config);\n }\n\n /**\n * Generates the versioned storage key.\n * @param meta - An object containing the name and schemaVersion.\n * @returns The versioned key string.\n */\n public static getKey(config: LocalStorageProviderConfig): string {\n return `${config.name}.v${config.schemaVersion}`;\n }\n\n /**\n * Manages data migration by removing all previous versions of the item.\n */\n public static clearPreviousStorageVersions(config: LocalStorageProviderConfig): void {\n if (config.schemaVersion < 1) return;\n\n // Iterate from v1 up to the version just before the current one and remove them.\n for (let i = 0; i < config.schemaVersion; i++) {\n const oldKey = LocalStorageProvider.getKey({name: config.name, schemaVersion: i});\n localStorage.removeItem(oldKey);\n }\n }\n\n /**\n * Checks if a versioned item exists in localStorage for the given configuration.\n * This static method allows checking for the existence of a specific versioned item\n * without instantiating the provider.\n *\n * @param config - The configuration object containing the name and schemaVersion.\n * @returns `true` if the item exists in localStorage, otherwise `false`.\n *\n * @example\n * ```typescript\n * const exists = LocalStorageProvider.has({ name: 'user-form', schemaVersion: 1 });\n * ```\n */\n public static has(config: LocalStorageProviderConfig): boolean {\n const key = LocalStorageProvider.getKey(config);\n return localStorage.getItem(key) !== null;\n }\n\n /**\n * Checks if the current versioned item exists in localStorage.\n *\n * @returns `true` if the item exists in localStorage, otherwise `false`.\n *\n * @example\n * ```typescript\n * const provider = new LocalStorageProvider({ name: 'profile', schemaVersion: 2 });\n * if (provider.has()) {\n * // Item exists\n * }\n * ```\n */\n public has(): boolean {\n return localStorage.getItem(this.key__) !== null;\n }\n\n /**\n * Reads and parses the value from localStorage.\n * If the item doesn't exist or is invalid JSON, returns null.\n */\n public read(): T | null {\n let value: string | null = null;\n\n try {\n value = localStorage.getItem(this.key__);\n }\n catch (err) {\n this.logger_.error('read', 'read_local_storage_error', {err});\n }\n\n if (!value) {\n this.logger_.logMethod?.('read//no_value');\n return null;\n }\n\n try {\n const parsedValue = JSON.parse(value) as T;\n this.logger_.logMethodFull?.('read//value', undefined, {parsedValue});\n return parsedValue;\n }\n catch (err) {\n this.logger_.error('read', 'read_parse_error', {err});\n return null;\n }\n }\n\n /**\n * Serializes and writes a value to localStorage.\n */\n public write(value: T): void {\n this.logger_.logMethodArgs?.('write', {value});\n let valueStr: string;\n try {\n valueStr = JSON.stringify(value);\n }\n catch (err) {\n this.logger_.error('write', 'write_stringify_error', {err});\n throw new Error('write_stringify_error');\n }\n\n try {\n localStorage.setItem(this.key__, valueStr);\n }\n catch (err) {\n this.logger_.error('write', 'write_local_storage_error', {err});\n }\n }\n\n /**\n * Removes the item from localStorage.\n */\n public remove(): void {\n localStorage.removeItem(this.key__);\n }\n}\n", "import {LocalStorageProvider} from './local-storage.provider.js';\n\nimport type {LocalStorageProviderConfig} from './type.js';\n\n/**\n * Factory function to create a new LocalStorageProvider.\n *\n * @param config - The configuration for the provider.\n * @returns An instance of LocalStorageProvider.\n *\n * @example\n * ```typescript\n * const userSettings = createLocalStorageProvider({\n * name: 'user-settings',\n * schemaVersion: 1\n * });\n *\n * // Write new settings\n * userSettings.write({ theme: 'dark', notifications: false });\n *\n * // Read the current settings\n * const currentSettings = userSettings.read();\n * console.log(currentSettings); // { theme: 'dark', notifications: false }\n * ```\n */\nexport function createLocalStorageProvider<T extends JsonValue>(config: LocalStorageProviderConfig): LocalStorageProvider<T> {\n return new LocalStorageProvider<T>(config);\n}\n"],
|
|
5
|
-
"mappings": ";qqBAAA,+LCAA,kBAA2B,0BAuBpB,IAAM,qBAAN,MAAM,qBAA0C,CACrD,YAAuB,QAAU,QAKjC,YAAY,OAAoC,CAC9C,KAAK,WAAU,4BAAa,2BAA2B,OAAO,IAAI,QAAQ,OAAO,aAAa,EAAE,EAChG,KAAK,QAAQ,gBAAgB,cAAe,CAAC,MAAM,CAAC,EACpD,KAAK,MAAQ,sBAAqB,OAAO,MAAM,EAC/C,sBAAqB,6BAA6B,MAAM,CAC1D,CAOA,OAAc,OAAO,OAA4C,CAC/D,MAAO,GAAG,OAAO,IAAI,KAAK,OAAO,aAAa,EAChD,CAKA,OAAc,6BAA6B,OAA0C,CACnF,GAAI,OAAO,cAAgB,EAAG,OAG9B,QAAS,EAAI,EAAG,EAAI,OAAO,cAAe,IAAK,CAC7C,MAAM,OAAS,sBAAqB,OAAO,CAAC,KAAM,OAAO,KAAM,cAAe,CAAC,CAAC,EAChF,aAAa,WAAW,MAAM,CAChC,CACF,CAeA,OAAc,IAAI,OAA6C,CAC7D,MAAM,IAAM,sBAAqB,OAAO,MAAM,EAC9C,OAAO,aAAa,QAAQ,GAAG,IAAM,IACvC,CAeO,KAAe,CACpB,OAAO,aAAa,QAAQ,KAAK,KAAK,IAAM,IAC9C,CAMO,MAAiB,CACtB,IAAI,MAAuB,KAE3B,GAAI,CACF,MAAQ,aAAa,QAAQ,KAAK,KAAK,CACzC,OACO,IAAK,CACV,KAAK,QAAQ,MAAM,OAAQ,2BAA4B,CAAC,GAAG,CAAC,CAC9D,CAEA,GAAI,CAAC,MAAO,CACV,KAAK,QAAQ,YAAY,gBAAgB,EACzC,OAAO,IACT,CAEA,GAAI,CACF,MAAM,YAAc,KAAK,MAAM,KAAK,EACpC,KAAK,QAAQ,gBAAgB,cAAe,OAAW,CAAC,WAAW,CAAC,EACpE,OAAO,WACT,OACO,IAAK,CACV,KAAK,QAAQ,MAAM,OAAQ,mBAAoB,CAAC,GAAG,CAAC,EACpD,OAAO,IACT,CACF,CAKO,MAAM,MAAgB,CAC3B,KAAK,QAAQ,gBAAgB,QAAS,CAAC,KAAK,CAAC,EAC7C,IAAI,SACJ,GAAI,CACF,SAAW,KAAK,UAAU,KAAK,CACjC,OACO,IAAK,CACV,KAAK,QAAQ,MAAM,QAAS,wBAAyB,CAAC,GAAG,CAAC,EAC1D,MAAM,IAAI,MAAM,uBAAuB,CACzC,CAEA,GAAI,CACF,aAAa,QAAQ,KAAK,MAAO,QAAQ,CAC3C,OACO,IAAK,CACV,KAAK,QAAQ,MAAM,QAAS,4BAA6B,CAAC,GAAG,CAAC,CAChE,CACF,CAKO,QAAe,CACpB,aAAa,WAAW,KAAK,KAAK,CACpC,CACF,EC9HO,SAAS,2BAAgD,OAA6D,CAC3H,OAAO,IAAI,qBAAwB,MAAM,CAC3C",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/main.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/** 📦 @alwatr/local-storage v7.0.9 */
|
|
2
|
-
import{createLogger}from"@alwatr/logger";var LocalStorageProvider=class _LocalStorageProvider{static{this.version="7.0.9"}constructor(config){this.logger_=createLogger(`local-storage-provider: ${config.name}, v: ${config.schemaVersion}`);this.logger_.logMethodArgs?.("constructor",{config});this.key__=_LocalStorageProvider.getKey(config);_LocalStorageProvider.clearPreviousStorageVersions(config)}static getKey(config){return`${config.name}.v${config.schemaVersion}`}static clearPreviousStorageVersions(config){if(config.schemaVersion<1)return;for(let i=0;i<config.schemaVersion;i++){const oldKey=_LocalStorageProvider.getKey({name:config.name,schemaVersion:i});localStorage.removeItem(oldKey)}}static has(config){const key=_LocalStorageProvider.getKey(config);return localStorage.getItem(key)!==null}has(){return localStorage.getItem(this.key__)!==null}read(){let value=null;try{value=localStorage.getItem(this.key__)}catch(err){this.logger_.error("read","read_local_storage_error",{err})}if(!value){this.logger_.logMethod?.("read//no_value");return null}try{const parsedValue=JSON.parse(value);this.logger_.logMethodFull?.("read//value",void 0,{parsedValue});return parsedValue}catch(err){this.logger_.error("read","read_parse_error",{err});return null}}write(value){this.logger_.logMethodArgs?.("write",{value});let valueStr;try{valueStr=JSON.stringify(value)}catch(err){this.logger_.error("write","write_stringify_error",{err});throw new Error("write_stringify_error")}try{localStorage.setItem(this.key__,valueStr)}catch(err){this.logger_.error("write","write_local_storage_error",{err})}}remove(){localStorage.removeItem(this.key__)}};function createLocalStorageProvider(config){return new LocalStorageProvider(config)}export{LocalStorageProvider,createLocalStorageProvider};
|
|
3
|
-
//# sourceMappingURL=main.mjs.map
|
package/dist/main.mjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/local-storage.provider.ts", "../src/facade.ts"],
|
|
4
|
-
"sourcesContent": ["import {createLogger} from '@alwatr/logger';\n\nimport type {LocalStorageProviderConfig} from './type.js';\n\n/**\n * A provider class for managing a specific, versioned item in localStorage.\n * It encapsulates the logic for key generation, serialization, and migration.\n *\n * @example\n * ```typescript\n * const userSettings = new LocalStorageProvider({\n * name: 'user-settings',\n * version: 1\n * });\n *\n * // Write new settings\n * userSettings.write({ theme: 'dark', notifications: false });\n *\n * // Read the current settings\n * const currentSettings = userSettings.read();\n * console.log(currentSettings); // { theme: 'dark', notifications: false }\n * ```\n */\nexport class LocalStorageProvider<T extends JsonValue> {\n public static readonly version = __package_version__;\n\n private readonly key__: string;\n protected readonly logger_;\n\n constructor(config: LocalStorageProviderConfig) {\n this.logger_ = createLogger(`local-storage-provider: ${config.name}, v: ${config.schemaVersion}`);\n this.logger_.logMethodArgs?.('constructor', {config});\n this.key__ = LocalStorageProvider.getKey(config);\n LocalStorageProvider.clearPreviousStorageVersions(config);\n }\n\n /**\n * Generates the versioned storage key.\n * @param meta - An object containing the name and schemaVersion.\n * @returns The versioned key string.\n */\n public static getKey(config: LocalStorageProviderConfig): string {\n return `${config.name}.v${config.schemaVersion}`;\n }\n\n /**\n * Manages data migration by removing all previous versions of the item.\n */\n public static clearPreviousStorageVersions(config: LocalStorageProviderConfig): void {\n if (config.schemaVersion < 1) return;\n\n // Iterate from v1 up to the version just before the current one and remove them.\n for (let i = 0; i < config.schemaVersion; i++) {\n const oldKey = LocalStorageProvider.getKey({name: config.name, schemaVersion: i});\n localStorage.removeItem(oldKey);\n }\n }\n\n /**\n * Checks if a versioned item exists in localStorage for the given configuration.\n * This static method allows checking for the existence of a specific versioned item\n * without instantiating the provider.\n *\n * @param config - The configuration object containing the name and schemaVersion.\n * @returns `true` if the item exists in localStorage, otherwise `false`.\n *\n * @example\n * ```typescript\n * const exists = LocalStorageProvider.has({ name: 'user-form', schemaVersion: 1 });\n * ```\n */\n public static has(config: LocalStorageProviderConfig): boolean {\n const key = LocalStorageProvider.getKey(config);\n return localStorage.getItem(key) !== null;\n }\n\n /**\n * Checks if the current versioned item exists in localStorage.\n *\n * @returns `true` if the item exists in localStorage, otherwise `false`.\n *\n * @example\n * ```typescript\n * const provider = new LocalStorageProvider({ name: 'profile', schemaVersion: 2 });\n * if (provider.has()) {\n * // Item exists\n * }\n * ```\n */\n public has(): boolean {\n return localStorage.getItem(this.key__) !== null;\n }\n\n /**\n * Reads and parses the value from localStorage.\n * If the item doesn't exist or is invalid JSON, returns null.\n */\n public read(): T | null {\n let value: string | null = null;\n\n try {\n value = localStorage.getItem(this.key__);\n }\n catch (err) {\n this.logger_.error('read', 'read_local_storage_error', {err});\n }\n\n if (!value) {\n this.logger_.logMethod?.('read//no_value');\n return null;\n }\n\n try {\n const parsedValue = JSON.parse(value) as T;\n this.logger_.logMethodFull?.('read//value', undefined, {parsedValue});\n return parsedValue;\n }\n catch (err) {\n this.logger_.error('read', 'read_parse_error', {err});\n return null;\n }\n }\n\n /**\n * Serializes and writes a value to localStorage.\n */\n public write(value: T): void {\n this.logger_.logMethodArgs?.('write', {value});\n let valueStr: string;\n try {\n valueStr = JSON.stringify(value);\n }\n catch (err) {\n this.logger_.error('write', 'write_stringify_error', {err});\n throw new Error('write_stringify_error');\n }\n\n try {\n localStorage.setItem(this.key__, valueStr);\n }\n catch (err) {\n this.logger_.error('write', 'write_local_storage_error', {err});\n }\n }\n\n /**\n * Removes the item from localStorage.\n */\n public remove(): void {\n localStorage.removeItem(this.key__);\n }\n}\n", "import {LocalStorageProvider} from './local-storage.provider.js';\n\nimport type {LocalStorageProviderConfig} from './type.js';\n\n/**\n * Factory function to create a new LocalStorageProvider.\n *\n * @param config - The configuration for the provider.\n * @returns An instance of LocalStorageProvider.\n *\n * @example\n * ```typescript\n * const userSettings = createLocalStorageProvider({\n * name: 'user-settings',\n * schemaVersion: 1\n * });\n *\n * // Write new settings\n * userSettings.write({ theme: 'dark', notifications: false });\n *\n * // Read the current settings\n * const currentSettings = userSettings.read();\n * console.log(currentSettings); // { theme: 'dark', notifications: false }\n * ```\n */\nexport function createLocalStorageProvider<T extends JsonValue>(config: LocalStorageProviderConfig): LocalStorageProvider<T> {\n return new LocalStorageProvider<T>(config);\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAQ,iBAAmB,iBAuBpB,IAAM,qBAAN,MAAM,qBAA0C,CACrD,YAAuB,QAAU,QAKjC,YAAY,OAAoC,CAC9C,KAAK,QAAU,aAAa,2BAA2B,OAAO,IAAI,QAAQ,OAAO,aAAa,EAAE,EAChG,KAAK,QAAQ,gBAAgB,cAAe,CAAC,MAAM,CAAC,EACpD,KAAK,MAAQ,sBAAqB,OAAO,MAAM,EAC/C,sBAAqB,6BAA6B,MAAM,CAC1D,CAOA,OAAc,OAAO,OAA4C,CAC/D,MAAO,GAAG,OAAO,IAAI,KAAK,OAAO,aAAa,EAChD,CAKA,OAAc,6BAA6B,OAA0C,CACnF,GAAI,OAAO,cAAgB,EAAG,OAG9B,QAAS,EAAI,EAAG,EAAI,OAAO,cAAe,IAAK,CAC7C,MAAM,OAAS,sBAAqB,OAAO,CAAC,KAAM,OAAO,KAAM,cAAe,CAAC,CAAC,EAChF,aAAa,WAAW,MAAM,CAChC,CACF,CAeA,OAAc,IAAI,OAA6C,CAC7D,MAAM,IAAM,sBAAqB,OAAO,MAAM,EAC9C,OAAO,aAAa,QAAQ,GAAG,IAAM,IACvC,CAeO,KAAe,CACpB,OAAO,aAAa,QAAQ,KAAK,KAAK,IAAM,IAC9C,CAMO,MAAiB,CACtB,IAAI,MAAuB,KAE3B,GAAI,CACF,MAAQ,aAAa,QAAQ,KAAK,KAAK,CACzC,OACO,IAAK,CACV,KAAK,QAAQ,MAAM,OAAQ,2BAA4B,CAAC,GAAG,CAAC,CAC9D,CAEA,GAAI,CAAC,MAAO,CACV,KAAK,QAAQ,YAAY,gBAAgB,EACzC,OAAO,IACT,CAEA,GAAI,CACF,MAAM,YAAc,KAAK,MAAM,KAAK,EACpC,KAAK,QAAQ,gBAAgB,cAAe,OAAW,CAAC,WAAW,CAAC,EACpE,OAAO,WACT,OACO,IAAK,CACV,KAAK,QAAQ,MAAM,OAAQ,mBAAoB,CAAC,GAAG,CAAC,EACpD,OAAO,IACT,CACF,CAKO,MAAM,MAAgB,CAC3B,KAAK,QAAQ,gBAAgB,QAAS,CAAC,KAAK,CAAC,EAC7C,IAAI,SACJ,GAAI,CACF,SAAW,KAAK,UAAU,KAAK,CACjC,OACO,IAAK,CACV,KAAK,QAAQ,MAAM,QAAS,wBAAyB,CAAC,GAAG,CAAC,EAC1D,MAAM,IAAI,MAAM,uBAAuB,CACzC,CAEA,GAAI,CACF,aAAa,QAAQ,KAAK,MAAO,QAAQ,CAC3C,OACO,IAAK,CACV,KAAK,QAAQ,MAAM,QAAS,4BAA6B,CAAC,GAAG,CAAC,CAChE,CACF,CAKO,QAAe,CACpB,aAAa,WAAW,KAAK,KAAK,CACpC,CACF,EC9HO,SAAS,2BAAgD,OAA6D,CAC3H,OAAO,IAAI,qBAAwB,MAAM,CAC3C",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|