Deno cheat sheet v1.24

Testing

deno test [paths...]
Deno.test()

Cli options:

  • To stop on the first failure: --fail-fast.
  • To filter the test you are running: --filter "string or /pattern/

Formatter

deno fmt [files...]

Directives

  • Ignore an entire file:

    • JavaScript: // deno-fmt-ignore-file
    • Markdown: <!-- deno-fmt-ignore-file -->
  • Ignore the preceding code:

    • JavaScript: // deno-fmt-ignore
    • Markdown: <!-- deno-fmt-ignore -->
  • Ignore a markdown section:

    • Start: <!-- deno-fmt-ignore-start -->
    • End: <!-- deno-fmt-ignore-end -->

Configuration

  • Whether to use tabs
    • CLI: --options-use-tabs
    • deno.json: fmt.options.useTabs
    • default: false (use spaces)
  • The width of a line the printer will try to stay under. Note that the printer may exceed this width in certain cases.
    • CLI: --options-line-width
    • deno.json: fmt.options.lineWidth
    • default: 80
  • The number of characters for an indent.
    • CLI: --options-indent-width
    • deno.json: fmt.options.indentWidth
    • default: 2
  • Whether to use single quote.
    • CLI: --options-single-quote
    • deno.json: fmt.options.singleQuote
    • default: false (using double quote)
  • Define how prose should be wrapped in Markdown files.
    • CLI: --options-prose-wrap={always,never,preserve}
    • deno.json: fmt.options.proseWrap
    • default: always

Linter

deno lint [files...]

JavaScript directives

  • Ignore a entire file: // deno-lint-ignore-file
  • Ignore a specific diagnostics in a entire file: // deno-lint-ignore-file <codes...>
  • Ignore certain diagnostics: // deno-lint-ignore <codes...>

Configuration

List of rules

  • List of tag names that will be run. Empty list disables all tags and will only use rules from include.
    • CLI: --rules-tags
    • deno.json: lint.rules.tags
    • default: ["recommended"]
  • List of rule names that will be excluded from configured tag sets. If the same rule is in include it will be run.
    • CLI: --rules-exclude
    • deno.json: lint.rules.exclude
    • default: []
  • List of rule names that will be run. Even if the same rule is in exclude it will be run.
    • CLI: --rules-include
    • deno.json: lint.rules.include
    • default: []

Tasks   unstable

deno task <task> [args...]

Supported syntax

  • Sequential list (if success): command1 && command2
  • Sequential list (if not success) command1 || command2
  • Sequential list (regardless of previous command is success or not): command1 ; command2
  • Async commands: command1 & command2
  • Negate exit code (from 1 to 0): ! command1
  • Copy files: cp
  • Move files: mv
  • Remove files or directories: rm -rf
  • Make directories: mkdir
  • Print the current directory: pwd
  • Delays for a specific amount of time: sleep
  • Display a line of text: echo
  • Causes the shell to exit: exit

Benchmarking   unstable

deno bench [files...]
Deno.bench()

Vendoring

deno vendor <specifiers...>

Deno runtime API

File System

Tools

Resources

FFI (Foreign Function Interface)

Errors

Subprocesses

Runtime utils

Network

Web APIs

Window

Async

Fetch & URLs

Websocket

Web Workers

Message

Performance

Storage

File

TextEncoder

Streams

Compression Streams

Events

Errors

AbortController

CryptoKey

Binary to ASCII

BroadcastChannel

structuredClone

WebAssembly

WebGPU

Standard library

Archive/Tar

Provides a Tar and Untar classes for compressing and decompressing arbitrary data.

Async

Provide help with asynchronous tasks like delays, debouncing, deferring, or pooling.

Bytes

Provides helper functions to manipulate Uint8Array byte slices that are not included on the Uint8Array prototype.

Collections

Functions for specific common tasks around collection types like Array and Record.

Crypto

Extensions to the Web Crypto supporting additional encryption APIs.

Datetime   Browser

Utilities for dealing with Date objects.

Dotenv

Load environment variables from .env files.

Encoding/ascii85   Browser

Encode and decode for Ascii85/base85 encoding.

Encoding/base32   Browser

Encode and decode for base32 encoding.

Encoding/base64   Browser

Encode and decode for base64 encoding.

Encoding/base64 (URL safe)   Browser

Encode and decode for base64 URL safe encoding.

Encoding/binary

Functions for encoding binary data in array buffers.

Encoding/csv (stringify)   Browser

Provides stringify to encode data following the CSV specification.

Encoding/csv

Port of the Go encoding/csv library.

Encoding/front matter

Extract and test functions to handle many forms of front matter.

Encoding/hex   Browser

Port of the Go encoding/hex library.

Encoding/jsonc   Browser

Parse function for parsing JSONC strings.

Encoding/toml   Browser

Parse and stringify for handling TOML encoded data.

Encoding/varint

Functions for encoding typed integers in array buffers.

Encoding/yaml   Browser

Parse and stringify for handling YAML encoded data.

Flags   Browser

Command line arguments parser based on minimist.

Fmt/bytes   Browser

Pretty print bytes.

Fmt/colors   Browser

String formatters and utilities for dealing with ANSI color codes.

Fmt/printf

Sprintf and printf} for printing formatted strings to stdout.

FS

Helpers for working with the filesystem.

HTTP

Provides user-friendly serve on top of Deno's native HTTP server and other utilities for creating HTTP servers and clients.

IO

Utilities for working with Deno's readers, writers, and web streams.

Log

Logging library with the support for terminal and file outputs. Also provides interfaces for building custom loggers.

Media types

Utility functions for media types (MIME types).

Node

Compatibility layer for the Node.js standard library.

Path   Browser

Utilities for working with OS-specific file paths.

Permissions

Helpers for interacting with Deno's permissions system.

Semver   Browser

The semantic version parser. Adapted directly from semver.

Signal

Higher level API for dealing with OS signals.

Streams

Utilities for working with the Streams API. Includes buffering and conversion.

Testing/asserts   Browser

A library of assertion functions.

Testing/bdd

A BDD interface to Deno.test() API.

Testing/mock   Browser

A mocking and spying library.

Testing/snapshot

A snapshotting library.

Testing/time   Browser

Utilities for mocking time while testing.

Textproto

A reader for dealing with low level text based protocols.

UUID   Browser

Generators and validators for UUIDs for versions v1, v4 and v5.