food-utils.js 736 B

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * 计算食物来源对应的path
  3. * @param {string} dataSource
  4. * @returns {String}
  5. */
  6. export function getFoodUrl(dataSource = '') {
  7. if (dataSource.indexOf('ENTRY') > -1) {
  8. return '/food/entry'
  9. } else if (dataSource.indexOf('CFCT') > -1) {
  10. return '/food/cfct'
  11. } else {
  12. return '/food'
  13. }
  14. }
  15. /**
  16. * 根据url判断食物来源
  17. * @param url
  18. * @returns {string}
  19. */
  20. export function getFoodSourceByUrl(url = '') {
  21. if (url.indexOf('entry') > -1) {
  22. return 'ENTRY'
  23. } else if (url.indexOf('cfct') > -1) {
  24. return 'CFCT'
  25. } else if (url.indexOf('usda') > -1) {
  26. return 'USDA'
  27. } else {
  28. return ''
  29. }
  30. }
  31. export function isUsda(dataSource) {
  32. return dataSource && dataSource.indexOf('USDA') > -1
  33. }