@fedify/fedify
Version:
An ActivityPub server framework
105 lines (104 loc) • 3.87 kB
JavaScript
import "@js-temporal/polyfill";
import "urlpattern-polyfill";
globalThis.addEventListener = () => {};
import { l as AssertionError, s as format } from "./assert_equals-Ew3jOFa3.mjs";
import "./assert_rejects-B-qJtC9Z.mjs";
import "./assert_throws-4NwKEy2q.mjs";
import "./assert_strict_equals-Dmjbg-bA.mjs";
//#region ../../node_modules/.pnpm/@jsr+std__assert@0.226.0/node_modules/@jsr/std__assert/assert_exists.js
/**
* Make an assertion that actual is not null or undefined.
* If not then throw.
*
* @example Usage
* ```ts no-eval
* import { assertExists } from "@std/assert/assert-exists";
*
* assertExists("something"); // Doesn't throw
* assertExists(undefined); // Throws
* ```
*
* @typeParam T The type of the actual value.
* @param actual The actual value to check.
* @param msg The optional message to include in the error if the assertion fails.
*/ function assertExists(actual, msg) {
if (actual === void 0 || actual === null) {
msg = `Expected actual: "${actual}" to not be null or undefined${msg ? `: ${msg}` : "."}`;
throw new AssertionError(msg);
}
}
//#endregion
//#region ../../node_modules/.pnpm/@jsr+std__assert@0.226.0/node_modules/@jsr/std__assert/assert_greater_or_equal.js
/**
* Make an assertion that `actual` is greater than or equal to `expected`.
* If not then throw.
*
* @example Usage
* ```ts no-eval
* import { assertGreaterOrEqual } from "@std/assert/assert-greater-or-equal";
*
* assertGreaterOrEqual(2, 1); // Doesn't throw
* assertGreaterOrEqual(1, 1); // Doesn't throw
* assertGreaterOrEqual(0, 1); // Throws
* ```
*
* @typeParam T The type of the values to compare.
* @param actual The actual value to compare.
* @param expected The expected value to compare.
* @param msg The optional message to display if the assertion fails.
*/ function assertGreaterOrEqual(actual, expected, msg) {
if (actual >= expected) return;
const actualString = format(actual);
const expectedString = format(expected);
throw new AssertionError(msg ?? `Expect ${actualString} >= ${expectedString}`);
}
//#endregion
//#region ../../node_modules/.pnpm/@jsr+std__assert@0.226.0/node_modules/@jsr/std__assert/assert_greater.js
/**
* Make an assertion that `actual` is greater than `expected`.
* If not then throw.
*
* @example Usage
* ```ts no-eval
* import { assertGreater } from "@std/assert/assert-greater";
*
* assertGreater(2, 1); // Doesn't throw
* assertGreater(1, 1); // Throws
* assertGreater(0, 1); // Throws
* ```
*
* @typeParam T The type of the values to compare.
* @param actual The actual value to compare.
* @param expected The expected value to compare.
* @param msg The optional message to display if the assertion fails.
*/ function assertGreater(actual, expected, msg) {
if (actual > expected) return;
const actualString = format(actual);
const expectedString = format(expected);
throw new AssertionError(msg ?? `Expect ${actualString} > ${expectedString}`);
}
//#endregion
//#region ../../node_modules/.pnpm/@jsr+std__assert@0.226.0/node_modules/@jsr/std__assert/assert_string_includes.js
/**
* Make an assertion that actual includes expected. If not
* then throw.
*
* @example Usage
* ```ts no-eval
* import { assertStringIncludes } from "@std/assert/assert-string-includes";
*
* assertStringIncludes("Hello", "ello"); // Doesn't throw
* assertStringIncludes("Hello", "world"); // Throws
* ```
*
* @param actual The actual string to check for inclusion.
* @param expected The expected string to check for inclusion.
* @param msg The optional message to display if the assertion fails.
*/ function assertStringIncludes(actual, expected, msg) {
if (!actual.includes(expected)) {
msg = `Expected actual: "${actual}" to contain: "${expected}"${msg ? `: ${msg}` : "."}`;
throw new AssertionError(msg);
}
}
//#endregion
export { assertExists as i, assertGreater as n, assertGreaterOrEqual as r, assertStringIncludes as t };