@alwatr/local-storage 5.5.9 โ 5.5.10
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/CHANGELOG.md +6 -0
- package/README.md +0 -2
- package/dist/main.cjs +2 -2
- package/dist/main.cjs.map +1 -1
- package/dist/main.mjs +2 -2
- package/dist/main.mjs.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [5.5.10](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.9...@alwatr/local-storage@5.5.10) (2025-09-09)
|
|
7
|
+
|
|
8
|
+
### ๐งน Miscellaneous Chores
|
|
9
|
+
|
|
10
|
+
* remove trailing newlines from contributing sections in README files ([e8ab1bc](https://github.com/Alwatr/nanolib/commit/e8ab1bc43e0addea5ccd4c897c2cec597cb9e15f))
|
|
11
|
+
|
|
6
12
|
## [5.5.9](https://github.com/Alwatr/nanolib/compare/@alwatr/local-storage@5.5.8...@alwatr/local-storage@5.5.9) (2025-09-06)
|
|
7
13
|
|
|
8
14
|
### ๐ Bug Fixes
|
package/README.md
CHANGED
|
@@ -67,5 +67,3 @@ The following companies, organizations, and individuals support Nanolib ongoing
|
|
|
67
67
|
### Contributing
|
|
68
68
|
|
|
69
69
|
Contributions are welcome! Please read our [contribution guidelines](https://github.com/Alwatr/.github/blob/next/CONTRIBUTING.md) before submitting a pull request.
|
|
70
|
-
|
|
71
|
-
|
package/dist/main.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @alwatr/local-storage v5.5.
|
|
1
|
+
/* @alwatr/local-storage v5.5.10 */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -25,7 +25,7 @@ __export(main_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(main_exports);
|
|
27
27
|
var import_package_tracer = require("@alwatr/package-tracer");
|
|
28
|
-
__dev_mode__: import_package_tracer.packageTracer.add("@alwatr/local-storage", "5.5.
|
|
28
|
+
__dev_mode__: import_package_tracer.packageTracer.add("@alwatr/local-storage", "5.5.10");
|
|
29
29
|
function parseJson(content) {
|
|
30
30
|
try {
|
|
31
31
|
return JSON.parse(content);
|
package/dist/main.cjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/main.ts"],
|
|
4
4
|
"sourcesContent": ["import {packageTracer} from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\n/**\n * Parse json string without throwing error.\n *\n * @param content - json string\n * @returns json object or null if json is invalid\n * @example\n * ```typescript\n * const json = parseJson('{\"a\":1,\"b\":2}');\n * console.log(json.a); // 1\n * ```\n */\nfunction parseJson<T extends JsonValue>(content: string): T | null {\n try {\n return JSON.parse(content);\n }\n catch (err) {\n console.error('parseJson', 'invalid_json', err);\n return null;\n }\n}\n\n// @TODO: localStorage polyfill (memory fallback)\n\n/**\n * A utility object for working with local storage and JSON data.\n */\nexport const localJsonStorage = {\n /**\n * Generate local storage key.\n *\n * @param name - Name of the item.\n * @param version - Version of the item (default: 1).\n * @returns The generated local storage key.\n * @example\n * ```typescript\n * localJsonStorage.key_('myItem', 1); // myItem.v1\n * ```\n */\n key_(name: string, version = 1): string {\n return `${name}.v${version}`;\n },\n\n /**\n * Get the local storage item and parse it as JSON.\n * If the item is not found, return the default value.\n * If the version is greater than 1, remove the previous version.\n * If the item is not a valid JSON object, return the default value.\n *\n * @param name - The name of the item.\n * @param defaultValue - The default value of the item.\n * @param version - The data structure version of the item (default: 1).\n * @returns The parsed JSON value or the default value if the item is not found.\n * @example\n * ```typescript\n * const value = localJsonStorage.getItem('myItem', {a: 1, b: 2});\n * ```\n */\n getItem<T extends JsonValue>(name: string, defaultValue: T, version = 1): T {\n if (version > 1) {\n this.removeItem(name, version - 1);\n }\n if (version > 1) {\n this.removeItem(name, version - 1);\n }\n const key = this.key_(name, version);\n const value = localStorage.getItem(key);\n if (value === null) {\n localStorage.setItem(key, JSON.stringify(defaultValue));\n return defaultValue;\n }\n const json = parseJson<T>(value);\n if (json === null) return defaultValue;\n return json;\n },\n\n /**\n * Check if an item exists in local storage.\n *\n * @param name - The name of the item.\n * @param version - The version of the item (default: 1).\n * @returns True if the item exists, false otherwise.\n * @example\n * ```typescript\n * const exists = localJsonStorage.hasItem('myItem');\n * ```\n */\n hasItem(name: string, version = 1): boolean {\n const key = this.key_(name, version);\n return localStorage.getItem(key) !== null;\n },\n\n /**\n * Set local storage item as JSON.\n *\n * @param name - Name of the item.\n * @param value - Value of the item.\n * @param version - Version of the item.\n * @example\n * ```typescript\n * localJsonStorage.setItem('myItem', {a: 1, b: 2});\n * ```\n */\n setItem<T extends JsonValue>(name: string, value: T, version = 1): void {\n const key = this.key_(name, version);\n localStorage.setItem(key, JSON.stringify(value));\n },\n\n /**\n * Removes an item from the local storage.\n *\n * @param name - The name of the item to remove.\n * @param version - The version of the item to remove. Default is 1.\n * @example\n * ```typescript\n * localJsonStorage.removeItem('myItem');\n * ```\n */\n removeItem(name: string, version = 1): void {\n const key = this.key_(name, version);\n localStorage.removeItem(key);\n },\n} as const;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA4B;AAE5B,aAAc,qCAAc,IAAI,yBAAkB,
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA4B;AAE5B,aAAc,qCAAc,IAAI,yBAAkB,QAAmB;AAarE,SAAS,UAA+B,SAA2B;AACjE,MAAI;AACF,WAAO,KAAK,MAAM,OAAO;AA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AA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,WAAW,MAAc,UAAU,GAAS;AAC1C,UAAM,MAAM,KAAK,KAAK,MAAM,OAAO;AACnC,iBAAa,WAAW,GAAG;AAAA,EAC7B;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/main.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/* @alwatr/local-storage v5.5.
|
|
1
|
+
/* @alwatr/local-storage v5.5.10 */
|
|
2
2
|
|
|
3
3
|
// src/main.ts
|
|
4
4
|
import { packageTracer } from "@alwatr/package-tracer";
|
|
5
|
-
__dev_mode__: packageTracer.add("@alwatr/local-storage", "5.5.
|
|
5
|
+
__dev_mode__: packageTracer.add("@alwatr/local-storage", "5.5.10");
|
|
6
6
|
function parseJson(content) {
|
|
7
7
|
try {
|
|
8
8
|
return JSON.parse(content);
|
package/dist/main.mjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/main.ts"],
|
|
4
4
|
"sourcesContent": ["import {packageTracer} from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\n/**\n * Parse json string without throwing error.\n *\n * @param content - json string\n * @returns json object or null if json is invalid\n * @example\n * ```typescript\n * const json = parseJson('{\"a\":1,\"b\":2}');\n * console.log(json.a); // 1\n * ```\n */\nfunction parseJson<T extends JsonValue>(content: string): T | null {\n try {\n return JSON.parse(content);\n }\n catch (err) {\n console.error('parseJson', 'invalid_json', err);\n return null;\n }\n}\n\n// @TODO: localStorage polyfill (memory fallback)\n\n/**\n * A utility object for working with local storage and JSON data.\n */\nexport const localJsonStorage = {\n /**\n * Generate local storage key.\n *\n * @param name - Name of the item.\n * @param version - Version of the item (default: 1).\n * @returns The generated local storage key.\n * @example\n * ```typescript\n * localJsonStorage.key_('myItem', 1); // myItem.v1\n * ```\n */\n key_(name: string, version = 1): string {\n return `${name}.v${version}`;\n },\n\n /**\n * Get the local storage item and parse it as JSON.\n * If the item is not found, return the default value.\n * If the version is greater than 1, remove the previous version.\n * If the item is not a valid JSON object, return the default value.\n *\n * @param name - The name of the item.\n * @param defaultValue - The default value of the item.\n * @param version - The data structure version of the item (default: 1).\n * @returns The parsed JSON value or the default value if the item is not found.\n * @example\n * ```typescript\n * const value = localJsonStorage.getItem('myItem', {a: 1, b: 2});\n * ```\n */\n getItem<T extends JsonValue>(name: string, defaultValue: T, version = 1): T {\n if (version > 1) {\n this.removeItem(name, version - 1);\n }\n if (version > 1) {\n this.removeItem(name, version - 1);\n }\n const key = this.key_(name, version);\n const value = localStorage.getItem(key);\n if (value === null) {\n localStorage.setItem(key, JSON.stringify(defaultValue));\n return defaultValue;\n }\n const json = parseJson<T>(value);\n if (json === null) return defaultValue;\n return json;\n },\n\n /**\n * Check if an item exists in local storage.\n *\n * @param name - The name of the item.\n * @param version - The version of the item (default: 1).\n * @returns True if the item exists, false otherwise.\n * @example\n * ```typescript\n * const exists = localJsonStorage.hasItem('myItem');\n * ```\n */\n hasItem(name: string, version = 1): boolean {\n const key = this.key_(name, version);\n return localStorage.getItem(key) !== null;\n },\n\n /**\n * Set local storage item as JSON.\n *\n * @param name - Name of the item.\n * @param value - Value of the item.\n * @param version - Version of the item.\n * @example\n * ```typescript\n * localJsonStorage.setItem('myItem', {a: 1, b: 2});\n * ```\n */\n setItem<T extends JsonValue>(name: string, value: T, version = 1): void {\n const key = this.key_(name, version);\n localStorage.setItem(key, JSON.stringify(value));\n },\n\n /**\n * Removes an item from the local storage.\n *\n * @param name - The name of the item to remove.\n * @param version - The version of the item to remove. Default is 1.\n * @example\n * ```typescript\n * localJsonStorage.removeItem('myItem');\n * ```\n */\n removeItem(name: string, version = 1): void {\n const key = this.key_(name, version);\n localStorage.removeItem(key);\n },\n} as const;\n"],
|
|
5
|
-
"mappings": ";;;AAAA,SAAQ,qBAAoB;AAE5B,aAAc,eAAc,IAAI,yBAAkB,
|
|
5
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AAc,OAAU,UAAU,GAAS;AACtE,UAAM,MAAM,KAAK,KAAK,MAAM,OAAO;AACnC,iBAAa,QAAQ,KAAK,KAAK,UAAU,KAAK,CAAC;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,WAAW,MAAc,UAAU,GAAS;AAC1C,UAAM,MAAM,KAAK,KAAK,MAAM,OAAO;AACnC,iBAAa,WAAW,GAAG;AAAA,EAC7B;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/local-storage",
|
|
3
3
|
"description": "`localJsonStorage` is a utility object in our TypeScript package that provides methods for interacting with the local storage in a structured and versioned manner.",
|
|
4
|
-
"version": "5.5.
|
|
4
|
+
"version": "5.5.10",
|
|
5
5
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
|
|
6
6
|
"bugs": "https://github.com/Alwatr/nanolib/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@alwatr/package-tracer": "5.5.
|
|
8
|
+
"@alwatr/package-tracer": "5.5.10"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@alwatr/nano-build": "6.1.
|
|
12
|
-
"@alwatr/prettier-config": "5.0.
|
|
13
|
-
"@alwatr/tsconfig-base": "6.0.
|
|
14
|
-
"@alwatr/type-helper": "6.0.
|
|
11
|
+
"@alwatr/nano-build": "6.1.1",
|
|
12
|
+
"@alwatr/prettier-config": "5.0.3",
|
|
13
|
+
"@alwatr/tsconfig-base": "6.0.1",
|
|
14
|
+
"@alwatr/type-helper": "6.0.1",
|
|
15
15
|
"typescript": "^5.9.2"
|
|
16
16
|
},
|
|
17
17
|
"exports": {
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
},
|
|
76
76
|
"type": "module",
|
|
77
77
|
"types": "./dist/main.d.ts",
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "cd02a1a9fa579930cd54291ba51ed86241313a6d"
|
|
79
79
|
}
|