PageSourceSearch

https://www.acog.org/scripts/helpers/storagehelper.js?v=20261008053033

js acog.org collected 2026-10-09 23:19:16 UTC 8,934 bytes, 238 lines download raw bytes

1var Helpers;
2(function (Helpers) {
3    class StorageItem {
4        constructor(data) {
5            this.key = data.key;
6            this.value = data.value;
7        }
8    }
9    Helpers.StorageItem = StorageItem;
10    // class for working with local storage in browser (common that can use other classes for store some data)
11    class LocalStorageWorker {
12        constructor() {
13            this.pastExpired = (value) => {
14                if (value) {
15                    const ms = parseInt(value);
16                    return (Date.now() > ms);
17                }
18                return true;
19            };
20            this.timeoutSuffix = "_timeout";
21            this.localStorageSupported = typeof window['localStorage'] != "undefined" && window['localStorage'] != null;
22        }
23        // add value to storage
24        add(key, item) {
25            if (this.localStorageSupported) {
26                localStorage.setItem(key, item);
27            }
28        }
29        addWithTimeout(key, item, secondsToStore) {
30            this.add(key, item);
31            const timeout = (Date.now() + secondsToStore * 1000).toString();
32            this.add(key + this.timeoutSuffix, timeout);
33        }
34        clearExpiredItems() {
35            const keysToClear = new Array();
36            for (let i = 0; i < localStorage.length; i++) {
37                const key = localStorage.key(i);
38                if (key) {
39                    if (Helpers.UtilityHelper.endsWith(key, this.timeoutSuffix, true)) {
40                        const value = localStorage.getItem(key);
41                        if (this.pastExpired(value))
42                            keysToClear.push(key);
43                    }
44                }
45            }
46            if (keysToClear.length > 0)
47                keysToClear.forEach(key => {
48                    const baseKey = key.substr(0, key.indexOf(this.timeoutSuffix));
49                    this.remove(baseKey);
50                });
51        }
52        // get all values from storage (all items)
53        getAllItems() {
54            this.clearExpiredItems();
55            const list = new Array();
56            for (let i = 0; i < localStorage.length; i++) {
57                const key = localStorage.key(i);
58                if (key) {
59                    const value = localStorage.getItem(key);
60                    list.push(new StorageItem({
61                        key: key,
62                        value: value
63                    }));
64                }
65            }
66            return list;
67        }
68        // get only all values from localStorage
69        getAllValues() {
70            this.clearExpiredItems();
71            const list = new Array();
72            for (let i = 0; i < localStorage.length; i++) {
73                const key = localStorage.key(i);
74                if (key) {
75                    const value = localStorage.getItem(key);
76                    list.push(value);
77                }
78            }
79            return list;
80        }
81        // get one item by key from storage
82        get(key) {
83            if (this.localStorageSupported) {
84                const item = localStorage.getItem(key);
85                if (item) {
86                    const timeOutItem = localStorage.getItem(key + this.timeoutSuffix);
87                    if (timeOutItem) {
88                        if (this.pastExpired(timeOutItem)) {
89                            this.remove(key);
90                            return null;
91                        }
92                    }
93                }
94                return item;
95            }
96            else {
97                return null;
98            }
99        }
100        // remove value from storage
101        remove(key) {
102            if (this.localStorageSupported) {
103                localStorage.removeItem(key);
104                localStorage.removeItem(key + this.timeoutSuffix);
105            }
106        }
107        // clear storage (remove all items from it)
108        clear() {
109            if (this.localStorageSupported) {
110                localStorage.clear();
111            }
112        }
113        clearStartingWith(starting) {
114            if (this.localStorageSupported) {
115                const allItems = this.getAllItems();
116                for (let i = 0; i < allItems.length; i++) {
117                    if (allItems[i].key.indexOf(starting) > -1)
118                        this.remove(allItems[i].key);
119                }
120            }
121        }
122    }
123    Helpers.LocalStorageWorker = LocalStorageWorker;
124    class SessionStorageWorker {
125        constructor() {
126            this.pastExpired = (value) => {
127                if (value) {
128                    const ms = parseInt(value);
129                    return (Date.now() > ms);
130                }
131                return true;
132            };
133            this.timeoutSuffix = "_timeout";
134            this.sessionStorageSupported = typeof window['sessionStorage'] != "undefined" && window['sessionStorage'] != null;
135        }
136        // add value to storage
137        add(key, item) {
138            if (this.sessionStorageSupported) {
139                sessionStorage.setItem(key, item);
140            }
141        }
142        addWithTimeout(key, item, secondsToStore) {
143            this.add(key, item);
144            const timeout = (Date.now() + secondsToStore * 1000).toString();
145            this.add(key + this.timeoutSuffix, timeout);
146        }
147        clearExpiredItems() {
148            const keysToClear = new Array();
149            for (let i = 0; i < sessionStorage.length; i++) {
150                const key = sessionStorage.key(i);
151                if (key) {
152                    if (Helpers.UtilityHelper.endsWith(key, this.timeoutSuffix, true)) {
153                        const value = sessionStorage.getItem(key);
154                        if (this.pastExpired(value))
155                            keysToClear.push(key);
156                    }
157                }
158            }
159            if (keysToClear.length > 0)
160                keysToClear.forEach(key => {
161                    const baseKey = key.substr(0, key.indexOf(this.timeoutSuffix));
162                    this.remove(baseKey);
163                });
164        }
165        // get all values from storage (all items)
166        getAllItems() {
167            this.clearExpiredItems();
168            const list = new Array();
169            for (let i = 0; i < sessionStorage.length; i++) {
170                let key = sessionStorage.key(i);
171                if (key) {
172                    const value = sessionStorage.getItem(key);
173                    list.push(new StorageItem({
174                        key: key,
175                        value: value
176                    }));
177                }
178            }
179            return list;
180        }
181        // get only all values from sessionStorage
182        getAllValues() {
183            this.clearExpiredItems();
184            const list = new Array();
185            for (let i = 0; i < sessionStorage.length; i++) {
186                const key = sessionStorage.key(i);
187                if (key) {
188                    const value = sessionStorage.getItem(key);
189                    list.push(value);
190                }
191            }
192            return list;
193        }
194        // get one item by key from storage
195        get(key) {
196            if (this.sessionStorageSupported) {
197                const item = sessionStorage.getItem(key);
198                if (item) {
199                    const timeOutItem = sessionStorage.getItem(key + this.timeoutSuffix);
200                    if (timeOutItem) {
201                        if (this.pastExpired(timeOutItem)) {
202                            this.remove(key);
203                            return null;
204                        }
205                    }
206                }
207                return item;
208            }
209            else {
210                return null;
211            }
212        }
213        // remove value from storage
214        remove(key) {
215            if (this.sessionStorageSupported) {
216                sessionStorage.removeItem(key);
217                sessionStorage.removeItem(key + this.timeoutSuffix);
218            }
219        }
220        // clear storage (remove all items from it)
221        clear() {
222            if (this.sessionStorageSupported) {
223                sessionStorage.clear();
224            }
225        }
226        clearStartingWith(starting) {
227            if (this.sessionStorageSupported) {
228                const allItems = this.getAllItems();
229                for (let i = 0; i < allItems.length; i++) {
230                    if (allItems[i].key.indexOf(starting) > -1)
231                        this.remove(allItems[i].key);
232                }
233            }
234        }
235    }
236    Helpers.SessionStorageWorker = SessionStorageWorker;
237})(Helpers || (Helpers = {}));
238//# sourceMappingURL=StorageHelper.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.