Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # take a path string and resourcePath string and parse into Object
- ```js
- 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))
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement