UNPKG

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