@alwatr/local-storage 9.33.0 → 9.36.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.
@@ -0,0 +1,5 @@
1
+ /* 📦 @alwatr/local-storage v9.36.0 */
2
+ import{createLogger as z}from"@alwatr/logger";class j{static version="9.36.0";key__;logger_;parse_;stringify_;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),this.parse_=x.parse??JSON.parse,this.stringify_=x.stringify??JSON.stringify}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=this.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=this.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=9E9CE8962586BEB864756E2164756E21
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> {\n public static readonly version = __package_version__;\n\n private readonly key__: string;\n protected readonly logger_;\n protected readonly parse_: (value: string) => T;\n protected readonly stringify_: (value: T) => string;\n\n constructor(config: LocalStorageProviderConfig<T>) {\n this.logger_ = createLogger(`local-storage-provider: ${config.name}, v: ${config.schemaVersion}`);\n DEV_MODE && this.logger_.logMethodArgs?.('constructor', {config});\n this.key__ = LocalStorageProvider.getKey(config);\n LocalStorageProvider.clearPreviousStorageVersions(config);\n\n this.parse_ = config.parse ?? (JSON.parse as (value: string) => T);\n this.stringify_ = config.stringify ?? JSON.stringify;\n }\n\n /**\n * Generates the versioned storage key.\n * @param config - An object containing the name and schemaVersion.\n * @returns The versioned key string.\n */\n public static getKey(config: {name: string; schemaVersion: number}): 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: {name: string; schemaVersion: number}): 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 } catch (err) {\n this.logger_.error('read', 'read_local_storage_error', {err});\n }\n\n if (!value) {\n DEV_MODE && this.logger_.logMethod?.('read//no_value');\n return null;\n }\n\n try {\n const parsedValue = this.parse_(value);\n DEV_MODE && this.logger_.logMethodFull?.('read//value', undefined, {parsedValue});\n return parsedValue;\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 DEV_MODE && this.logger_.logMethodArgs?.('write', {value});\n let valueStr: string;\n try {\n valueStr = this.stringify_(value);\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 } 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>(config: LocalStorageProviderConfig<T>): LocalStorageProvider<T> {\n return new LocalStorageProvider<T>(config);\n}\n"
7
+ ],
8
+ "mappings": ";AAAA,uBAAQ,uBAuBD,MAAM,CAAwB,OACZ,SAAU,SAEhB,MACE,QACA,OACA,WAEnB,WAAW,CAAC,EAAuC,CACjD,KAAK,QAAU,EAAa,2BAA2B,EAAO,YAAY,EAAO,eAAe,EACpF,KAAK,QAAQ,gBAAgB,cAAe,CAAC,QAAM,CAAC,EAChE,KAAK,MAAQ,EAAqB,OAAO,CAAM,EAC/C,EAAqB,6BAA6B,CAAM,EAExD,KAAK,OAAS,EAAO,OAAU,KAAK,MACpC,KAAK,WAAa,EAAO,WAAa,KAAK,gBAQ/B,OAAM,CAAC,EAAuD,CAC1E,MAAO,GAAG,EAAO,SAAS,EAAO,sBAMrB,6BAA4B,CAAC,EAAqD,CAC9F,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,EACvC,MAAO,EAAK,CACZ,KAAK,QAAQ,MAAM,OAAQ,2BAA4B,CAAC,KAAG,CAAC,EAG9D,GAAI,CAAC,EAEH,OADY,KAAK,QAAQ,YAAY,gBAAgB,EAC9C,KAGT,GAAI,CACF,IAAM,EAAc,KAAK,OAAO,CAAK,EAErC,OADY,KAAK,QAAQ,gBAAgB,cAAe,OAAW,CAAC,aAAW,CAAC,EACzE,EACP,MAAO,EAAK,CAEZ,OADA,KAAK,QAAQ,MAAM,OAAQ,mBAAoB,CAAC,KAAG,CAAC,EAC7C,MAOJ,KAAK,CAAC,EAAgB,CACf,KAAK,QAAQ,gBAAgB,QAAS,CAAC,OAAK,CAAC,EACzD,IAAI,EACJ,GAAI,CACF,EAAW,KAAK,WAAW,CAAK,EAChC,MAAO,EAAK,CAEZ,MADA,KAAK,QAAQ,MAAM,QAAS,wBAAyB,CAAC,KAAG,CAAC,EAChD,MAAM,uBAAuB,EAGzC,GAAI,CACF,aAAa,QAAQ,KAAK,MAAO,CAAQ,EACzC,MAAO,EAAK,CACZ,KAAK,QAAQ,MAAM,QAAS,4BAA6B,CAAC,KAAG,CAAC,GAO3D,MAAM,EAAS,CACpB,aAAa,WAAW,KAAK,KAAK,EAEtC,CC/HO,SAAS,CAA6B,CAAC,EAAgE,CAC5G,OAAO,IAAI,EAAwB,CAAM",
9
+ "debugId": "9E9CE8962586BEB864756E2164756E21",
10
+ "names": []
11
+ }
package/dist/main.js CHANGED
@@ -1,5 +1,5 @@
1
- /* 📦 @alwatr/local-storage v9.33.0 */
2
- import{createLogger as z}from"@alwatr/logger";class j{static version="9.33.0";key__;logger_;parse_;stringify_;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),this.parse_=x.parse??JSON.parse,this.stringify_=x.stringify??JSON.stringify}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=this.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=this.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};
1
+ /* 📦 @alwatr/local-storage v9.36.0 */
2
+ import{createLogger as z}from"@alwatr/logger";class j{static version="9.36.0";key__;logger_;parse_;stringify_;constructor(x){this.logger_=z(`local-storage-provider: ${x.name}, v: ${x.schemaVersion}`),this.key__=j.getKey(x),j.clearPreviousStorageVersions(x),this.parse_=x.parse??JSON.parse,this.stringify_=x.stringify??JSON.stringify}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 null;try{return this.parse_(x)}catch(b){return this.logger_.error("read","read_parse_error",{err:b}),null}}write(x){let b;try{b=this.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
3
 
4
- //# debugId=7C84887DD66C7B1064756E2164756E21
4
+ //# debugId=6AB2583D52F0041864756E2164756E21
5
5
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -2,10 +2,10 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/local-storage.provider.ts", "../src/facade.ts"],
4
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> {\n public static readonly version = __package_version__;\n\n private readonly key__: string;\n protected readonly logger_;\n protected readonly parse_: (value: string) => T;\n protected readonly stringify_: (value: T) => string;\n\n constructor(config: LocalStorageProviderConfig<T>) {\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 this.parse_ = config.parse ?? (JSON.parse as (value: string) => T);\n this.stringify_ = config.stringify ?? JSON.stringify;\n }\n\n /**\n * Generates the versioned storage key.\n * @param config - An object containing the name and schemaVersion.\n * @returns The versioned key string.\n */\n public static getKey(config: {name: string; schemaVersion: number}): 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: {name: string; schemaVersion: number}): 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 } 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 = this.parse_(value);\n this.logger_.logMethodFull?.('read//value', undefined, {parsedValue});\n return parsedValue;\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 = this.stringify_(value);\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 } 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",
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> {\n public static readonly version = __package_version__;\n\n private readonly key__: string;\n protected readonly logger_;\n protected readonly parse_: (value: string) => T;\n protected readonly stringify_: (value: T) => string;\n\n constructor(config: LocalStorageProviderConfig<T>) {\n this.logger_ = createLogger(`local-storage-provider: ${config.name}, v: ${config.schemaVersion}`);\n DEV_MODE && this.logger_.logMethodArgs?.('constructor', {config});\n this.key__ = LocalStorageProvider.getKey(config);\n LocalStorageProvider.clearPreviousStorageVersions(config);\n\n this.parse_ = config.parse ?? (JSON.parse as (value: string) => T);\n this.stringify_ = config.stringify ?? JSON.stringify;\n }\n\n /**\n * Generates the versioned storage key.\n * @param config - An object containing the name and schemaVersion.\n * @returns The versioned key string.\n */\n public static getKey(config: {name: string; schemaVersion: number}): 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: {name: string; schemaVersion: number}): 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 } catch (err) {\n this.logger_.error('read', 'read_local_storage_error', {err});\n }\n\n if (!value) {\n DEV_MODE && this.logger_.logMethod?.('read//no_value');\n return null;\n }\n\n try {\n const parsedValue = this.parse_(value);\n DEV_MODE && this.logger_.logMethodFull?.('read//value', undefined, {parsedValue});\n return parsedValue;\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 DEV_MODE && this.logger_.logMethodArgs?.('write', {value});\n let valueStr: string;\n try {\n valueStr = this.stringify_(value);\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 } 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
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>(config: LocalStorageProviderConfig<T>): LocalStorageProvider<T> {\n return new LocalStorageProvider<T>(config);\n}\n"
7
7
  ],
8
- "mappings": ";AAAA,uBAAQ,uBAuBD,MAAM,CAAwB,OACZ,SAAU,SAEhB,MACE,QACA,OACA,WAEnB,WAAW,CAAC,EAAuC,CACjD,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,EAExD,KAAK,OAAS,EAAO,OAAU,KAAK,MACpC,KAAK,WAAa,EAAO,WAAa,KAAK,gBAQ/B,OAAM,CAAC,EAAuD,CAC1E,MAAO,GAAG,EAAO,SAAS,EAAO,sBAMrB,6BAA4B,CAAC,EAAqD,CAC9F,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,EACvC,MAAO,EAAK,CACZ,KAAK,QAAQ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/type.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,MAAM,WAAW,0BAA0B,CAAC,CAAC,GAAG,OAAO;IACrD;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,CAAC;IAE7B;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC;CAClC"}
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,0BAA0B,CAAC,CAAC,GAAG,OAAO;IACrD;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,CAAC;IAE7B;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC;CAClC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alwatr/local-storage",
3
- "version": "9.33.0",
3
+ "version": "9.36.0",
4
4
  "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.",
5
5
  "license": "MPL-2.0",
6
6
  "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
@@ -15,34 +15,37 @@
15
15
  "exports": {
16
16
  ".": {
17
17
  "types": "./dist/main.d.ts",
18
+ "development": "./dist/dev/main.js",
18
19
  "import": "./dist/main.js",
19
20
  "default": "./dist/main.js"
20
21
  }
21
22
  },
