@alwatr/local-storage 7.0.8 → 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 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
@@ -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: LocalStor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K,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,29 +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": "7.0.8",
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": "6.0.17"
8
+ "@alwatr/logger": "7.0.0"
9
9
  },
10
10
  "devDependencies": {
11
- "@alwatr/nano-build": "6.4.1",
12
- "@alwatr/prettier-config": "6.0.2",
13
- "@alwatr/tsconfig-base": "6.0.4",
14
- "@alwatr/type-helper": "7.0.1",
15
- "@jest/globals": "^30.2.0",
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",
16
15
  "typescript": "^5.9.3"
17
16
  },
18
17
  "exports": {
19
18
  ".": {
20
19
  "types": "./dist/main.d.ts",
21
- "import": "./dist/main.mjs",
22
- "require": "./dist/main.cjs"
20
+ "default": "./dist/main.js"
23
21
  }
24
22
  },
25
23
  "files": [
26
- "**/*.{js,mjs,cjs,map,d.ts,html,md,LEGAL.txt}",
24
+ "**/*.{js,mjs,cjs,ts,map,d.ts,html,LEGAL.txt}",
25
+ "README.md",
27
26
  "LICENSE",
28
27
  "!demo/**/*",
29
28
  "!**/*.test.js"
@@ -48,8 +47,6 @@
48
47
  "versioning"
49
48
  ],
50
49
  "license": "MPL-2.0",
51
- "main": "./dist/main.cjs",
52
- "module": "./dist/main.mjs",
53
50
  "prettier": "@alwatr/prettier-config",
54
51
  "publishConfig": {
55
52
  "access": "public"
@@ -60,21 +57,21 @@
60
57
  "directory": "packages/local-storage"
61
58
  },
62
59
  "scripts": {
63
- "b": "yarn run build",
64
- "build": "yarn run build:ts && yarn run build:es",
65
- "build:es": "nano-build --preset=module",
60
+ "b": "bun run build",
61
+ "build": "bun run build:ts && bun run build:es",
62
+ "build:es": "nano-build --preset=module src/main.ts",
66
63
  "build:ts": "tsc --build",
67
- "c": "yarn run clean",
68
- "cb": "yarn run clean && yarn run build",
64
+ "c": "bun run clean",
65
+ "cb": "bun run clean && bun run build",
69
66
  "clean": "rm -rfv dist *.tsbuildinfo",
70
- "d": "yarn run build:es && yarn node --enable-source-maps --trace-warnings",
71
- "w": "yarn run watch",
72
- "watch": "yarn run watch:ts & yarn run watch:es",
73
- "watch:es": "yarn run build:es --watch",
74
- "watch:ts": "yarn run build:ts --watch --preserveWatchOutput"
67
+ "d": "bun run build:es && bun",
68
+ "w": "bun run watch",
69
+ "watch": "bun run watch:ts & bun run watch:es",
70
+ "watch:es": "bun run build:es --watch",
71
+ "watch:ts": "bun run build:ts --watch --preserveWatchOutput"
75
72
  },
76
73
  "sideEffects": false,
77
74
  "type": "module",
78
75
  "types": "./dist/main.d.ts",
