@devbookhq/sdk
Advanced tools
Comparing version 0.1.5 to 1.0.0
{ | ||
"name": "@devbookhq/sdk", | ||
"version": "0.1.5", | ||
"version": "1.0.0", | ||
"description": "Devbook allows visitors of your docs to interact with and execute any code snippet or shell command in a private VM", | ||
@@ -5,0 +5,0 @@ "homepage": "https://usedevbook.com", |
@@ -20,6 +20,6 @@ # Devbook SDK | ||
```tsx | ||
// 1. Import the hook. | ||
// 1. Import the hook | ||
import { useDevbook, Env } from '@devbookhq/sdk' | ||
// 2. Define your code. | ||
// 2. Define your code | ||
const code = ` | ||
@@ -30,7 +30,13 @@ > Code that you want to execute in a VM goes here. | ||
function InteractiveCodeSnippet() { | ||
// 3. Use the hook | ||
const { stdout, stderr, runCode } = useDevbook({ env: Env.NodeJS }) | ||
function handleRun() { | ||
// 4. Execute the code | ||
runCode(code) | ||
} | ||
return ( | ||
<div> | ||
<button onClick={() => runCode(code)}>Run</button> | ||
<button onClick={handleRun}>Run</button> | ||
<h3>Output</h3> | ||
@@ -48,2 +54,3 @@ {stdout.map((o, idx) => <span key={`out_${idx}`}>{o}</span>)} | ||
```ts | ||
// 1. Import the class | ||
import { Devbook, Env } from '@devbookhq/sdk' | ||
@@ -56,13 +63,14 @@ | ||
// 3. Define callbacks. | ||
function handleStdout(out: string) { | ||
console.log('stdout', { err }) | ||
} | ||
// 3. Create new Devbook instance | ||
const dbk = new Devbook({ | ||
env: Env.NodeJS, | ||
onStdout(out) { | ||
console.log('stdout', { err }) | ||
}, | ||
onStderr(err) { | ||
console.log('stderr', { err }) | ||
}, | ||
}) | ||
function handleStderr(err: string) { | ||
console.log('stderr', { err }) | ||
} | ||
// 4. Create new Devbook instance. | ||
const dbk = new Devbook({ env: Env.NodeJS, onStdout: handleStdout, onStderr: handleStderr }) | ||
// 4. Execute the code | ||
dbk.runCode(code) | ||
@@ -69,0 +77,0 @@ ``` |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
320428
2
82