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

x/dtils/deps.ts

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

Namespaces

A library of assertion functions. If the assertion is false an AssertionError will be thrown which will result in pretty-printed diff of failing assertion.

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

String formatters and utilities for dealing with ANSI color codes.

Utilities for working with OS-specific file paths.

Utilities for working with the Streams API.

Classes

The MuxAsyncIterator class multiplexes multiple async iterators into a single stream. It currently makes an assumption that the final result (the value returned and not yielded from the iterator) does not matter; if there is any result, it is discarded.

A variable-sized buffer of bytes with read() and write() methods.

A transform stream that only transforms from the zero-indexed start and end bytes (both inclusive).

Divide a stream into chunks delimited by a given byte sequence.

A TransformStream that will only read & enqueue size amount of bytes. This operation is chunk based and not BYOB based, and as such will read more than needed.

A TransformStream that will only read & enqueue size amount of chunks.

Transform a stream into a stream where each chunk is divided by a given delimiter.

Transform a stream into a stream where each chunk is divided by a newline, be it \n or \r\n. \r can be enabled via the allowCR option.

Functions

Make an assertion, error will be thrown if expr does not have truthy value.

Make an assertion that actual and expected are almost equal numbers through a given tolerance. It can be used to take into account IEEE-754 double-precision floating-point representation limitations. If the values are not almost equal then throw.

Make an assertion that actual includes the expected values. If not then an error will be thrown.

Make an assertion that actual and expected are equal, deeply. If not deeply equal, then throw.

Make an assertion that actual is not null or undefined. If not then throw.

Make an assertion, error will be thrown if expr have truthy value.

Make an assertion that actual is greater than expected. If not then throw.

Make an assertion that actual is greater than or equal to expected. If not then throw.

Make an assertion that obj is an instance of type. If not then throw.

Make an assertion that error is an Error. If not then an error will be thrown. An error class and a string that should be included in the error message can also be asserted.

Make an assertion that actual is less than expected. If not then throw.

Make an assertion that actual is less than or equal to expected. If not then throw.

Make an assertion that actual match RegExp expected. If not then throw.

Make an assertion that actual and expected are not equal, deeply. If not then throw.

Make an assertion that obj is not an instance of type. If so, then throw.

Make an assertion that actual not match RegExp expected. If match then throw.

Make an assertion that actual and expected are not strictly equal. If the values are strictly equal then throw.

Make an assertion that actual object is a subset of expected object, deeply. If not, then throw.

Executes a function which returns a promise, expecting it to reject.

Make an assertion that actual and expected are strictly equal. If not then throw.

Make an assertion that actual includes expected. If not then throw.

Executes a function, expecting it to throw. If it does not, then it throws.

Deep equality comparison used in assertions

Forcefully throws a failed assertion

Use this to stub out methods that will throw when invoked.

Use this to assert unreachable code.

Make Promise abortable with the given signal.

Make AsyncIterable abortable with the given signal.

Make Promise abortable with the given signal.

Create a promise which will be rejected with DeadlineError when a given delay is exceeded.

Creates a debounced function that delays the given func by a given wait time in milliseconds. If the method is called again before the timeout expires, the previous call will be aborted.

Creates a Promise with the reject and resolve functions placed as methods on the promise object itself.

Resolve a Promise after a given amount of milliseconds.

pooledMap transforms values from an (async) iterable into another async iterable. The transforms are done concurrently, with a max concurrency defined by the poolLimit.

Calls the given (possibly asynchronous) function up to maxAttempts times. Retries as long as the given function throws. If the attempts are exhausted, throws an RetryError with cause set to the inner exception.

Branches the given async iterable into the n branches.

Decodes a given RFC4648 base64 encoded string

Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation

Given an Iterable/Iterator input which yields buffers, returns an IterableIterator which yields sync decoded objects Or, given an Async Iterable/Iterator which yields promises resolving in buffers, returns an AsyncIterableIterator.

Given an Iterable first argument, returns an Iterable where each value is encoded as a Buffer If the argument is only Async Iterable, the return value will be an Async Iterable.

Set background color to black.

Set background color to blue.

Set background color to bright black.

Set background color to bright blue.

Set background color to bright cyan.

Set background color to bright green.

Set background color to bright magenta.

Set background color to bright red.

Set background color to bright white.

Set background color to bright yellow.

Set background color to cyan.

Set background color to green.

Set background color to magenta.

Set background color to red.

Set background color using 24bit rgb. color can be a number in range 0x000000 to 0xffffff or an Rgb.

Set background color using paletted 8bit colors. https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit

Set background color to white.

Set background color to yellow.

Set text color to black.

Set text color to blue.

Make the text bold.

Set text color to bright black.

Set text color to bright blue.

Set text color to bright cyan.

Set text color to bright green.

Set text color to bright magenta.

Set text color to bright red.

Set text color to bright white.

Set text color to bright yellow.

Set text color to cyan.

The text emits only a small amount of light.

Get whether text color change is enabled or disabled.

Set text color to gray.

Set text color to green.

Make the text hidden.

Invert background color and text color.

Make the text italic.

Set text color to magenta.

Set text color to red.

Reset the text modified

Set text color using 24bit rgb. color can be a number in range 0x000000 to 0xffffff or an Rgb.

Set text color using paletted 8bit colors. https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit

Set changing text color to enabled or disabled

Put horizontal line through the center of the text.

Remove ANSI escape codes from the string.

Make the text underline.

Set text color to white.

Set text color to yellow.

Decodes the given hex string to Uint8Array. If the input is malformed, an error will be thrown.

Encodes the source into hex string.

Takes Header, Payload and CryptoKey and returns the url-safe encoded jwt.

Takes a jwt and returns a 3-tuple [unknown, unknown, Uint8Array] if the jwt has a valid serialization. Otherwise it throws an Error. This function does not verify the digital signature.

This helper function simplifies setting a NumericDate. It takes either a Date object or a number (in seconds) and returns the number of seconds from 1970-01-01T00:00:00Z UTC until the specified UTC date/time.

It does not verify the digital signature.

Takes jwt, CryptoKey and VerifyOptions and returns the Payload of the jwt if the jwt is valid. Otherwise it throws an Error.

Return the last portion of a path. Trailing directory separators are ignored, and optional suffix is removed.

Determines the common path from a set of paths, using an optional separator, which defaults to the OS default separator.

Return the directory path of a path.

Return the extension of the path with leading period.

Generate a path from FormatInputPathObject object.

Converts a file URL to a path string.

Convert a glob string to a regular expression.

Verifies whether provided path is absolute

Test whether the given string is a glob

Join all given a sequence of paths,then normalizes the resulting path.

Like join(), but doesn't collapse "**/.." when globstar is true.

Normalize the path, resolving '..' and '.' segments. Note that resolving these segments does not necessarily mean that all will be eliminated. A '..' at the top-level will be preserved, and an empty path is canonically '.'.

Like normalize(), but doesn't collapse "**/.." when globstar is true.

Return a ParsedPath object of the path.

Return the relative path from from to to based on current working directory.

Resolves path segments into a path

Converts a path string to a file URL.

Resolves path to a namespace path

Finds a free port based on the options Requires --allow-net flag

Finds a free port based on the options Requires --allow-net flag

Checks if a port is available Requires --allow-net flag

Checks if a port is available Requires --allow-net flag

Kills running process on a given port Requires --allow-run flag

f
streamUtils.copy
deprecated

Merge multiple streams into a single one, taking order into account, and each stream will wait for a chunk to enqueue before the next stream can append another chunk. If a stream ends before other ones, the others will be cancelled.

Merge multiple streams into a single one, not taking order into account. If a stream ends before other ones, the other will continue adding data, and the finished one will not add any more data.

Convert the generator function into a TransformStream.

Merge multiple streams into a single one, taking order into account, and each stream will wait for a chunk to enqueue before the next stream can append another chunk. If a stream ends before other ones, the others will continue adding data in order, and the finished one will not add any more data.

Interfaces

A debounced function that will be delayed by a given wait time in milliseconds. If the method is called again before the timeout expires, the previous call will be aborted.

JWS §4.1.1: The "alg" value is a case-sensitive ASCII string containing a StringOrURI value. This Header Parameter MUST be present and MUST be understood and processed by implementations.

JWT §1: JWTs encode claims to be transmitted as a JSON [RFC7159] object [...]. JWT §4.1: The following Claim Names are registered in the IANA "JSON Web Token Claims" registry established by Section 10.1. None of the claims defined below are intended to be mandatory to use or implement in all cases, but rather they provide a starting point for a set of useful, interoperable claims. Applications using JWTs should define which specific claims they use and when they are required or optional.

A parsed path object generated by path.parse() or consumed by path.format().

Type Aliases

With expLeeway and nbfLeeway implementers may provide for some small leeway to account for clock skew (JWT §4.1.4). The default is 1 second. By passing the option audience, this application tries to identify the recipient with a value in the aud claim. If the values don't match, an Error is thrown.

Disposition of the delimiter.