79
- "gitHead": "f9f9ba54b319ce8ccc6968059b222e89f4b5d149"
76
+ "gitHead": "056102a1c8a563bbae8a290b6830450f467322a3"
80
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
@@ -0,0 +1,3 @@
1
+ export * from './local-storage.provider.js';
2
+ export * from './facade.js';
3
+ export type * from './type.js';
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,478 +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.8](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.7...@alwatr/local-storage@7.0.8) (2026-02-18)
7
-
8
- **Note:** Version bump only for package @alwatr/local-storage
9
-
10
- ## [7.0.7](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.6...@alwatr/local-storage@7.0.7) (2025-12-23)
11
-
12
- **Note:** Version bump only for package @alwatr/local-storage
13
-
14
- ## [7.0.6](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.5...@alwatr/local-storage@7.0.6) (2025-12-13)
15
-
16
- **Note:** Version bump only for package @alwatr/local-storage
17
-
18
- ## [7.0.5](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.4...@alwatr/local-storage@7.0.5) (2025-12-10)
19
-
20
- **Note:** Version bump only for package @alwatr/local-storage
21
-
22
- ## [7.0.4](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.3...@alwatr/local-storage@7.0.4) (2025-11-18)
23
-
24
- ### 🔨 Code Refactoring
25
-
26
- * remove unnecessary type declarations from tsconfig.json files ([89bcc7d](https://github.com/Alwatr/nanolib/commit/89bcc7db839807110b80f8ba34414ea9734d9c75))
27
-
28
- ## [7.0.3](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.2...@alwatr/local-storage@7.0.3) (2025-11-15)
29
-
30
- **Note:** Version bump only for package @alwatr/local-storage
31
-
32
- ## [7.0.2](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.1...@alwatr/local-storage@7.0.2) (2025-11-15)
33
-
34
- **Note:** Version bump only for package @alwatr/local-storage
35
-
36
- ## [7.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@7.0.0...@alwatr/local-storage@7.0.1) (2025-11-04)
37
-
38
- **Note:** Version bump only for package @alwatr/local-storage
39
-
40
- ## [7.0.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.3.4...@alwatr/local-storage@7.0.0) (2025-10-06)
41
-
42
- ### ⚠ BREAKING CHANGES
43
-
44
- * api changed and defaultValue removed
45
-
46
- ### ✨ Features
47
-
48
- * implement static method to check existence of versioned item in localStorage ([c622595](https://github.com/Alwatr/nanolib/commit/c622595bcd793746133733b22c7704463d50314d))
49
-
50
- ### 🔨 Code Refactoring
51
-
52
- * enhance documentation for LocalStorageProviderConfig interface ([11407cd](https://github.com/Alwatr/nanolib/commit/11407cd80ee9def06bcb21c6bb426e92caa7d702))
53
- * improve documentation for LocalStorageProvider's static methods ([145ac5c](https://github.com/Alwatr/nanolib/commit/145ac5c0d947c9d3f1e91a25e5ca749e0e56d85b))
54
- * simplify LocalStorageProvider configuration and remove unused types ([b839299](https://github.com/Alwatr/nanolib/commit/b839299d3950f1662773fd8f3a0e6b2189c3d140))
55
-
56
- ### 🔗 Dependencies update
57
-
58
- * bump the npm-dependencies group with 4 updates ([9825815](https://github.com/Alwatr/nanolib/commit/982581552bbb4b97dca52af5e93a80937f0c3109))
59
-
60
- ## [6.3.4](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.3.3...@alwatr/local-storage@6.3.4) (2025-09-27)
61
-
62
- ### 🧹 Miscellaneous Chores
63
-
64
- * exclude test files from package distribution ([86f4f2f](https://github.com/Alwatr/nanolib/commit/86f4f2f5985845c5cf3a3a9398de7b2f98ce53e7))
65
-
66
- ## [6.3.3](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.3.2...@alwatr/local-storage@6.3.3) (2025-09-22)
67
-
68
- ### 🐛 Bug Fixes
69
-
70
- * add constraint to createLocalStorageProvider generic type to extend JsonValue ([198ca49](https://github.com/Alwatr/nanolib/commit/198ca49042780aff15d3979bea3951bf094b3b15))
71
- * add generic type constraint to LocalStorageProviderConfig to extend JsonValue ([9b97692](https://github.com/Alwatr/nanolib/commit/9b9769254613aac6ad94a0c2dd885c44e63b6ed2))
72
- * refine generic type constraints in LocalStorageProvider to extend JsonValue ([6a05c12](https://github.com/Alwatr/nanolib/commit/6a05c12583326dbea8784f79f7c559b9a31d3cef))
73
- * rename convertDataType method to convertDataType__ for consistency ([83ccb56](https://github.com/Alwatr/nanolib/commit/83ccb56a9ff95ba0c4e8e6a77cb67a010d60701a))
74
-
75
- ## [6.3.2](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.3.1...@alwatr/local-storage@6.3.2) (2025-09-22)
76
-
77
- ### 🐛 Bug Fixes
78
-
79
- * remove unnecessary constraint from createLocalStorageProvider generic type ([960467f](https://github.com/Alwatr/nanolib/commit/960467fd161a80bf4e90cb3070054cee58182bfb))
80
-
81
- ## [6.3.1](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.3.0...@alwatr/local-storage@6.3.1) (2025-09-22)
82
-
83
- ### 🐛 Bug Fixes
84
-
85
- * update convertDataType method to accept both raw and serialized data types ([1ca0256](https://github.com/Alwatr/nanolib/commit/1ca02563d0ce27f0b90572563eb8afb109ae2f07))
86
-
87
- ## [6.3.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.2.0...@alwatr/local-storage@6.3.0) (2025-09-22)
88
-
89
- ### ✨ Features
90
-
91
- * make convertDataType public access ([f8b08e1](https://github.com/Alwatr/nanolib/commit/f8b08e1c81b97176f1dc1777434a17126651fdd3))
92
-
93
- ## [6.2.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.8...@alwatr/local-storage@6.2.0) (2025-09-22)
94
-
95
- ### ✨ Features
96
-
97
- * move createLocalStorageProvider function to facade.ts and clean up main.ts ([5dd6164](https://github.com/Alwatr/nanolib/commit/5dd6164f908de9a6ceec70dd19cc6f67d8c22ad6))
98
-
99
- ### 🐛 Bug Fixes
100
-
101
- * correct parameter name in createLocalStorageProvider example ([bc894a3](https://github.com/Alwatr/nanolib/commit/bc894a36e3d033244b81063dccb1dfedb86a0082))
102
- * improve error handling in read and write methods of LocalStorageProvider ([845f37c](https://github.com/Alwatr/nanolib/commit/845f37cddd14f54a5bb50c3d902c7221d8fc9aef))
103
- * refactor LocalStorageProvider constructor and methods for improved clarity and error handling ([da2c5b4](https://github.com/Alwatr/nanolib/commit/da2c5b476ff0184e476be2e2a8af87ba6364bfbd))
104
- * update error logging in convertDataType__ method for improved clarity ([3e395e5](https://github.com/Alwatr/nanolib/commit/3e395e529aae1dcac5ad0b431070761b23e2d935))
105
- * update return types in LocalStorageProvider methods for better type safety ([0abcb41](https://github.com/Alwatr/nanolib/commit/0abcb41b9440324a70e2b782b0643bb8a51e47c6))
106
-
107
- ## [6.1.8](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.7...@alwatr/local-storage@6.1.8) (2025-09-22)
108
-
109
- ### 🐛 Bug Fixes
110
-
111
- * update version references to schemaVersion in README and code ([c51c115](https://github.com/Alwatr/nanolib/commit/c51c115ea431bba10a248fe6e4e37dcdff6da059))
112
-
113
- ## [6.1.7](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.6...@alwatr/local-storage@6.1.7) (2025-09-21)
114
-
115
- **Note:** Version bump only for package @alwatr/local-storage
116
-
117
- ## [6.1.6](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.5...@alwatr/local-storage@6.1.6) (2025-09-20)
118
-
119
- ### 🐛 Bug Fixes
120
-
121
- * add sideEffects property to package.json files for better tree-shaking ([c7b9e74](https://github.com/Alwatr/nanolib/commit/c7b9e74e1920c8e35b438742de61883ca62da58c))
122
- * add sideEffects property to package.json files for better tree-shaking ([e8402c4](https://github.com/Alwatr/nanolib/commit/e8402c481a14a1f807a37aaa862a936713d26176))
123
-
124
- ### 🧹 Miscellaneous Chores
125
-
126
- * remove duplicate sideEffects property from multiple package.json files ([b123f86](https://github.com/Alwatr/nanolib/commit/b123f86be81481de2314aae9bb2eeb629743d24c))
127
-
128
- ## [6.1.5](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.4...@alwatr/local-storage@6.1.5) (2025-09-19)
129
-
130
- **Note:** Version bump only for package @alwatr/local-storage
131
-
132
- ## [6.1.4](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.3...@alwatr/local-storage@6.1.4) (2025-09-19)
133
-
134
- **Note:** Version bump only for package @alwatr/local-storage
135
-
136
- ## [6.1.3](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.2...@alwatr/local-storage@6.1.3) (2025-09-15)
137
-
138
- **Note:** Version bump only for package @alwatr/local-storage
139
-
140
- ## [6.1.2](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.1...@alwatr/local-storage@6.1.2) (2025-09-14)
141
-
142
- ### 🔨 Code Refactoring
143
-
144
- * **package:** update keywords in package.json for debounce, local-storage, and synapse packages ([09c9cca](https://github.com/Alwatr/nanolib/commit/09c9cca3cd600e9ffaf600fb1926c0ee884a1aa8))
145
- * remove types from tsconfig.json and adjust imports in type.ts ([ad2d3b3](https://github.com/Alwatr/nanolib/commit/ad2d3b3927db7bf3b5b54dcac5cdae751d00eb4a))
146
-
147
- ## [6.1.1](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.1.0...@alwatr/local-storage@6.1.1) (2025-09-13)
148
-
149
- ### 🐛 Bug Fixes
150
-
151
- * remove duplicate "types" entry in package.json ([86dce1a](https://github.com/Alwatr/nanolib/commit/86dce1a88ad3c605fe03f335d4f4813aad573ed8))
152
-
153
- ## [6.1.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@6.0.0...@alwatr/local-storage@6.1.0) (2025-09-13)
154
-
155
- ### ✨ Features
156
-
157
- * **local-storage:** add static version property to LocalStorageProvider ([267b4b6](https://github.com/Alwatr/nanolib/commit/267b4b6d5a7d4fb14fbea7fe3b5c11611c838170))
158
-
159
- ### 🧹 Miscellaneous Chores
160
-
161
- * remove package-tracer dependency and related code from fetch package ([96fe4e9](https://github.com/Alwatr/nanolib/commit/96fe4e9552a205f218ceed187c55e4e904a07089))
162
- * remove package-tracer dependency and related code from LocalStorageProvider ([84e2fc1](https://github.com/Alwatr/nanolib/commit/84e2fc1894a09908119b5456804a6404e5cdcbd3))
163
-
164
- ## [6.0.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.10...@alwatr/local-storage@6.0.0) (2025-09-13)
165
-
166
- ### ⚠ BREAKING CHANGES
167
-
168
- * **local-storage:** The provider's constructor config shape and public methods have changed.
169
- Existing callers must be updated to the new API:
170
- - Update imports/instantiation to use the new LocalStorageProvider<T>(config: LocalStorageProviderConfig<T>).
171
- - Replace any old config fields / method names with the new ones (e.g. versioned key handling, defaultValue handling).
172
- - Data migration behavior changed: previous-version keys are automatically removed when version > 1.
173
- - Update call sites that relied on prior serialization, error handling, or return semantics.
174
-
175
- Suggested migration steps:
176
- 1. Inspect the new LocalStorageProviderConfig<T> type and adapt object literal passed to the constructor.
177
- 2. Replace old read/write/remove calls with the new method names and signatures.
178
- 3. Ensure stored values match the new serialization expectations (JSON-serializable).
179
- 4. Run tests and rehydrate any persisted data if necessary (previous keys are removed for versions >1).
180
-
181
- ### ✨ Features
182
-
183
- * **local-storage:** add factory function to create LocalStorageProvider with detailed documentation ([eb4a04d](https://github.com/Alwatr/nanolib/commit/eb4a04de84d69497e7489b756c172ed2b0af008d))
184
- * **local-storage:** add static method to check existence of versioned items in localStorage ([8e05938](https://github.com/Alwatr/nanolib/commit/8e059382d085aa691f296b2267a372925868f974))
185
-
186
- ### 🐛 Bug Fixes
187
-
188
- * **local-storage:** correct typo in writeDefault method name ([c0b05c0](https://github.com/Alwatr/nanolib/commit/c0b05c0417ec75e7d9bc57c224380f34472ec467))
189
- * **local-storage:** simplify read method by removing type check for parsed value ([23826ef](https://github.com/Alwatr/nanolib/commit/23826ef70eb22e6f092ba2c6ce11c28b3628f2f2))
190
- * **local-storage:** standardize key naming convention in LocalStorageProvider ([043cf27](https://github.com/Alwatr/nanolib/commit/043cf27881b840d5adeb79ea4a840a15ea23e262))
191
-
192
- ### 🔨 Code Refactoring
193
-
194
- * **local-storage:** complete API rewrite for LocalStorageProvider ([29d01d8](https://github.com/Alwatr/nanolib/commit/29d01d84fbb3ed405ce46d1870d1a929de1c838c))
195
- * **local-storage:** enhance logging in read and write methods for better error tracking ([2cbf404](https://github.com/Alwatr/nanolib/commit/2cbf4042fcef74de016fd1ae80f8263f9de5c610))
196
- * **local-storage:** rename private key variable and update its initialization method ([e25a8ea](https://github.com/Alwatr/nanolib/commit/e25a8ea4a4b75aeac0702fc0a9ef39a5f441e54c))
197
- * **local-storage:** update key generation method to static and enhance documentation ([e36fd53](https://github.com/Alwatr/nanolib/commit/e36fd5355ad4b7fa7b4e629568b9a878ae868c3e))
198
- * **types:** reorganize StorageMeta and LocalStorageProviderConfig interfaces ([d3d001e](https://github.com/Alwatr/nanolib/commit/d3d001ef041ea59981551204d84bee7635cfc192))
199
-
200
- ### 🧹 Miscellaneous Chores
201
-
202
- * add @jest/globals dependency for testing ([a024449](https://github.com/Alwatr/nanolib/commit/a024449366e6b4aa246603528dde6586dda3379e))
203
-
204
- ## [5.5.10](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.9...@alwatr/local-storage@5.5.10) (2025-09-09)
205
-
206
- ### 🧹 Miscellaneous Chores
207
-
208
- * remove trailing newlines from contributing sections in README files ([e8ab1bc](https://github.com/Alwatr/nanolib/commit/e8ab1bc43e0addea5ccd4c897c2cec597cb9e15f))
209
-
210
- ## [5.5.9](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.8...@alwatr/local-storage@5.5.9) (2025-09-06)
211
-
212
- ### 🐛 Bug Fixes
213
-
214
- * support json primitive values ([0af6a75](https://github.com/Alwatr/nanolib/commit/0af6a75881073a586d89666679b1c2e351f48224))
215
-
216
- ### 🔨 Code Refactoring
217
-
218
- * update type definitions for getItem and setItem to use JsonValue for consistency ([140cd09](https://github.com/Alwatr/nanolib/commit/140cd09c4c4cdab480fd2263f387bf9385b497ef))
219
-
220
- ## [5.5.8](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.7...@alwatr/local-storage@5.5.8) (2025-09-05)
221
-
222
- **Note:** Version bump only for package @alwatr/local-storage
223
-
224
- ## [5.5.7](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.6...@alwatr/local-storage@5.5.7) (2025-09-01)
225
-
226
- **Note:** Version bump only for package @alwatr/local-storage
227
-
228
- ## [5.5.6](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.5...@alwatr/local-storage@5.5.6) (2025-08-23)
229
-
230
- **Note:** Version bump only for package @alwatr/local-storage
231
-
232
- ## [5.5.5](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.3...@alwatr/local-storage@5.5.5) (2025-08-23)
233
-
234
- ### 🐛 Bug Fixes
235
-
236
- * update license from AGPL-3.0-only to MPL-2.0 ([d20968e](https://github.com/Alwatr/nanolib/commit/d20968e60cc89b1dcdf9b96507178da6ed562f55))
237
- * update package versions in multiple package.json files ([7638b1c](https://github.com/Alwatr/nanolib/commit/7638b1cafee2b4e0f97db7a89ac9fba6384b9b10))
238
-
239
- ### 🔨 Code Refactoring
240
-
241
- * 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))
242
-
243
- ### 🧹 Miscellaneous Chores
244
-
245
- * reformat all package.json files ([ceda45d](https://github.com/Alwatr/nanolib/commit/ceda45de186667790474f729cb4b161a5148ce19))
246
-
247
- ### 🔗 Dependencies update
248
-
249
- * update TypeScript and Jest versions across all packages to improve compatibility and performance ([31baf36](https://github.com/Alwatr/nanolib/commit/31baf366101e92e27db66a21c849fb101f19be47))
250
-
251
- ## [5.5.4](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.3...@alwatr/local-storage@5.5.4) (2025-08-23)
252
-
253
- ### Code Refactoring
254
-
255
- * 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
256
-
257
- ## <small>5.5.3 (2025-04-15)</small>
258
-
259
- **Note:** Version bump only for package @alwatr/local-storage
260
-
261
- ## [5.5.2](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.1...@alwatr/local-storage@5.5.2) (2025-04-01)
262
-
263
- **Note:** Version bump only for package @alwatr/local-storage
264
-
265
- ## [5.5.1](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.0...@alwatr/local-storage@5.5.1) (2025-03-18)
266
-
267
- **Note:** Version bump only for package @alwatr/local-storage
268
-
269
- ## [5.5.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.4.0...@alwatr/local-storage@5.5.0) (2025-03-06)
270
-
271
- ### Miscellaneous Chores
272
-
273
- * update username casing in changelog entries ([9722ac9](https://github.com/Alwatr/nanolib/commit/9722ac9a078438a4e8ebfa5826ea70e0e3a52ca6)) by @
274
-
275
- ### Dependencies update
276
-
277
- * bump the development-dependencies group across 1 directory with 11 updates ([720c395](https://github.com/Alwatr/nanolib/commit/720c3954da55c929fe8fb16957121f4c51fb7f0c)) by @dependabot[bot]
278
-
279
- ## [5.4.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.8...@alwatr/local-storage@5.4.0) (2025-02-18)
280
-
281
- ## 5.3.0 (2025-02-03)
282
-
283
- ### Features
284
-
285
- * **local-storage:** add setItem after getItem and add hasItem ([a1b845d](https://github.com/Alwatr/nanolib/commit/a1b845d8d9d207b514f9e06c37610220337b0235)) by @
286
-
287
- ### Miscellaneous Chores
288
-
289
- * edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @
290
-
291
- ### Dependencies update
292
-
293
- * bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @
294
- * 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 @
295
-
296
- ## 5.0.0 (2024-11-02)
297
-
298
- ### ⚠ BREAKING CHANGES
299
-
300
- * 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.
301
-
302
- ### Code Refactoring
303
-
304
- * use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
305
-
306
- ## [5.3.0](https://github.com/Alwatr/nanolib/compare/v5.2.1...v5.3.0) (2025-02-03)
307
-
308
- ### Features
309
-
310
- * **local-storage:** add setItem after getItem and add hasItem ([a1b845d](https://github.com/Alwatr/nanolib/commit/a1b845d8d9d207b514f9e06c37610220337b0235)) by @ArmanAsadian
311
-
312
- ### Miscellaneous Chores
313
-
314
- * edit README ([3860b3d](https://github.com/Alwatr/nanolib/commit/3860b3df48ab82dc479d5236c2e8579df614aabf)) by @ArmanAsadian
315
-
316
- ### Dependencies update
317
-
318
- * bump the development-dependencies group across 1 directory with 11 updates ([cb79d07](https://github.com/Alwatr/nanolib/commit/cb79d072a57c79e1c01abff1a293d6757bb65350)) by @dependabot[bot]
319
- * 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
320
-
321
- ## 5.0.0 (2024-11-02)
322
-
323
- ### ⚠ BREAKING CHANGES
324
-
325
- * 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.
326
-
327
- ### Features
328
-
329
- * **local-storage:** If the version is greater than 1, remove the previous version. ([1fdff96](https://github.com/Alwatr/nanolib/commit/1fdff9696a9cf7f1ced0a4c905ea62eb4c422f7a)) by @
330
- * **local-storage:** Rewrite local storage module ([5ed0f39](https://github.com/Alwatr/nanolib/commit/5ed0f39d090c027bb600a5d061ede887b4669198)) by @
331
- * **local-storage:** separate package from `@alwatr/util` ([4cc22ed](https://github.com/Alwatr/nanolib/commit/4cc22eda8d89f291783eef3b8917434489b628e1)) by @
332
- * use `package-tracer` ([cc3c5f9](https://github.com/Alwatr/nanolib/commit/cc3c5f9c1a3d03f0d81b46835665f16a0426fd0d)) by @
333
-
334
- ### Bug Fixes
335
-
336
- * all dependeny topology ([1c17f34](https://github.com/Alwatr/nanolib/commit/1c17f349adf3e98e2a80ab2da4f0f81028dc9c5f)) by @
337
- * **local-storage:** Remove unused dependency and update tsconfig references ([b1caaea](https://github.com/Alwatr/nanolib/commit/b1caaea8565cd497d31d91e4e2ea1becd84a82a4)) by @
338
-
339
- ### Code Refactoring
340
-
341
- * **local-storage:** update removeItem method to use localStorage instead of window.localStorage ([9680a14](https://github.com/Alwatr/nanolib/commit/9680a141a4366d4bb146a73ffcd1bb63dd14f27c)) by @
342
- * prevent side-effects ([01e00e1](https://github.com/Alwatr/nanolib/commit/01e00e191385cc92b28677df0c01a085916ae677)) by @
343
- * use new type-helper global types and remove all import types ([08b5d08](https://github.com/Alwatr/nanolib/commit/08b5d08c03c7c315382337239de0426462f384b8)) by @
344
- * use the same version as @alwatr/nanolib ([60eb860](https://github.com/Alwatr/nanolib/commit/60eb860a0e33dfffe2d1d95e63ce54c60876be06)) by @
345
-
346
- ### Miscellaneous Chores
347
-
348
- * include LICENSE and LEGAL files to publish ([09f366f](https://github.com/Alwatr/nanolib/commit/09f366f680bfa9fb26acb2cd1ccbc68c5a9e9ad8)) by @
349
- * **local-storage:** change the license to AGPL-3.0 ([ef7ea07](https://github.com/Alwatr/nanolib/commit/ef7ea075094c88d90d2ddc6fb9612ae18d792225)) by @
350
- * Update build and lint scripts ([392d0b7](https://github.com/Alwatr/nanolib/commit/392d0b71f446bce336b0256119a80f07aff794ba)) by @
351
- * Update package.json exports for [@alwatr](https://github.com/alwatr) packages ([dacb362](https://github.com/Alwatr/nanolib/commit/dacb362b145e3c51b4aba00ff643687a3fac11d2)) by @
352
-
353
- ### Dependencies update
354
-
355
- * bump the development-dependencies group across 1 directory with 10 updates ([9ed98ff](https://github.com/Alwatr/nanolib/commit/9ed98ffd0668d5a36e255c82edab3af53bffda8f)) by @
356
- * bump the development-dependencies group with 10 updates ([fa4aaf0](https://github.com/Alwatr/nanolib/commit/fa4aaf04c907ecae06aa14000ce35216170c15ad)) by @
357
- * upd ([451d025](https://github.com/Alwatr/nanolib/commit/451d0255ba96ed55f897a6f44f62cf4e6d2b12be)) by @
358
- * update all dependencies ([1e0c30e](https://github.com/Alwatr/nanolib/commit/1e0c30e6a3a8e19deb5185814e24ab6c08dca573)) by @
359
- * update all dependencies ([0e908b4](https://github.com/Alwatr/nanolib/commit/0e908b476a6b976ec2447f864c8cafcbb8a0f099)) by @
360
-
361
- ## [1.1.8](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.7...@alwatr/local-storage@1.1.8) (2024-11-02)
362
-
363
- **Note:** Version bump only for package @alwatr/local-storage
364
-
365
- ## [1.1.7](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.6...@alwatr/local-storage@1.1.7) (2024-10-25)
366
-
367
- ### Code Refactoring
368
-
369
- * **local-storage:** update removeItem method to use localStorage instead of window.localStorage ([9680a14](https://github.com/Alwatr/nanolib/commit/9680a141a4366d4bb146a73ffcd1bb63dd14f27c)) by @alimd
370
-
371
- ## [1.1.6](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.5...@alwatr/local-storage@1.1.6) (2024-10-12)
372
-
373
- **Note:** Version bump only for package @alwatr/local-storage
374
-
375
- ## [1.1.5](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.4...@alwatr/local-storage@1.1.5) (2024-10-11)
376
-
377
- ### Code Refactoring
378
-
379
- - prevent side-effects ([01e00e1](https://github.com/Alwatr/nanolib/commit/01e00e191385cc92b28677df0c01a085916ae677)) by @mohammadhonarvar
380
-
381
- ## [1.1.4](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.3...@alwatr/local-storage@1.1.4) (2024-10-11)
382
-
383
- ### Miscellaneous Chores
384
-
385
- - include LICENSE and LEGAL files to publish ([09f366f](https://github.com/Alwatr/nanolib/commit/09f366f680bfa9fb26acb2cd1ccbc68c5a9e9ad8)) by @alimd
386
-
387
- ## [1.1.3](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.2...@alwatr/local-storage@1.1.3) (2024-10-11)
388
-
389
- **Note:** Version bump only for package @alwatr/local-storage
390
-
391
- ## [1.1.2](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.1...@alwatr/local-storage@1.1.2) (2024-10-10)
392
-
393
- ### Dependencies update
394
-
395
- - bump the development-dependencies group with 10 updates ([fa4aaf0](https://github.com/Alwatr/nanolib/commit/fa4aaf04c907ecae06aa14000ce35216170c15ad)) by @dependabot[bot]
396
-
397
- ## [1.1.1](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.1.0...@alwatr/local-storage@1.1.1) (2024-10-08)
398
-
399
- **Note:** Version bump only for package @alwatr/local-storage
400
-
401
- ## [1.1.0](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.10...@alwatr/local-storage@1.1.0) (2024-09-29)
402
-
403
- ### Features
404
-
405
- - **local-storage:** If the version is greater than 1, remove the previous version. ([1fdff96](https://github.com/Alwatr/nanolib/commit/1fdff9696a9cf7f1ced0a4c905ea62eb4c422f7a)) by @alimd
406
- - use `package-tracer` ([cc3c5f9](https://github.com/Alwatr/nanolib/commit/cc3c5f9c1a3d03f0d81b46835665f16a0426fd0d)) by @mohammadhonarvar
407
-
408
- ### Bug Fixes
409
-
410
- - all dependeny topology ([1c17f34](https://github.com/Alwatr/nanolib/commit/1c17f349adf3e98e2a80ab2da4f0f81028dc9c5f)) by @mohammadhonarvar
411
-
412
- ### Code Refactoring
413
-
414
- - use new type-helper global types and remove all import types ([08b5d08](https://github.com/Alwatr/nanolib/commit/08b5d08c03c7c315382337239de0426462f384b8)) by @alimd
415
-
416
- ### Miscellaneous Chores
417
-
418
- - **local-storage:** change the license to AGPL-3.0 ([ef7ea07](https://github.com/Alwatr/nanolib/commit/ef7ea075094c88d90d2ddc6fb9612ae18d792225)) by @ArmanAsadian
419
- - Update build and lint scripts ([392d0b7](https://github.com/Alwatr/nanolib/commit/392d0b71f446bce336b0256119a80f07aff794ba)) by @alimd
420
-
421
- ## [1.0.10](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.9...@alwatr/local-storage@1.0.10) (2024-09-21)
422
-
423
- **Note:** Version bump only for package @alwatr/local-storage
424
-
425
- ## [1.0.9](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.8...@alwatr/local-storage@1.0.9) (2024-09-15)
426
-
427
- ### Dependencies update
428
-
429
- - bump the development-dependencies group across 1 directory with 10 updates ([9ed98ff](https://github.com/Alwatr/nanolib/commit/9ed98ffd0668d5a36e255c82edab3af53bffda8f)) by @dependabot[bot]
430
-
431
- ## [1.0.8](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.7...@alwatr/local-storage@1.0.8) (2024-08-31)
432
-
433
- ### Miscellaneous Chores
434
-
435
- - Update package.json exports for [@alwatr](https://github.com/alwatr) packages ([dacb362](https://github.com/Alwatr/nanolib/commit/dacb362b145e3c51b4aba00ff643687a3fac11d2)) by @
436
-
437
- ## [1.0.7](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.6...@alwatr/local-storage@1.0.7) (2024-08-31)
438
-
439
- ### Dependencies update
440
-
441
- - update all dependencies ([1e0c30e](https://github.com/Alwatr/nanolib/commit/1e0c30e6a3a8e19deb5185814e24ab6c08dca573)) by @alimd
442
-
443
- ## [1.0.6](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.5...@alwatr/local-storage@1.0.6) (2024-07-04)
444
-
445
- ### Dependencies update
446
-
447
- - update all dependencies ([0e908b4](https://github.com/Alwatr/nanolib/commit/0e908b476a6b976ec2447f864c8cafcbb8a0f099)) by @
448
-
449
- ## [1.0.5](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.4...@alwatr/local-storage@1.0.5) (2024-05-12)
450
-
451
- **Note:** Version bump only for package @alwatr/local-storage
452
-
453
- ## [1.0.4](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.3...@alwatr/local-storage@1.0.4) (2024-04-25)
454
-
455
- **Note:** Version bump only for package @alwatr/local-storage
456
-
457
- ## [1.0.3](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.2...@alwatr/local-storage@1.0.3) (2024-03-28)
458
-
459
- **Note:** Version bump only for package @alwatr/local-storage
460
-
461
- ## [1.0.2](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.1...@alwatr/local-storage@1.0.2) (2024-01-31)
462
-
463
- **Note:** Version bump only for package @alwatr/local-storage
464
-
465
- ## [1.0.1](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@1.0.0...@alwatr/local-storage@1.0.1) (2024-01-24)
466
-
467
- **Note:** Version bump only for package @alwatr/local-storage
468
-
469
- ## 1.0.0 (2024-01-16)
470
-
471
- ### Features
472
-
473
- - **local-storage:** Rewrite local storage module ([5ed0f39](https://github.com/Alwatr/nanolib/commit/5ed0f39d090c027bb600a5d061ede887b4669198)) by @alimd
474
- - **local-storage:** separate package from `@alwatr/util` ([4cc22ed](https://github.com/Alwatr/nanolib/commit/4cc22eda8d89f291783eef3b8917434489b628e1)) by @njfamirm
475
-
476
- ### Bug Fixes
477
-
478
- - **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,4 +0,0 @@
1
- /** 📦 @alwatr/local-storage v7.0.8 */
2
- __dev_mode__: console.debug("📦 @alwatr/local-storage v7.0.8");
3
- "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.8"}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});
4
- //# 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,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-storage v7.0.8");
3
- import{createLogger}from"@alwatr/logger";var LocalStorageProvider=class _LocalStorageProvider{static{this.version="7.0.8"}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};
4
- //# 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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