22
23
  "sideEffects": false,
23
24
  "dependencies": {
24
- "@alwatr/logger": "9.33.0"
25
+ "@alwatr/logger": "9.36.0"
25
26
  },
26
27
  "devDependencies": {
27
- "@alwatr/nano-build": "9.25.0",
28
+ "@alwatr/nano-build": "9.33.1",
28
29
  "@alwatr/standard": "9.33.0",
29
- "@alwatr/type-helper": "9.14.0",
30
+ "@alwatr/type-helper": "9.36.0",
30
31
  "typescript": "^6.0.3"
31
32
  },
32
33
  "scripts": {
33
34
  "b": "bun run build",
34
35
  "build": "bun run build:ts && bun run build:es",
35
- "build:es": "nano-build --preset=module src/main.ts",
36
+ "build:es": "bun run build:es:dev && bun run build:es:prod",
37
+ "build:es:dev": "nano-build --preset=module --outdir=dist/dev src/main.ts",
38
+ "build:es:prod": "NODE_ENV=production nano-build --preset=module --outdir=dist src/main.ts",
36
39
  "build:ts": "tsc --build",
37
40
  "cl": "bun run clean",
38
41
  "clean": "rm -rfv dist *.tsbuildinfo",
39
42
  "format": "prettier --write \"src/**/*.ts\"",
40
43
  "lint": "eslint src/ --ext .ts",
41
44
  "t": "bun run test",
42
- "test": "ALWATR_DEBUG=0 bun test",
45
+ "test": "bun test",
43
46
  "w": "bun run watch",
44
47
  "watch": "bun run watch:ts & bun run watch:es",
45
- "watch:es": "bun run build:es --watch",
48
+ "watch:es": "bun run build:es:dev --watch",
46
49
  "watch:ts": "bun run build:ts --watch --preserveWatchOutput"
47
50
  },
48
51
  "files": [
@@ -73,5 +76,5 @@
73
76
  "utility",
74
77
  "versioning"
75
78
  ],
76
- "gitHead": "ba7e63efa62c86c7845269f94c4cc9924c38ff21"
79
+ "gitHead": "252426e3bf06fdf5331691d5e8c09a4808104275"
77
80
  }
@@ -31,7 +31,7 @@ export class LocalStorageProvider<T> {
31
31
 
32
32
  constructor(config: LocalStorageProviderConfig<T>) {
33
33
  this.logger_ = createLogger(`local-storage-provider: ${config.name}, v: ${config.schemaVersion}`);
34
- this.logger_.logMethodArgs?.('constructor', {config});
34
+ DEV_MODE && this.logger_.logMethodArgs?.('constructor', {config});
35
35
  this.key__ = LocalStorageProvider.getKey(config);
36
36
  LocalStorageProvider.clearPreviousStorageVersions(config);
37
37
 
@@ -110,13 +110,13 @@ export class LocalStorageProvider<T> {
110
110
  }
111
111
 
112
112
  if (!value) {
113
- this.logger_.logMethod?.('read//no_value');
113
+ DEV_MODE && this.logger_.logMethod?.('read//no_value');
114
114
  return null;
115
115
  }
116
116
 
117
117
  try {
118
118
  const parsedValue = this.parse_(value);
119
- this.logger_.logMethodFull?.('read//value', undefined, {parsedValue});
119
+ DEV_MODE && this.logger_.logMethodFull?.('read//value', undefined, {parsedValue});
120
120
  return parsedValue;
121
121
  } catch (err) {
122
122
  this.logger_.error('read', 'read_parse_error', {err});
@@ -128,7 +128,7 @@ export class LocalStorageProvider<T> {
128
128
  * Serializes and writes a value to localStorage.
129
129
  */
130
130
  public write(value: T): void {
131
- this.logger_.logMethodArgs?.('write', {value});
131
+ DEV_MODE && this.logger_.logMethodArgs?.('write', {value});
132
132
  let valueStr: string;
133
133
  try {
134
134
  valueStr = this.stringify_(value);
package/src/type.ts CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  /**
3
2
  * Configuration options for a local storage provider.
4
3
  */