UNPKG

@fedify/fedify

Version:

An ActivityPub server framework

151 lines (143 loc) 5.47 kB
import { Temporal } from "@js-temporal/polyfill"; import { URLPattern } from "urlpattern-polyfill"; globalThis.addEventListener = () => {}; import { AssertionError, buildMessage, diff, diffStr, format, red } from "./assert_equals-CTYbeopb.js"; //#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) { const msgSuffix = msg ? `: ${msg}` : "."; msg = `Expected actual: "${actual}" to not be null or undefined${msgSuffix}`; 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_strict_equals.js /** * Make an assertion that `actual` and `expected` are equal using * {@linkcode Object.is} for equality comparison. If not, then throw. * * @example Usage * ```ts no-eval * import { assertStrictEquals } from "@std/assert/assert-strict-equals"; * * const a = {}; * const b = a; * assertStrictEquals(a, b); // Doesn't throw * * const c = {}; * const d = {}; * assertStrictEquals(c, d); // Throws * ``` * * @typeParam T The type of the expected value. * @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 assertStrictEquals(actual, expected, msg) { if (Object.is(actual, expected)) return; const msgSuffix = msg ? `: ${msg}` : "."; let message; const actualString = format(actual); const expectedString = format(expected); if (actualString === expectedString) { const withOffset = actualString.split("\n").map((l) => ` ${l}`).join("\n"); message = `Values have the same structure but are not reference-equal${msgSuffix}\n\n${red(withOffset)}\n`; } else { const stringDiff = typeof actual === "string" && typeof expected === "string"; const diffResult = stringDiff ? diffStr(actual, expected) : diff(actualString.split("\n"), expectedString.split("\n")); const diffMsg = buildMessage(diffResult, { stringDiff }).join("\n"); message = `Values are not strictly equal${msgSuffix}\n${diffMsg}`; } throw new AssertionError(message); } //#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)) { const msgSuffix = msg ? `: ${msg}` : "."; msg = `Expected actual: "${actual}" to contain: "${expected}"${msgSuffix}`; throw new AssertionError(msg); } } //#endregion export { assertExists, assertGreater, assertGreaterOrEqual, assertStrictEquals, assertStringIncludes };