function moduleNameFor
moduleNameFor(file: string): string

The name a file goes into scope under when nobody says what to call it.

Elixir's rule, because it is the one that turns a path into something you can type: test/fixtures/repl-helpers.ts becomes ReplHelpers, and every separator a filename uses to mean a word boundary — -, _, . — becomes a capital letter instead.

A file called index or mod is named for the directory holding it, since a session with three Index objects in it has none.

test/fixtures/repl-helpers.ts -> ReplHelpers lib/repl/index.ts -> Repl the directory, since every folder has an index package.json -> Package

Here rather than in a module of its own: .import and the start-up banner are the only things that ever need a name for a file, and both are in this file. Exported for its own test, which is where the awkward filenames live — a digit first, a name that survives no character of it.

import { moduleNameFor } from './session.ts';

moduleNameFor('test/fixtures/repl-helpers.ts'); // 'ReplHelpers'
moduleNameFor('lib/repl/index.ts'); // 'Repl' — the directory, since every folder has an index
moduleNameFor('package.json'); // 'Package'

Parameters

file: string

Return Type

string

Usage

import { moduleNameFor } from "lib/repl/session.ts";