index.js 543 B

12345678910111213141516171819
  1. 'use strict';
  2. var semverRegex = require('semver-regex');
  3. var arrayUniq = require('array-uniq');
  4. module.exports = function (str, opts) {
  5. if (typeof str !== 'string') {
  6. throw new TypeError('Expected a string');
  7. }
  8. opts = opts || {};
  9. var reLoose = new RegExp('(?:' + semverRegex().source + ')|(?:v?(?:\\d+\\.\\d+)(?:\\.\\d+)?)', 'g');
  10. var matches = str.match(opts.loose === true ? reLoose : semverRegex()) || [];
  11. return arrayUniq(matches.map(function (el) {
  12. return el.trim().replace(/^v/, '').replace(/^\d+\.\d+$/, '$&.0');
  13. }));
  14. };