duncanmalashock / elm-glossary

See all names used in your Elm project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

elm-glossary

See all names used in your Elm project using static analysis

Usage

npm run get-names --source=example: Generates a ./dist/found-names.json file listing all names used in the Elm source files contained in the source directory.

Example

Given the following ./example/Main.elm:

module Main exposing (main)

import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)


type alias Model =
    { count : Int }


init : Model
init =
    { count = 0 }


type Msg
    = Increment
    | Decrement


update : Msg -> Model -> Model
update msg model =
    let
        increment : Int
        increment =
            1
    in
    case msg of
        Increment ->
            { model | count = model.count + increment }

        Decrement ->
            { model | count = model.count - increment }


view : Model -> Html Msg
view model =
    div []
        [ button [ onClick Increment ] [ text "+1" ]
        , div [] [ text <| String.fromInt model.count ]
        , button [ onClick Decrement ] [ text "-1" ]
        ]


main : Program () Model Msg
main =
    Browser.sandbox
        { init = init
        , view = view
        , update = update
        }

The script will produce the following ./dist/found-names.json:

{
  "functions": {
    "increment": 1,
    "init": 1,
    "main": 1,
    "update": 1,
    "view": 1
  },
  "functionArguments": {
    "model": 2,
    "msg": 1
  },
  "types": {
    "Msg": 1
  },
  "typeVariants": {
    "Decrement": 1,
    "Increment": 1
  },
  "typeAliases": {
    "Model": 1
  },
  "typeVariables": {},
  "ports": {}
}

About

See all names used in your Elm project

License:MIT License


Languages

Language:Elm 89.1%Language:JavaScript 10.9%