import _ from 'lodash/fp'
const convertPath = (event) => {
const path = _.flow(
_.get('path'),
_.split('/')
)(event)
const args = _.flow(
_.get('resourcePath'),
_.split('/'),
_.map(_.replace(/{|}/g, ""))
)(event)
return _.flow(
_.zip(args),
_.map(_.uniq),
_.fromPairs,
_.pickBy(_.identity)
)(path)
}
const event = {
path: '/api/customers/add',
resourcePath: '/api/{model}/{action}'
}
console.log(convertPath(event))
Last active
May 24, 2017 08:28
-
-
Save stukennedy/06c34385d749aa0b83118801f0e4e21d to your computer and use it in GitHub Desktop.
convert a path and resourcePath string into an object of parameters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment