-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert_array.ts
More file actions
29 lines (27 loc) · 775 Bytes
/
assert_array.ts
File metadata and controls
29 lines (27 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright 2023-latest Tomoki Miyauchi. All rights reserved. MIT license.
// This module is browser compatible.
import type { ErrorConstructorLike } from "./types.ts";
/** Assert the input is array.
*
* @param Any input.
*
* @example
* ```ts
* import { assertArray } from "https://deno.land/x/assertion@$VERSION/assert_array.ts";
* import {
* assertFalse,
* assertThrows,
* } from "https://deno.land/std/testing/asserts.ts";
* assertFalse(assertArray([]));
* assertThrows(() => assertArray({}));
* ```
*
* @throws {Error} If the input is not array.
*/
export function assertArray(
input: unknown,
msg?: string,
constructor: ErrorConstructorLike = Error,
): asserts input is unknown[] {
if (!Array.isArray(input)) throw new constructor(msg);
}