Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

parse.js 698B

12345678910111213141516171819202122232425262728293031323334353637
  1. const {MAX_LENGTH} = require('../internal/constants')
  2. const { re, t } = require('../internal/re')
  3. const SemVer = require('../classes/semver')
  4. const parse = (version, options) => {
  5. if (!options || typeof options !== 'object') {
  6. options = {
  7. loose: !!options,
  8. includePrerelease: false
  9. }
  10. }
  11. if (version instanceof SemVer) {
  12. return version
  13. }
  14. if (typeof version !== 'string') {
  15. return null
  16. }
  17. if (version.length > MAX_LENGTH) {
  18. return null
  19. }
  20. const r = options.loose ? re[t.LOOSE] : re[t.FULL]
  21. if (!r.test(version)) {
  22. return null
  23. }
  24. try {
  25. return new SemVer(version, options)
  26. } catch (er) {
  27. return null
  28. }
  29. }
  30. module.exports = parse