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

x/hex/src/lib/mod.ts

An ecosystem delivering practices, philosophy and portability. Powered By Deno and JavaScript.
Latest
import * as hex from "https://deno.land/x/hex@0.6.5/src/lib/mod.ts";

Namespaces

Utilities for dealing with Date objects.

Load environment variables from .env files. Inspired by the node module dotenv and dotenv-expand.

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

Command line arguments parser based on minimist.

Pretty print bytes.

String formatters and utilities for dealing with ANSI color codes.

Format milliseconds to time duration.

sprintf and printf for printing formatted strings to stdout.

Helpers for working with the filesystem.

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

Utilities for working with OS-specific file paths.

The semantic version parser.

Utilities for working with the Streams API.

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.

A BDD interface to Deno.test() API.

A mocking and spying library.

A snapshotting library.

Utilities for mocking time while testing.

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

Classes

An object that encapsulates provided message and arguments as well some metadata that can be later used when formatting a message.

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

An error related to spying on a function or instance method.

Overrides the real Date object and timer functions with fake ones that can be controlled through the fake time instance.

An error related to faking time.

Enums

Platform-specific conventions for the line ending format (i.e., the "end-of-line").

Get log level numeric values through enum constants. Defaults to INFO.

Variables

The number of milliseconds in a day.

The number of milliseconds in an hour.

The number of milliseconds in a minute.

The number of milliseconds in a second.

The number of milliseconds in a week.

Handlers are responsible for actual output of log messages. When a handler is called by a logger, it firstly checks that LogRecord's level is not lower than level of the handler. If level check passes, handlers formats log record into string and outputs it to target.

Functions

Returns the number of the day in the year.

Returns the difference of the 2 given dates in the given units. If the units are omitted, it returns the difference in the all available units.

Takes an input date and a formatString to format to a string.

Returns whether the given date or year (in number) is a leap year or not. based on: https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-a-leap-year

Takes an input string and a formatString to parse to a date.

