Files
shields/frontend/lib/pattern-helpers.js
Paul Melnikow d9d8a3b227 Drop-downs for multiple choice in patterns (#2882)
You can see it in effect on the PyPI downloads and the David badges.
2019-02-18 11:15:58 -05:00

15 lines
454 B
JavaScript

// Given a patternToRegex `pattern` with multiple-choice options like
// `foo|bar|baz`, return an array with the options. If it can't be described
// as multiple-choice options, return `undefined`.
const basicChars = /^[A-za-z0-9-]+$/
function patternToOptions(pattern) {
const split = pattern.split('|')
if (split.some(part => !part.match(basicChars))) {
return undefined
} else {
return split
}
}
module.exports = { patternToOptions }