filename.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getCompleteExtname = exports.sanitizeFileName = void 0;
  4. // @ts-ignore
  5. const _sanitizeFileName = require("sanitize-filename");
  6. const path = require("path");
  7. function sanitizeFileName(s) {
  8. return _sanitizeFileName(s);
  9. }
  10. exports.sanitizeFileName = sanitizeFileName;
  11. // Get the filetype from a filename. Returns a string of one or more file extensions,
  12. // e.g. .zip, .dmg, .tar.gz, .tar.bz2, .exe.blockmap. We'd normally use `path.extname()`,
  13. // but it doesn't support multiple extensions, e.g. Foo-1.0.0.dmg.blockmap should be
  14. // .dmg.blockmap, not .blockmap.
  15. function getCompleteExtname(filename) {
  16. let extname = path.extname(filename);
  17. switch (extname) {
  18. // Append leading extension for blockmap filetype
  19. case ".blockmap": {
  20. extname = path.extname(filename.replace(extname, "")) + extname;
  21. break;
  22. }
  23. // Append leading extension for known compressed tar formats
  24. case ".bz2":
  25. case ".gz":
  26. case ".lz":
  27. case ".xz":
  28. case ".7z": {
  29. const ext = path.extname(filename.replace(extname, ""));
  30. if (ext === ".tar") {
  31. extname = ext + extname;
  32. }
  33. break;
  34. }
  35. }
  36. return extname;
  37. }
  38. exports.getCompleteExtname = getCompleteExtname;
  39. //# sourceMappingURL=filename.js.map