@streamlayer/sdk-web-storage 0.2.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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # sdk-web-storage
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build sdk-web-storage` to build the library.
package/lib/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export declare class Storage {
2
+ private delimiter;
3
+ private prefix;
4
+ constructor(prefix?: string);
5
+ clear: () => void;
6
+ protected generateKey: (keyParts: string[]) => string;
7
+ protected write: (keyParts_0: string, keyParts_1: string, ...keyParts_2: string[]) => void;
8
+ protected read: (...keyParts: string[]) => string | undefined;
9
+ protected remove: (...keyParts: string[]) => void;
10
+ }
package/lib/index.js ADDED
@@ -0,0 +1,26 @@
1
+ export class Storage {
2
+ delimiter = ':';
3
+ prefix;
4
+ constructor(prefix = 'main') {
5
+ this.prefix = `sl-sdk${this.delimiter}${prefix}`;
6
+ }
7
+ clear = () => {
8
+ for (const key in window.localStorage) {
9
+ if (key.startsWith(this.prefix)) {
10
+ window.localStorage.removeItem(key);
11
+ }
12
+ }
13
+ };
14
+ generateKey = (keyParts) => `${this.prefix}${this.delimiter}${keyParts.join(this.delimiter)}`;
15
+ write = (...keyParts) => {
16
+ const value = keyParts.pop() || '';
17
+ window.localStorage.setItem(this.generateKey(keyParts), value);
18
+ };
19
+ read = (...keyParts) => {
20
+ const value = window.localStorage.getItem(this.generateKey(keyParts));
21
+ return value === null ? undefined : value;
22
+ };
23
+ remove = (...keyParts) => {
24
+ window.localStorage.removeItem(this.generateKey(keyParts));
25
+ };
26
+ }
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@streamlayer/sdk-web-storage",
3
+ "version": "0.2.0",
4
+ "devDependencies": {
5
+ "@nx/playwright": "*",
6
+ "@playwright/test": "*",
7
+ "@nx/webpack": "*",
8
+ "webpack": "*",
9
+ "tslib": "*",
10
+ "url": "*"
11
+ },
12
+ "type": "module",
13
+ "main": "./lib/index.js",
14
+ "typings": "./lib/index.d.ts",
15
+ "files": [
16
+ "lib/",
17
+ "package.json"
18
+ ]
19
+ }