Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/dtils/mod.unstable.ts

The best unofficial library of utilities for Deno applications
Go to Latest
import * as dtils from "https://deno.land/x/dtils@2.3.1/mod.unstable.ts";

Classes

c
JsonBody
deprecated

A utility for creating an Md5 hash from a string or Uint8Array.

A utility for creating an Sha256 hash from a string or Uint8Array.

A utility for creating an Sha512 hash from a string or Uint8Array.

Functions

Returns true if arrays are found to match in a shallow-equal test

Bind error recovery to fn, which is expected to be a function. If when the function is later called and errors, recoverWith will be returned instead.

Test, lint, and format check source code in the current working directory

Chooses a random item from the array and returns it

Collect the chunks of stream into an array

Concatenates two strings in such a way that path delimiter attacks cannot occur

Asymmetrically decrypt encryptedBytes using a base64 encoded privateKey. Function will error if privateKey is not an RSA private key

Asymmetrically decrypt encryptedBytes using privateKeyBytes. Function will error if privateKeyBytes is not an RSA public key

Symmetrically decrypt bytes using key, which must be a base64 encoded AES key and prepended 16 byte counter

Symmetrically decrypt bytes using keyBytes, which must be an AES key, with a 16 byte counter prepended

Asymmetrically encrypt plainBytes using a base64 encoded publicKey. Function will error if publicKey is not an RSA public key

Asymmetrically encrypt plainBytes using publicKeyBytes. Function will error if publicKeyBytes is not an RSA public key

Symmetrically encrypt bytes using key, which must be a base64 encoded AES key and prepended 16 byte counter

Symmetrically encrypt bytes using keyBytes, which must be an AES key, with a 16 byte counter prepended

Executes segments as a child process, printing the child's output. Throws if the child exits with a non-zero status

Executes segments as a child process. Returns errorLines and logLines containing all the lines written to the child's stdout and stderr, respectively. Throws if the child exits with a non-zero status.

Executes segments as a child process. Incrementally calls options.onLogLine and options.onErrorLine for each new line written to the child's stdout an stderr, respectively. Throws if the child exits with a non-zero status.

Executes segments as a child process. Throws if the child exits with a non-zero status.

Sets the amount of zeros before a number. If digits is null, there will be no extra digits in front of the number

Run Deno's builtin formatter

Format date using the specified pattern.

Generates a base64 encoded key pair for asymmetric encryptions using the RSA algorithm

Generates a key pair for asymmetric encryptions using the RSA algorithm

Generates a base64 encoded encryption key for symmetric encryptions using the AES algorithm

Generates an encryption key for symmetric encryptions using the AES algorithm

Generates an asymmetric, base64 encoded key pair for signing or encryption purposes

Generates an asymmetric key pair for signing or encryption purposes

Generates a base64 encoded key pair for asymmetric signings using the EC algorithm

Generates a key pair for asymmetric signings using the EC algorithm

Get the current env level ($ENV). Assumes "dev" if invalid or unspecified

Get the current log level ($LOG_LEVEL). Assumes "normal" if invalid or unspecified

Get the current deployment disposition ($DEPLOY). Assumes false if unset, 0, or false

Get the current disposition for reloading dependencies ($RELOAD_DEPS). Assumes false if unset, 0, or false

Get the standard application env vars (ENV, RELOAD_DEPS, DEPLOY, and LOG_LEVEL) as an env object

Hashes a password into a symmetric encryption key for encryptions using the AES algorithm. Function assumes that password and salt are utf characters, not base64

Hashes a password into a symmetric encryption key for encryptions using the AES algorithm

Parse json.

Stringify json with an optional spacer. Wraps the native implementation

f
jsonParse
deprecated
f
jsonStringify
deprecated

Run Deno's builtin linter

Parses a string of query string parameters

Prepends new items onto items

Returns a random number between min and max (both included)

f
readBinary
deprecated

Read a file as a Uint8Array. Returns null if the file doesn't exist

Get all entries in dir. Resulting paths will not include dir

Read a file, parsing it as json. Returns an empty object if the file doesn't exist or can't be parsed.

Read a file, parsing it as json. Returns an empty object if the file doesn't exist. Throws if the json can't be parsed.

Read 1streamintofn, calling fnfor every chunk. Iffn` returns a promise, it will be awaited

Read a file as a string. Returns an empty string if the file doesn't exist.

Recursively read all files in rootDir. Resulting paths will include rootDir

Executes command in default shell, printing the command's output. Throws if command exits with a non-zero status

Executes command in default shell. Returns errorLines and logLines containing all the lines written to stdout and stderr, respectively. Throws if command exits with a non-zero status.

Executes command in default shell. Incrementally calls options.onLogLine and options.onErrorLine for each new line written to stdout an stderr, respectively. Throws if command exits with a non-zero status.

Executes command in default shell. Throws if command exits with a non-zero status.

Creates a digital signature using a base64 encoded EC private key. Note: function will error if the key passed in is not a private key

Creates a digital signature using an EC private key. Note: function will error if the key passed in is not a private key

Slices a string concatenated with concat into an array of sections

Run Deno's builtin test suite

f
validateJson
deprecated

Verifies that signature is from the EC private key corresponding to publicKey. Function will error if publicKey is not a base64 encoded EC public key

Verifies that signature is from the EC private key corresponding to publicKey. Function will error if publicKey is not an EC public key

Call fn, returning its result, but return recoverWith if it errors. If fn doesn't return a promise, use withErrorRecovery instead

Call fn, returning its result, but return recoverWith if it errors. If fn returns a promise, use withAsyncErrorRecovery

Write bytes to file. Creates the directory if it doesn't exist

Write json to file. Creates the directory if it doesn't exist

Write text to file. Creates the directory if it doesn't exist

Type Aliases

Provides a high-level api for standard application env variables (TODO reference blog post of standards)

T
JsonDescriptor
deprecated
T
ValidatorResult
deprecated