@openforis/arena-core 2.16.11 → 2.16.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dataExport/UniqueFileNamesGenerator.d.ts +3 -0
- package/dist/dataExport/UniqueFileNamesGenerator.js +14 -8
- package/dist/dataExport/UniqueFileNamesGenerator.js.map +1 -1
- package/dist/esm/dataExport/UniqueFileNamesGenerator.js +14 -8
- package/dist/esm/dataExport/UniqueFileNamesGenerator.js.map +1 -1
- package/dist/esm/utils/fileNames.js +4 -3
- package/dist/esm/utils/fileNames.js.map +1 -1
- package/dist/utils/fileNames.js +4 -3
- package/dist/utils/fileNames.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,10 @@ import { Dictionary } from '../common';
|
|
|
2
2
|
export declare class UniqueFileNamesGenerator {
|
|
3
3
|
private _fileNamesByKey;
|
|
4
4
|
private _keysByFileName;
|
|
5
|
+
private readonly _fileNamesLowerCase;
|
|
5
6
|
constructor();
|
|
7
|
+
private isFileNameUsed;
|
|
8
|
+
private assignFileName;
|
|
6
9
|
/**
|
|
7
10
|
* Generates a unique file name for the given key.
|
|
8
11
|
*
|
|
@@ -7,6 +7,16 @@ class UniqueFileNamesGenerator {
|
|
|
7
7
|
constructor() {
|
|
8
8
|
this._fileNamesByKey = {};
|
|
9
9
|
this._keysByFileName = {};
|
|
10
|
+
this._fileNamesLowerCase = new Set();
|
|
11
|
+
}
|
|
12
|
+
isFileNameUsed(fileName) {
|
|
13
|
+
return this._fileNamesLowerCase.has(fileName.toLowerCase());
|
|
14
|
+
}
|
|
15
|
+
assignFileName(fileName, key) {
|
|
16
|
+
this._keysByFileName[fileName] = key;
|
|
17
|
+
this._fileNamesByKey[key] = fileName;
|
|
18
|
+
this._fileNamesLowerCase.add(fileName.toLowerCase());
|
|
19
|
+
return fileName;
|
|
10
20
|
}
|
|
11
21
|
/**
|
|
12
22
|
* Generates a unique file name for the given key.
|
|
@@ -29,20 +39,16 @@ class UniqueFileNamesGenerator {
|
|
|
29
39
|
if (existingFileName) {
|
|
30
40
|
return existingFileName;
|
|
31
41
|
}
|
|
32
|
-
if (!this.
|
|
42
|
+
if (!this.isFileNameUsed(inputFileName)) {
|
|
33
43
|
// file name not used yet
|
|
34
|
-
this.
|
|
35
|
-
this._fileNamesByKey[key] = inputFileName;
|
|
36
|
-
return inputFileName;
|
|
44
|
+
return this.assignFileName(inputFileName, key);
|
|
37
45
|
}
|
|
38
46
|
let generatedFileName = this.generateNextFileName(inputFileName);
|
|
39
|
-
while (this.
|
|
47
|
+
while (this.isFileNameUsed(generatedFileName)) {
|
|
40
48
|
// file name already exists, generate the next one
|
|
41
49
|
generatedFileName = this.generateNextFileName(generatedFileName);
|
|
42
50
|
}
|
|
43
|
-
this.
|
|
44
|
-
this._fileNamesByKey[key] = generatedFileName;
|
|
45
|
-
return generatedFileName;
|
|
51
|
+
return this.assignFileName(generatedFileName, key);
|
|
46
52
|
}
|
|
47
53
|
/**
|
|
48
54
|
* Generates a new file name by incrementing an existing numeric suffix
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UniqueFileNamesGenerator.js","sourceRoot":"","sources":["../../src/dataExport/UniqueFileNamesGenerator.ts"],"names":[],"mappings":";;;AACA,oCAAoC;AAEpC,MAAM,kBAAkB,GAAG,kBAAkB,CAAA,CAAC,mCAAmC;AAEjF;
|
|
1
|
+
{"version":3,"file":"UniqueFileNamesGenerator.js","sourceRoot":"","sources":["../../src/dataExport/UniqueFileNamesGenerator.ts"],"names":[],"mappings":";;;AACA,oCAAoC;AAEpC,MAAM,kBAAkB,GAAG,kBAAkB,CAAA,CAAC,mCAAmC;AAEjF;IAME;QACE,IAAI,CAAC,eAAe,GAAG,EAAE,CAAA;QACzB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAA;QACzB,IAAI,CAAC,mBAAmB,GAAG,IAAI,GAAG,EAAE,CAAA;IACtC,CAAC;IAEO,cAAc,CAAC,QAAgB;QACrC,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AI,WAAW,CAAA;QACf,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC9C,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,CAAC,EAAE,gBAAgB,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAA;YAC5C,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACnC,WAAW,GAAG,GAAG,gBAAgB,KAAK,SAAS,GAAG,CAAA;QACpD,CAAC;aAAM,CAAC;YACN,WAAW,GAAG,GAAG,IAAI,MAAM,CAAA;QAC7B,CAAC;QACD,OAAO,SAAS,CAAC,CAAC,CAAC,GAAG,WAAW,IAAI,SAAS,EAAE,CAAC,CAAC,CAAC,WAAW,CAAA;IAChE,CAAC;IAED,IAAI,cAAc;QAChB,yBAAY,IAAI,CAAC,eAAe,EAAE;IACpC,CAAC;IAED,IAAI,cAAc;QAChB,yBAAY,IAAI,CAAC,eAAe,EAAE;IACpC,CAAC;CACF","sourcesContent":["import { Dictionary } from '../common'\nimport { FileNames } from '../utils'\n\nconst nameWithIndexRegEx = /^(.*) \\((\\d+)\\)$/ // file name like \"example (1).txt\"\n\nexport class UniqueFileNamesGenerator {\n private _fileNamesByKey: Dictionary<string>\n private _keysByFileName: Dictionary<string>\n // file names are compared ignoring case: names differing only in case overwrite each other on Windows/macOS\n private readonly _fileNamesLowerCase: Set<string>\n\n constructor() {\n this._fileNamesByKey = {}\n this._keysByFileName = {}\n this._fileNamesLowerCase = new Set()\n }\n\n private isFileNameUsed(fileName: string): boolean {\n return this._fileNamesLowerCase.has(fileName.toLowerCase())\n }\n\n private assignFileName(fileName: string, key: string): string {\n this._keysByFileName[fileName] = key\n this._fileNamesByKey[key] = fileName\n this._fileNamesLowerCase.add(fileName.toLowerCase())\n return fileName\n }\n\n /**\n * Generates a unique file name for the given key.\n *\n * If the key has been used before, the previously generated file name\n * associated with that key is returned, regardless of the current\n * {@link inputFileName} value.\n *\n * If the key has not been used before, the method either:\n * - returns {@link inputFileName} if it has not been used for another key, or\n * - generates the next available non-conflicting name by appending or\n * incrementing a numeric index in parentheses.\n *\n * @param inputFileName The desired base file name, including extension.\n * @param key A logical identifier whose associated file name should remain stable across calls.\n * @returns The unique file name associated with the given key.\n */\n generateUniqueFileName(inputFileName: string, key: string): string {\n const existingFileName = this._fileNamesByKey[key]\n if (existingFileName) {\n return existingFileName\n }\n if (!this.isFileNameUsed(inputFileName)) {\n // file name not used yet\n return this.assignFileName(inputFileName, key)\n }\n let generatedFileName = this.generateNextFileName(inputFileName)\n while (this.isFileNameUsed(generatedFileName)) {\n // file name already exists, generate the next one\n generatedFileName = this.generateNextFileName(generatedFileName)\n }\n return this.assignFileName(generatedFileName, key)\n }\n\n /**\n * Generates a new file name by incrementing an existing numeric suffix\n * of the form \"name (n)\" or appending \" (1)\" if no such suffix exists.\n *\n * @param inputFileName The original file name, including its extension.\n * @returns The updated file name with an incremented or newly added numeric suffix.\n */\n protected generateNextFileName(inputFileName: string): string {\n const name = FileNames.getName(inputFileName)\n const extension = FileNames.getExtension(inputFileName)\n let nameUpdated\n const matchRes = nameWithIndexRegEx.exec(name)\n if (matchRes) {\n const [, nameWithoutIndex, index] = matchRes\n const nextIndex = Number(index) + 1\n nameUpdated = `${nameWithoutIndex} (${nextIndex})`\n } else {\n nameUpdated = `${name} (1)`\n }\n return extension ? `${nameUpdated}.${extension}` : nameUpdated\n }\n\n get fileNamesByKey(): Readonly<Dictionary<string>> {\n return { ...this._fileNamesByKey }\n }\n\n get keysByFileName(): Readonly<Dictionary<string>> {\n return { ...this._keysByFileName }\n }\n}\n"]}
|
|
@@ -4,6 +4,16 @@ export class UniqueFileNamesGenerator {
|
|
|
4
4
|
constructor() {
|
|
5
5
|
this._fileNamesByKey = {};
|
|
6
6
|
this._keysByFileName = {};
|
|
7
|
+
this._fileNamesLowerCase = new Set();
|
|
8
|
+
}
|
|
9
|
+
isFileNameUsed(fileName) {
|
|
10
|
+
return this._fileNamesLowerCase.has(fileName.toLowerCase());
|
|
11
|
+
}
|
|
12
|
+
assignFileName(fileName, key) {
|
|
13
|
+
this._keysByFileName[fileName] = key;
|
|
14
|
+
this._fileNamesByKey[key] = fileName;
|
|
15
|
+
this._fileNamesLowerCase.add(fileName.toLowerCase());
|
|
16
|
+
return fileName;
|
|
7
17
|
}
|
|
8
18
|
/**
|
|
9
19
|
* Generates a unique file name for the given key.
|
|
@@ -26,20 +36,16 @@ export class UniqueFileNamesGenerator {
|
|
|
26
36
|
if (existingFileName) {
|
|
27
37
|
return existingFileName;
|
|
28
38
|
}
|
|
29
|
-
if (!this.
|
|
39
|
+
if (!this.isFileNameUsed(inputFileName)) {
|
|
30
40
|
// file name not used yet
|
|
31
|
-
this.
|
|
32
|
-
this._fileNamesByKey[key] = inputFileName;
|
|
33
|
-
return inputFileName;
|
|
41
|
+
return this.assignFileName(inputFileName, key);
|
|
34
42
|
}
|
|
35
43
|
let generatedFileName = this.generateNextFileName(inputFileName);
|
|
36
|
-
while (this.
|
|
44
|
+
while (this.isFileNameUsed(generatedFileName)) {
|
|
37
45
|
// file name already exists, generate the next one
|
|
38
46
|
generatedFileName = this.generateNextFileName(generatedFileName);
|
|
39
47
|
}
|
|
40
|
-
this.
|
|
41
|
-
this._fileNamesByKey[key] = generatedFileName;
|
|
42
|
-
return generatedFileName;
|
|
48
|
+
return this.assignFileName(generatedFileName, key);
|
|
43
49
|
}
|
|
44
50
|
/**
|
|
45
51
|
* Generates a new file name by incrementing an existing numeric suffix
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UniqueFileNamesGenerator.js","sourceRoot":"","sources":["../../../src/dataExport/UniqueFileNamesGenerator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,MAAM,kBAAkB,GAAG,kBAAkB,CAAA,CAAC,mCAAmC;AAEjF,MAAM,OAAO,wBAAwB;
|
|
1
|
+
{"version":3,"file":"UniqueFileN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CAAC,iBAAiB,CAAC,EAAE,CAAC;YAC9C,kDAAkD;YAClD,iBAAiB,GAAG,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,CAAA;QAClE,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAA;IACpD,CAAC;IAED;;;;;;OAMG;IACO,oBAAoB,CAAC,aAAqB;QAClD,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;QAC7C,MAAM,SAAS,GAAG,SAAS,CAAC,YAAY,CAAC,aAAa,CAAC,CAAA;QACvD,IAAI,WAAW,CAAA;QACf,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC9C,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,CAAC,EAAE,gBAAgB,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAA;YAC5C,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACnC,WAAW,GAAG,GAAG,gBAAgB,KAAK,SAAS,GAAG,CAAA;QACpD,CAAC;aAAM,CAAC;YACN,WAAW,GAAG,GAAG,IAAI,MAAM,CAAA;QAC7B,CAAC;QACD,OAAO,SAAS,CAAC,CAAC,CAAC,GAAG,WAAW,IAAI,SAAS,EAAE,CAAC,CAAC,CAAC,WAAW,CAAA;IAChE,CAAC;IAED,IAAI,cAAc;QAChB,yBAAY,IAAI,CAAC,eAAe,EAAE;IACpC,CAAC;IAED,IAAI,cAAc;QAChB,yBAAY,IAAI,CAAC,eAAe,EAAE;IACpC,CAAC;CACF","sourcesContent":["import { Dictionary } from '../common'\nimport { FileNames } from '../utils'\n\nconst nameWithIndexRegEx = /^(.*) \\((\\d+)\\)$/ // file name like \"example (1).txt\"\n\nexport class UniqueFileNamesGenerator {\n private _fileNamesByKey: Dictionary<string>\n private _keysByFileName: Dictionary<string>\n // file names are compared ignoring case: names differing only in case overwrite each other on Windows/macOS\n private readonly _fileNamesLowerCase: Set<string>\n\n constructor() {\n this._fileNamesByKey = {}\n this._keysByFileName = {}\n this._fileNamesLowerCase = new Set()\n }\n\n private isFileNameUsed(fileName: string): boolean {\n return this._fileNamesLowerCase.has(fileName.toLowerCase())\n }\n\n private assignFileName(fileName: string, key: string): string {\n this._keysByFileName[fileName] = key\n this._fileNamesByKey[key] = fileName\n this._fileNamesLowerCase.add(fileName.toLowerCase())\n return fileName\n }\n\n /**\n * Generates a unique file name for the given key.\n *\n * If the key has been used before, the previously generated file name\n * associated with that key is returned, regardless of the current\n * {@link inputFileName} value.\n *\n * If the key has not been used before, the method either:\n * - returns {@link inputFileName} if it has not been used for another key, or\n * - generates the next available non-conflicting name by appending or\n * incrementing a numeric index in parentheses.\n *\n * @param inputFileName The desired base file name, including extension.\n * @param key A logical identifier whose associated file name should remain stable across calls.\n * @returns The unique file name associated with the given key.\n */\n generateUniqueFileName(inputFileName: string, key: string): string {\n const existingFileName = this._fileNamesByKey[key]\n if (existingFileName) {\n return existingFileName\n }\n if (!this.isFileNameUsed(inputFileName)) {\n // file name not used yet\n return this.assignFileName(inputFileName, key)\n }\n let generatedFileName = this.generateNextFileName(inputFileName)\n while (this.isFileNameUsed(generatedFileName)) {\n // file name already exists, generate the next one\n generatedFileName = this.generateNextFileName(generatedFileName)\n }\n return this.assignFileName(generatedFileName, key)\n }\n\n /**\n * Generates a new file name by incrementing an existing numeric suffix\n * of the form \"name (n)\" or appending \" (1)\" if no such suffix exists.\n *\n * @param inputFileName The original file name, including its extension.\n * @returns The updated file name with an incremented or newly added numeric suffix.\n */\n protected generateNextFileName(inputFileName: string): string {\n const name = FileNames.getName(inputFileName)\n const extension = FileNames.getExtension(inputFileName)\n let nameUpdated\n const matchRes = nameWithIndexRegEx.exec(name)\n if (matchRes) {\n const [, nameWithoutIndex, index] = matchRes\n const nextIndex = Number(index) + 1\n nameUpdated = `${nameWithoutIndex} (${nextIndex})`\n } else {\n nameUpdated = `${name} (1)`\n }\n return extension ? `${nameUpdated}.${extension}` : nameUpdated\n }\n\n get fileNamesByKey(): Readonly<Dictionary<string>> {\n return { ...this._fileNamesByKey }\n }\n\n get keysByFileName(): Readonly<Dictionary<string>> {\n return { ...this._keysByFileName }\n }\n}\n"]}
|
|
@@ -7,11 +7,12 @@ const getName = (fileName) => {
|
|
|
7
7
|
return lastIndexOfDot > 0 ? fileNameStr.substring(0, lastIndexOfDot) : fileNameStr;
|
|
8
8
|
};
|
|
9
9
|
const getExtension = (fileName) => {
|
|
10
|
-
var _a;
|
|
11
10
|
if (Objects.isEmpty(fileName))
|
|
12
11
|
return '';
|
|
13
|
-
const
|
|
14
|
-
|
|
12
|
+
const fileNameStr = String(fileName);
|
|
13
|
+
const lastIndexOfDot = fileNameStr.lastIndexOf('.');
|
|
14
|
+
// consistent with getName: a leading dot (e.g. ".htaccess") is part of the name, not an extension
|
|
15
|
+
return lastIndexOfDot > 0 ? fileNameStr.substring(lastIndexOfDot + 1) : '';
|
|
15
16
|
};
|
|
16
17
|
const addExtensionIfMissing = (fileName, defaultExtension) => {
|
|
17
18
|
const extension = getExtension(fileName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileNames.js","sourceRoot":"","sources":["../../../src/utils/fileNames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,MAAM,OAAO,GAAG,CAAC,QAAmC,EAAU,EAAE;IAC9D,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;QAAE,OAAO,EAAE,CAAA;IACxC,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;IACpC,MAAM,cAAc,GAAG,WAAW,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IACnD,OAAO,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA;A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,OAAO,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC/C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,OAAO;IACP,YAAY;IACZ,qBAAqB;CACtB,CAAA","sourcesContent":["import { Objects } from './_objects'\n\nconst getName = (fileName: string | null | undefined): string => {\n if (Objects.isEmpty(fileName)) return ''\n const fileNameStr = String(fileName)\n const lastIndexOfDot = fileNameStr.lastIndexOf('.')\n return lastIndexOfDot > 0 ? fileNameStr.substring(0, lastIndexOfDot) : fileNameStr\n}\n\nconst getExtension = (fileName: string | null | undefined): string => {\n if (Objects.isEmpty(fileName)) return ''\n const fileNameStr = String(fileName)\n const lastIndexOfDot = fileNameStr.lastIndexOf('.')\n // consistent with getName: a leading dot (e.g. \".htaccess\") is part of the name, not an extension\n return lastIndexOfDot > 0 ? fileNameStr.substring(lastIndexOfDot + 1) : ''\n}\n\nconst addExtensionIfMissing = (fileName: string, defaultExtension: string): string => {\n const extension = getExtension(fileName)\n if (Objects.isNotEmpty(extension) || Objects.isEmpty(defaultExtension)) return fileName\n return [fileName, defaultExtension].join('.')\n}\n\nexport const FileNames = {\n getName,\n getExtension,\n addExtensionIfMissing,\n}\n"]}
|
package/dist/utils/fileNames.js
CHANGED
|
@@ -10,11 +10,12 @@ const getName = (fileName) => {
|
|
|
10
10
|
return lastIndexOfDot > 0 ? fileNameStr.substring(0, lastIndexOfDot) : fileNameStr;
|
|
11
11
|
};
|
|
12
12
|
const getExtension = (fileName) => {
|
|
13
|
-
var _a;
|
|
14
13
|
if (_objects_1.Objects.isEmpty(fileName))
|
|
15
14
|
return '';
|
|
16
|
-
const
|
|
17
|
-
|
|
15
|
+
const fileNameStr = String(fileName);
|
|
16
|
+
const lastIndexOfDot = fileNameStr.lastIndexOf('.');
|
|
17
|
+
// consistent with getName: a leading dot (e.g. ".htaccess") is part of the name, not an extension
|
|
18
|
+
return lastIndexOfDot > 0 ? fileNameStr.substring(lastIndexOfDot + 1) : '';
|
|
18
19
|
};
|
|
19
20
|
const addExtensionIfMissing = (fileName, defaultExtension) => {
|
|
20
21
|
const extension = getExtension(fileName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileNames.js","sourceRoot":"","sources":["../../src/utils/fileNames.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AAEpC,MAAM,OAAO,GAAG,CAAC,QAAmC,EAAU,EAAE;IAC9D,IAAI,kBAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;QAAE,OAAO,EAAE,CAAA;IACxC,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;IACpC,MAAM,cAAc,GAAG,WAAW,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IACnD,OAAO,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA;AACpF,CAAC,CAAA;AAED,MAAM,YAAY,GAAG,CAAC,QAAmC,EAAU,EAAE
|
|
1
|
+
{"version":3,"file":"fileNames.js","sourceRoot":"","sources":["../../src/utils/fileNames.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AAEpC,MAAM,OAAO,GAAG,CAAC,QAAmC,EAAU,EAAE;IAC9D,IAAI,kBAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;QAAE,OAAO,EAAE,CAAA;IACxC,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;IACpC,MAAM,cAAc,GAAG,WAAW,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IACnD,OAAO,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA;AACpF,CAAC,CAAA;AAED,MAAM,YAAY,GAAG,CAAC,QAAmC,EAAU,EAAE;IACnE,IAAI,kBAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;QAAE,OAAO,EAAE,CAAA;IACxC,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;IACpC,MAAM,cAAc,GAAG,WAAW,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IACnD,kGAAkG;IAClG,OAAO,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;AAC5E,CAAC,CAAA;AAED,MAAM,qBAAqB,GAAG,CAAC,QAAgB,EAAE,gBAAwB,EAAU,EAAE;IACnF,MAAM,SAAS,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;IACxC,IAAI,kBAAO,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,kBAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC;QAAE,OAAO,QAAQ,CAAA;IACvF,OAAO,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC/C,CAAC,CAAA;AAEY,QAAA,SAAS,GAAG;IACvB,OAAO;IACP,YAAY;IACZ,qBAAqB;CACtB,CAAA","sourcesContent":["import { Objects } from './_objects'\n\nconst getName = (fileName: string | null | undefined): string => {\n if (Objects.isEmpty(fileName)) return ''\n const fileNameStr = String(fileName)\n const lastIndexOfDot = fileNameStr.lastIndexOf('.')\n return lastIndexOfDot > 0 ? fileNameStr.substring(0, lastIndexOfDot) : fileNameStr\n}\n\nconst getExtension = (fileName: string | null | undefined): string => {\n if (Objects.isEmpty(fileName)) return ''\n const fileNameStr = String(fileName)\n const lastIndexOfDot = fileNameStr.lastIndexOf('.')\n // consistent with getName: a leading dot (e.g. \".htaccess\") is part of the name, not an extension\n return lastIndexOfDot > 0 ? fileNameStr.substring(lastIndexOfDot + 1) : ''\n}\n\nconst addExtensionIfMissing = (fileName: string, defaultExtension: string): string => {\n const extension = getExtension(fileName)\n if (Objects.isNotEmpty(extension) || Objects.isEmpty(defaultExtension)) return fileName\n return [fileName, defaultExtension].join('.')\n}\n\nexport const FileNames = {\n getName,\n getExtension,\n addExtensionIfMissing,\n}\n"]}
|