query
On this page

getLicenseFromSpdxIdOr

lib.meta.getLicenseFromSpdxIdOr

Docs pulled from | This Revision | 14 minutes ago


Get the corresponding attribute in lib.licenses from the SPDX ID or fallback to the given default value.

For SPDX IDs, see https://spdx.org/licenses. Note that some SPDX licenses might be missing.

Inputs

licstr
1. SPDX ID string to find a matching license
default
2. Fallback value when a match is not found

Type

getLicenseFromSpdxIdOr :: str -> Any -> Any

Examples

lib.meta.getLicenseFromSpdxIdOr usage example

lib.getLicenseFromSpdxIdOr "MIT" null == lib.licenses.mit
=> true
lib.getLicenseFromSpdxId "mIt" null == lib.licenses.mit
=> true
lib.getLicenseFromSpdxIdOr "MY LICENSE" lib.licenses.free == lib.licenses.free
=> true
lib.getLicenseFromSpdxIdOr "MY LICENSE" null
=> null
lib.getLicenseFromSpdxIdOr "MY LICENSE" (builtins.throw "No SPDX ID matches MY LICENSE")
=> error: No SPDX ID matches MY LICENSE

Noogle detected

Aliases

Implementation

The following is the current implementation of this function.

getLicenseFromSpdxIdOr =
    let
      lowercaseLicenses = lib.mapAttrs' (name: value: {
        name = lib.toLower name;
        inherit value;
      }) licensesSpdx;
    in licstr: default:
      lowercaseLicenses.${ lib.toLower licstr } or default;