1 // Thanks: https://github.com/capaj/localstorage-polyfill
3 const valuesMap = new Map()
7 [index: number]: string
10 const stringKey = String(key)
11 if (valuesMap.has(key)) {
12 return String(valuesMap.get(stringKey))
18 setItem (key: any, val: any) {
19 valuesMap.set(String(key), String(val))
22 removeItem (key: any) {
31 if (arguments.length === 0) {
32 throw new TypeError('Failed to execute "key" on "Storage": 1 argument required, but only 0 present.')
35 const arr = Array.from(valuesMap.keys())
44 let peertubeLocalStorage: Storage
46 peertubeLocalStorage = localStorage
48 const instance = new MemoryStorage()
50 peertubeLocalStorage = new Proxy(instance, {
51 set: function (obj, prop: string | number, value) {
52 if (MemoryStorage.prototype.hasOwnProperty(prop)) {
53 instance[prop] = value
55 instance.setItem(prop, value)
59 get: function (target, name: string | number) {
60 if (MemoryStorage.prototype.hasOwnProperty(name)) {
63 if (valuesMap.has(name)) {
64 return instance.getItem(name)
70 export { peertubeLocalStorage }