Function valid

Return the parsed version as a string, or null if it's not valid.

valid('1.2.3') // '1.2.3'
valid('1.2.3-foo.bar+build.12345') // 1.2.3-foo.bar
valid('1.2') // null
  • Parameters

    • version: string

      version string

    • OptionaloptionsOrLoose: boolean | Options

      an options object { loose } (where loose is the only available option) or a boolean indicating whether to enable loose mode. In loose mode, the parser is more forgiving with imperfectly formatted semver strings

    Returns null | string

    the parsed version as a string, or null if it's not valid