taiju / ob-deno

Babel Functions for Javascript/TypeScript with Deno.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ob-deno

https://melpa.org/packages/ob-deno-badge.svg

Babel Functions for Javascript/TypeScript with Deno.

ob-deno is based on ob-js. (However, there is no session support.)

Requirements

Installation

ob-deno can be installed from MELPA.

M-x package-install RET ob-deno

Setup

(require 'ob-deno)

(add-to-list 'org-babel-load-languages '(deno . t))
(org-babel-do-load-languages 'org-babel-load-languages org-babel-load-languages)

;; optional (required the typescript.el)
(add-to-list 'org-src-lang-modes '("deno" . typescript))

Customization

M-x customize-group RET ob-deno RET

  • Ob Deno Cmd
  • Ob Deno Variable Prefix

Usage

The results parameter is default value.

#+begin_src deno
const arr = [1, 2, 3];
return arr;
#+end_src

#+RESULTS:
| 1 | 2 | 3 |

The results parameter is output.

#+begin_src deno :results output
const arr = [1, 2, 3];
console.log(arr);
#+end_src

#+RESULTS:
: [ 1, 2, 3 ]

Specify variables.

#+begin_src deno :var foo="bar" baz='("qux")
return {foo, baz};
#+end_src

#+RESULTS:
: { foo: "bar", baz: [ "qux" ] }

Run with --allow-net. (equivalent to deno run --allow-net)

#+begin_src deno :allow net :results output
  const response = await fetch("https://httpbin.org/get?hello=world");
  const json = await response.json();

  console.log(json.args);
#+end_src

#+RESULTS:
: { hello: "world" }

More complex. (equivalent to deno run --allow-net=httpbin.org,example.com --allow-env)

#+begin_src deno :allow '((net . (httpbin.org example.com)) env) :results output
  const response = await fetch(`https://httpbin.org/get?user=${Deno.env.get("USER")}`);
  const json = await response.json();

  console.log(json.args);
#+end_src

#+RESULTS:
: { user: "taiju" }

About

Babel Functions for Javascript/TypeScript with Deno.

License:GNU General Public License v3.0


Languages

Language:Emacs Lisp 100.0%