DEV Community

Richie Bendall
Richie Bendall

Posted on

Coercing an array with semver, sorting it and then reverting it to its pre-coerce counterpart

A problem with semver is that its different functions return different outputs:

const semver = require("semver")


semver.valid("1.0.0")
//=> "1.0.0"

semver.valid(" 1.0.0 ")
//=> null

semver.valid(" v1.0.0 ")
//=> null


semver.clean("1.0.0")
//=> "1.0.0"

semver.clean(" 1.0.0 ")
//=> "1.0.0"

semver.clean(" v1.0.0 ")
//=> null


semver.valid(semver.coerce("1.0.0"))
//=> "1.0.0"

semver.valid(semver.coerce(" 1.0.0 "))
//=> "1.0.0"

Top comments (0)