export function assertStringArraysOverlap()

in src/assert.ts [92:133]


export function assertStringArraysOverlap(
  name: string,
  actual: unknown,
  expected: string | string[],
  errorConstructor: AssertionErrorConstructor = FailedAssertionError
): void {
  if (!actual) {
    throw new errorConstructor(
      `Missing ${name}. ${expectationMessage(expected)}`,
      actual,
      expected
    );
  }
  const expectedAsSet = new Set(
    Array.isArray(expected) ? expected : [expected]
  );
  if (typeof actual === "string") {
    actual = [actual];
  }
  if (!Array.isArray(actual)) {
    throw new errorConstructor(`${name} is not an array`, actual, expected);
  }
  const overlaps = actual.some((actualItem) => {
    if (typeof actualItem !== "string") {
      throw new errorConstructor(
        `${name} includes elements that are not of type string`,
        actual,
        expected
      );
    }
    return expectedAsSet.has(actualItem);
  });
  if (!overlaps) {
    throw new errorConstructor(
      `${name} not allowed: ${actual.join(", ")}. ${expectationMessage(
        expected
      )}`,
      actual,
      expected
    );
  }
}