forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInMemoryStorage.ts
More file actions
37 lines (29 loc) · 804 Bytes
/
InMemoryStorage.ts
File metadata and controls
37 lines (29 loc) · 804 Bytes
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
import { IStorage } from './IStorage';
export class InMemoryStorage<T> implements IStorage<T> {
private _items = {};
public save<T>(path:string, value:T):boolean {
this._items[path] = value;
return true;
}
public get(path:string):T {
return this._items[path] || null;
}
public getList(searchPattern?:string, limit?:number):{ path:string, value:T }[] {
var regex = new RegExp(searchPattern || '.*');
var results:{ path:string, value:T }[] = [];
for (var key in this._items) {
if (results.length >= limit) {
break;
}
if (regex.test(key)) {
results.push({ path: key, value: this._items[key] });
}
}
return results;
}
public remove(path:string):void {
if (path) {
delete this._items[path];
}
}
}