function isModulePath
isModulePath(name: string): boolean

Reports whether a name ends in an extension the runtime will load.

Shared by classification here and by the directory listing in ./target.ts, so "what counts as a module" is answered in one place: a directory refusal that offered names the classifier would then reject would be teaching a form the tool does not accept.

Examples

Every extension the runtime loads counts, and nothing else

import { assertEquals } from "@std/assert";
import { isModulePath } from "./specifier.ts";

assertEquals(isModulePath("mod.ts"), true);
assertEquals(isModulePath("./pkg/mod.mts"), true);
assertEquals(isModulePath("deno.json"), false);
assertEquals(isModulePath("README.md"), false);

Parameters

name: string

A file name or path, e.g. mod.ts or ./pkg/mod.mts.

Return Type

boolean

Whether it ends in a JS/TS module extension.

Usage

import { isModulePath } from "mod.ts";