forked from authts/oidc-client-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInMemoryWebStorage.ts
More file actions
40 lines (32 loc) · 1.09 KB
/
Copy pathInMemoryWebStorage.ts
File metadata and controls
40 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
import { Logger } from "./utils";
/**
* @public
*/
export class InMemoryWebStorage implements Storage {
private readonly _logger = new Logger("InMemoryWebStorage");
private _data: Record<string, string> = {};
public clear(): void {
this._logger.create("clear");
this._data = {};
}
public getItem(key: string): string {
this._logger.create(`getItem('${key}')`);
return this._data[key];
}
public setItem(key: string, value: string): void {
this._logger.create(`setItem('${key}')`);
this._data[key] = value;
}
public removeItem(key: string): void {
this._logger.create(`removeItem('${key}')`);
delete this._data[key];
}
public get length(): number {
return Object.getOwnPropertyNames(this._data).length;
}
public key(index: number): string {
return Object.getOwnPropertyNames(this._data)[index];
}
}