Formats the given date to IMF date time format. (Reference: https://tools.ietf.org/html/rfc7231#section-7.1.1.1). IMF is the time format to use when generating times in HTTP headers. The time being formatted must be in UTC for Format to generate the correct format.

Returns the ISO week number of the provided date (1-53).

Check if the passed UUID is the nil UUID.

Generates a RFC4122 v1 UUID (time-based).

Validates the UUID v1.

Validate that the passed UUID is an RFC4122 v4 UUID.

Generate a RFC4122 v5 UUID (SHA-1 namespace).

Validate that the passed UUID is an RFC4122 v5 UUID.

Test a string to see if it is a valid UUID.

Detect RFC version of a UUID.

Take a set of command line arguments, optionally with a set of options, and return an object representing the flags found in the passed arguments.

Convert bytes to a human-readable string: 1337 → 1.34 kB

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.

Converts and format a variable number of args as is specified by format. printf writes the formatted string to standard output.

Converts and format a variable number of args as is specified by format. sprintf returns the formatted string.

Copy a file or directory. The directory can have contents. Like cp -r. Requires the --allow-read and --allow-write flag.

Copy a file or directory. The directory can have contents. Like cp -r. Requires the --allow-read and --allow-write flag.

Detect the EOL character for string input. returns null if no newline.

Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted. Requires the --allow-read and --allow-write flag.

Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted. Requires the --allow-read and --allow-write flag.

Ensures that the directory exists. If the directory structure does not exist, it is created. Like mkdir -p. Requires the --allow-read and --allow-write flag.

Ensures that the directory exists. If the directory structure does not exist, it is created. Like mkdir -p. Requires the --allow-read and --allow-write flag.

Ensures that the file exists. If the file that is requested to be created is in directories that do not exist. these directories are created. If the file already exists, it is NOTMODIFIED. Requires the --allow-read and --allow-write flag.

Ensures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is NOT MODIFIED. Requires the --allow-read and --allow-write flag.

Ensures that the hard link exists. If the directory structure does not exist, it is created.

Ensures that the hard link exists. If the directory structure does not exist, it is created.

Ensures that the link exists. If the directory structure does not exist, it is created.

Ensures that the link exists. If the directory structure does not exist, it is created.

f
stdx.fs.exists
deprecated

Test whether or not the given path exists by checking with the file system.

Test whether or not the given path exists by checking with the file system.

Expand the glob string from the specified root directory and yield each result as a WalkEntry object.

Synchronous version of expandGlob().

Format the file to the targeted EOL.

Moves a file or directory.

Moves a file or directory synchronously.

Walks the file tree rooted at root, yielding each file or directory in the tree filtered according to the given options.

Same as walk() but uses synchronous ops

Log with critical level, using default logger.

Log with debug level, using default logger.

Log with error level, using default logger.

Get a logger instance. If not specified name, get the default logger.

Log with info level, using default logger.

Setup logger config.

Log with warning level, using default logger.

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

Convert a glob string to a regular expression.

Test whether the given string is a glob

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

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

Pass in a comparison string, and it'll call the corresponding comparison function. "===" and "!==" do simple string comparison, but are included for completeness. Throws if an invalid comparison string is provided.

Returns 0 if v1 == v2, or 1 if v1 is greater, or -1 if v2 is greater. Sorts in ascending order if passed to Array.sort(),

The same as compare but considers build when two versions are equal. Sorts in ascending order if passed to Array.sort().

Returns difference between two versions by the release type (major, premajor, minor, preminor, patch, prepatch, or prerelease), or null if the versions are the same.

This is true if they're logically equivalent, even if they're not the exact same string.

Greater than comparison

Greater than or equal comparison

Returns true if version is greater than all the versions possible in the range.

Returns the version incremented by the release type (major, minor, patch, or prerelease), or null if it's not valid.

Returns true if the two supplied ranges or comparators intersect.

Less than comparison

Less than or equal comparison

Returns true if version is less than all the versions possible in the range.

Returns the major version number.

Returns the highest version in the list that satisfies the range, or null if none of them do.

Returns the minor version number.

Returns the lowest version in the list that satisfies the range, or null if none of them do.

Returns the lowest version that can possibly match the given range.

This is true if they're not logically equivalent, even if they're the exact same string.

Returns true if the version is outside the bounds of the range in either the high or low direction. The hilo argument must be either the string '>' or '<'. (This is the function called by gtr and ltr.)

Attempt to parse a string as a semantic version, returning either a SemVer object or null.

Returns the patch version number.

Returns an array of prerelease components, or null if none exist.

Returns 0 if v1 == v2, or -1 if v1 is greater, or 1 if v2 is greater. Sorts in descending order if passed to Array.sort(),

Returns true if the version satisfies the range.

Returns the parsed version, or null if it's not valid.

Returns the valid range or null if it's not valid.

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 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 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.

Run some shared teardown after all of the tests in the suite.

Run some shared teardown after each test in the suite.

Run some shared setup before all of the tests in the suite.

Run some shared setup before each test in the suite.

Registers a test suite.

Registers an individual test case.

Asserts that a spy is called as expected.

Asserts that a spy is called with a specific arg as expected.

Asserts that an spy is called with a specific range of args as expected. If a start and end index is not provided, the expected will be compared against all args. If a start is provided without an end index, the expected will be compared against all args from the start index to the end. The end index is not included in the range of args that are compared.

Asserts that an async spy is called as expected.

Asserts that a spy is called as much as expected and no more.

Creates a session that tracks all mocks created before it's restored. If a callback is provided, it restores all mocks created within it.

Creates an async session that tracks all mocks created before the promise resolves.

Creates a function that resolves the awaited iterable values. Any awaited iterable values that are errors will be thrown.

Restores all mocks registered in the current session that have not already been restored. If an id is provided, it will restore all mocks registered in the session associed with that id that have not already been restored.

Creates a function that returns one of its arguments.

Creates a function that returns its arguments or a subset of them. If end is specified, it will return arguments up to but not including the end.

Creates a function that returns the iterable values. Any iterable values that are errors will be thrown.

Creates a function that returns the instance the method was called on.

Wraps a function or instance method with a Spy.

Replaces an instance method with a Stub.

Make an assertion that actual matches a snapshot. If the snapshot and actual do not a match, then throw.

Default serializer for assertSnapshot.

Check if the passed UUID is the nil UUID.

Generates a RFC4122 v1 UUID (time-based).

Validates the UUID v1.

Validate that the passed UUID is an RFC4122 v4 UUID.

Generate a RFC4122 v5 UUID (SHA-1 namespace).

Validate that the passed UUID is an RFC4122 v5 UUID.

Test a string to see if it is a valid UUID.

Detect RFC version of a UUID.

Interfaces

The options used for generating a v1 UUID.

The options for the parse call.

The options for pretty printing the byte numbers.

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

Registers a test suite.

The options for creating a test suite with the describe function.

Registers an individual test case.

The options for creating an individual test case with the it function.

A group of tests.

Call information recorded by a spy.

A function or instance method wrapper that records all calls made to it.

Call information recorded by a spy.

An instance method replacement that records all calls made to it.

The options used for generating a v1 UUID.

Type Aliases

The value returned from parse.

Union of valid log level strings

The semantic version parser.

The arguments for a DescribeFunction.

The arguments for an ItFunction.