graphics.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import _ from 'lodash'
  2. /* eslint-disable
  3. max-len,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * DS103: Rewrite code to no longer use __guard__
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. import App from '../../../base'
  15. export default App.factory('graphics', function(ide) {
  16. const Graphics = {
  17. getGraphicsFiles() {
  18. const graphicsFiles = []
  19. ide.fileTreeManager.forEachEntity(function(entity, folder, path) {
  20. if (
  21. entity.type === 'file' &&
  22. __guardMethod__(
  23. entity != null ? entity.name : undefined,
  24. 'match',
  25. o => o.match(/.*\.(png|jpg|jpeg|pdf|eps)/i)
  26. )
  27. ) {
  28. const cloned = _.clone(entity)
  29. cloned.path = path
  30. return graphicsFiles.push(cloned)
  31. }
  32. })
  33. return graphicsFiles
  34. }
  35. }
  36. return Graphics
  37. })
  38. function __guardMethod__(obj, methodName, transform) {
  39. if (
  40. typeof obj !== 'undefined' &&
  41. obj !== null &&
  42. typeof obj[methodName] === 'function'
  43. ) {
  44. return transform(obj, methodName)
  45. } else {
  46. return undefined
  47. }
  48. }