UNPKG

mock-violentmonkey

Version:

Mock violentmonkey's globals for testing userscripts

17 lines 570 B
import { BetterWeakMap } from './utils/index.js'; import { getUserscriptId } from './violentmonkey-context.js'; /** @internal */ class VMStorage { getDefaultValue; storages = new BetterWeakMap(); constructor(getDefaultValue) { this.getDefaultValue = getDefaultValue; } get = setDefault => this.storages.get(getUserscriptId(), (setDefault ? this.getDefaultValue : undefined)); set = (value) => { this.storages.set(getUserscriptId(), value); return this; }; } export { VMStorage }; //# sourceMappingURL=vm-storage.js.map