mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-25 10:01:30 -04:00
19 lines
397 B
JavaScript
19 lines
397 B
JavaScript
module.exports = extractUrlVariableName
|
|
|
|
const flatten = require('lodash/flatten')
|
|
|
|
const urlVariableRegex = /\{[^}]+\}/g
|
|
function extractUrlVariableName (url) {
|
|
const matches = url.match(urlVariableRegex)
|
|
|
|
if (!matches) {
|
|
return []
|
|
}
|
|
|
|
return flatten(matches.map(removeNonChars))
|
|
}
|
|
|
|
function removeNonChars (variableName) {
|
|
return variableName.replace(/^\W+|\W+$/g, '').split(/,/)
|
|
}
|