19 lines
385 B
JavaScript
19 lines
385 B
JavaScript
module.exports = extractUrlVariableName
|
|
|
|
const _ = require('lodash')
|
|
|
|
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(/,/)
|
|
}
|