jakearchibald / idb

IndexedDB, but with promises
https://www.npmjs.com/package/idb
ISC License
6.2k stars 348 forks source link

How to use it in a REPL? #297

Open siddhsql opened 11 months ago

siddhsql commented 11 months ago

I am new to this library and also indexeddb. Before using it - rather I mean before I write a lot of code using this library, I just want to test it out (test-drive) in a REPL. The library cannot be used in a Node REPL since IndexedDB does not exist in Node. It only exists in browser. And I cannot use it in browser REPL (chrome dev tools) as the import/require does not work. e.g.: this code won't work in chrome dev tools console:

const { openDB, deleteDB, wrap, unwrap } = require( 'idb' );

what is the best way to prototype/test out this library?

jcbhmr commented 11 months ago

You can use something like https://www.jsdelivr.com/esm or https://esm.sh/ to import packages in your browser's DevTools on any page you want! (as long as there's no CSP)

i like to use https://example.org or https://example.com since they have no CSP

let m; m = await import("https://esm.run/idb")
let db; db = await m.openDB("hello-world")

image

if you're more adventurous, you can use a browser-based ide like https://codesandbox.io/ or https://stackblitz.com/ or https://codepen.io/ depending on your needs