| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | const semverRegex = require('semver-regex'); |
| 3 | |
| 4 | module.exports = (stringWithVersions, options = {}) => { |
| 5 | if (typeof stringWithVersions !== 'string') { |
| 6 | throw new TypeError(`Expected a string, got ${typeof stringWithVersions}`); |
| 7 | } |
| 8 | |
| 9 | const reLoose = new RegExp(`(?:${semverRegex().source})|(?:v?(?:\\d+\\.\\d+)(?:\\.\\d+)?)`, 'g'); |
| 10 | const matches = stringWithVersions.match(options.loose === true ? reLoose : semverRegex()) || []; |
| 11 | |
| 12 | return [...new Set(matches.map(match => match.trim().replace(/^v/, '').replace(/^\d+\.\d+$/, '$&.0')))]; |
| 13 | }; |