eco-pro / project-metadata-utils / Elm.License

The elm.json for packages always has a "license" field. That field must contain an OSI approved license in the SPDX format.

This module helps verify that licenses are acceptable.

Licenses


type License

An OSI approved license in the SPDX format. It is impossible to construct an invalid License value.

bsd3 : License

Easy access to a license commonly used in the Elm ecosystem.

toDetails : License -> { name : String, spdx : String }

Extract the common name of a License, along with its standardized spdx abbreviation.

toDetails bsd3
-- { name = "BSD 3-clause \"New\" or \"Revised\" License"
-- , spdx = "BSD-3-Clause"
-- }

osiApprovedSpdxLicenses : List License

OSI approved licenses in SPDX format.

String Conversions

toString : License -> String

Convert a License to its SPDX abbreviation:

toString bsd3 == "BSD-3-Clause"

fromString : String -> Maybe License

Convert an arbitrary String into a License:

fromString "BSD-3-Clause" == Just bsd3
fromString "BSD3"         == Nothing

Notice that this function only succeds when given an OSI approved license in its SPDX abbreviation. Go here for a full list of such licenses.

JSON Conversions

encode : License -> Json.Encode.Value

Encode a License into a SPDX string for use in elm.json

decoder : Json.Decode.Decoder License

Decode a SPDX string from elm.json into a License