Advertisement
Guest User

Untitled

a guest
May 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. # take a path string and resourcePath string and parse into Object
  2.  
  3. ```js
  4. import _ from 'lodash/fp'
  5.  
  6. const convertPath = (event) => {
  7. const path = _.flow(
  8. _.get('path'),
  9. _.split('/')
  10. )(event)
  11. const args = _.flow(
  12. _.get('resourcePath'),
  13. _.split('/'),
  14. _.map(_.replace(/{|}/g, ""))
  15. )(event)
  16. return _.flow(
  17. _.zip(args),
  18. _.map(_.uniq),
  19. _.fromPairs,
  20. _.pickBy(_.identity)
  21. )(path)
  22. }
  23.  
  24. const event = {
  25. path: '/api/customers/add',
  26. resourcePath: '/api/{model}/{action}'
  27. }
  28. console.log(convertPath(event))
  29. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement