• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ringcentral / ringcentral-js / 9885902521

11 Jul 2024 05:15AM UTC coverage: 92.878% (-0.6%) from 93.438%
9885902521

push

github

SushilMallRC
Support asynchronous externals.localStorage API

580 of 710 branches covered (81.69%)

Branch coverage included in aggregate %.

7 of 7 new or added lines in 1 file covered. (100.0%)

14 existing lines in 2 files now uncovered.

1924 of 1986 relevant lines covered (96.88%)

41.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.63
/sdk/src/core/Cache.ts
1
import Externals from './Externals';
2

3
export interface CacheOptions {
4
    prefix?: string;
5
    externals: Externals;
6
}
7

8
export default class Cache {
4✔
9
    public static defaultPrefix = 'rc-';
4✔
10

11
    private readonly _prefix = null;
97✔
12

13
    private _externals = null;
97✔
14

15
    public constructor({prefix = Cache.defaultPrefix, externals}: CacheOptions) {
97✔
16
        this._prefix = prefix;
97✔
17
        this._externals = externals;
97✔
18
    }
19

20
    public setItemSync(key, data) {
4✔
UNCOV
21
        this._externals.localStorage.setItem(this._prefixKey(key), JSON.stringify(data));
×
UNCOV
22
        return this;
×
23
    }
24

25
    public async setItem(key, data) {
4✔
26
        await this._externals.localStorage.setItem(this._prefixKey(key), JSON.stringify(data));
326✔
27
        return this; 
163✔
28
        //this.setItemSync(key, data);
29
    }
30

31
    public removeItemSync(key) {
4✔
UNCOV
32
        this._externals.localStorage.removeItem(this._prefixKey(key));
×
UNCOV
33
        return this;
×
34
    }
35

36
    public async removeItem(key) {
4✔
37
        await this._externals.localStorage.removeItem(this._prefixKey(key));
6✔
38
        return this;
3✔
39
        //await this.removeItemSync(key);
40
    }
41

42
    public getItemSync(key) {
4✔
UNCOV
43
        const item = this._externals.localStorage.getItem(this._prefixKey(key));
×
UNCOV
44
        if (!item) {return null;}
×
UNCOV
45
        return JSON.parse(item);
×
46
    }
47

48
    public async getItem(key) {
4✔
49
        const item = await this._externals.localStorage.getItem(this._prefixKey(key));
423✔
50
        if (!item) {return null;}
423✔
51
        return JSON.parse(item);
317✔
52
       // return this.getItemSync(key);
53
    }
54

55
    private async _keys(): Promise<string[]> {
4✔
56
        return 'keys' in this._externals.localStorage
156!
57
            ? this._externals.localStorage.keys() // could be async
58
            : Object.keys(this._externals.localStorage);
59
    }
60

61
    public async clean() {
4✔
62
        await Promise.all(
312✔
63
            (await this._keys()).map(async key => {
156✔
64
                if (key.startsWith(this._prefix)) {
111✔
65
                    await this._externals.localStorage.removeItem(key);
206✔
66
                }
67
            }),
68
        );
69

70
        return this;
156✔
71
    }
72

73
    private _prefixKey(key: string) {
4✔
74
        return this._prefix + key;
589✔
75
    }
76
}
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc