elm-in-elm / compiler / Elm.Data.ModuleName

Module name, eg. the Foo.Bar in

something =
    Foo.Bar.x + 1


type alias ModuleName =
String

Just a String alias, instead of a type wrapper. We generally use records with explanatory field names where two Strings would be next to each other, to protect against swapping them accidentally.

expectedModuleName : { sourceDirectory : String, filePath : String } -> Maybe ModuleName

Converts from file path to its expected module name. Additionally needs the source directory from elm.json.

Returns Nothing if the source directory doesn't agree with the file path.

expectedModuleName { sourceDirectory = "src", filePath = "src/Foo.elm" }
--> Just "Foo"

expectedModuleName { sourceDirectory = "src", filePath = "lib/Foo.elm" }
--> Nothing