parse.js 424 B

1234567891011121314151617181920212223
  1. const { MAX_LENGTH } = require('../internal/constants')
  2. const SemVer = require('../classes/semver')
  3. const parse = (version, options) => {
  4. if (version instanceof SemVer) {
  5. return version
  6. }
  7. if (typeof version !== 'string') {
  8. return null
  9. }
  10. if (version.length > MAX_LENGTH) {
  11. return null
  12. }
  13. try {
  14. return new SemVer(version, options)
  15. } catch (er) {
  16. return null
  17. }
  18. }
  19. module.exports = parse