@worker-tools/kv-storage
Version:
Picks the platform-specific Storage Area (1,2,3) implementation for Deno, Cloudflare Workers and the browser.
20 lines (16 loc) • 725 B
text/typescript
import * as dntShim from "./_dnt.shims.js";
import type {
StorageArea as IStorageArea, Options, AllowedKey, Key
} from 'kv-storage-interface';
export type { Options, AllowedKey, Key }
import * as dn from '@worker-tools/deno-kv-storage';
import * as cf from '@worker-tools/cloudflare-kv-storage';
import * as br from '@worker-tools/kv-storage-polyfill';
type StorageAreaConstructor = new (name: string, opts?: Options) => IStorageArea;
type StorageAreaClass = StorageAreaConstructor & { prototype: IStorageArea };
export const StorageArea: StorageAreaClass =
'Deno' in dntShim.dntGlobalThis
? dn.StorageArea
: navigator.userAgent?.includes('Cloudflare-Workers')
? cf.StorageArea
: br.StorageArea;