graphics.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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', [
  16. 'ide',
  17. function (ide) {
  18. const Graphics = {
  19. getGraphicsFiles() {
  20. const graphicsFiles = []
  21. ide.fileTreeManager.forEachEntity(function (entity, folder, path) {
  22. if (
  23. entity.type === 'file' &&
  24. __guardMethod__(
  25. entity != null ? entity.name : undefined,
  26. 'match',
  27. o => o.match(/.*\.(png|jpg|jpeg|pdf|eps)/i)
  28. )
  29. ) {
  30. const cloned = _.clone(entity)
  31. cloned.path = path
  32. return graphicsFiles.push(cloned)
  33. }
  34. })
  35. return graphicsFiles
  36. },
  37. }
  38. return Graphics
  39. },
  40. ])
  41. function __guardMethod__(obj, methodName, transform) {
  42. if (
  43. typeof obj !== 'undefined' &&
  44. obj !== null &&
  45. typeof obj[methodName] === 'function'
  46. ) {
  47. return transform(obj, methodName)
  48. } else {
  49. return undefined
  50. }
  51. }