ui.file_manager.utils.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * DevExtreme (ui/file_manager/ui.file_manager.utils.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var _iterator = require("../../core/utils/iterator");
  11. var PATH_SEPARATOR = "/";
  12. var getFileExtension = function(path) {
  13. var index = path.lastIndexOf(".");
  14. return index !== -1 ? path.substr(index) : ""
  15. };
  16. var getName = function(path) {
  17. var index = path.lastIndexOf(PATH_SEPARATOR);
  18. return index !== -1 ? path.substr(index + PATH_SEPARATOR.length) : path
  19. };
  20. var getParentPath = function(path) {
  21. var index = path.lastIndexOf(PATH_SEPARATOR);
  22. return index !== -1 ? path.substr(0, index) : ""
  23. };
  24. var getPathParts = function(path, includeFullPath) {
  25. var result = path.split(PATH_SEPARATOR);
  26. if (includeFullPath) {
  27. for (var i = 0; i < result.length; i++) {
  28. result[i] = pathCombine(0 === i ? "" : result[i - 1], result[i])
  29. }
  30. }
  31. return result
  32. };
  33. var pathCombine = function() {
  34. var result = "";
  35. (0, _iterator.each)(arguments, function(_, arg) {
  36. if (arg) {
  37. if (result) {
  38. result += PATH_SEPARATOR
  39. }
  40. result += arg
  41. }
  42. });
  43. return result
  44. };
  45. var getDisplayFileSize = function(byteSize) {
  46. var sizesTitles = ["B", "KB", "MB", "GB", "TB"];
  47. var index = 0;
  48. var displaySize = byteSize;
  49. while (displaySize >= 1024 && index <= sizesTitles.length - 1) {
  50. displaySize /= 1024;
  51. index++
  52. }
  53. displaySize = Math.round(10 * displaySize) / 10;
  54. return "".concat(displaySize, " ").concat(sizesTitles[index])
  55. };
  56. module.exports.getFileExtension = getFileExtension;
  57. module.exports.getName = getName;
  58. module.exports.getParentPath = getParentPath;
  59. module.exports.getPathParts = getPathParts;
  60. module.exports.pathCombine = pathCombine;
  61. module.exports.getDisplayFileSize = getDisplayFileSize;