image-exporter 1.0.6 → 1.0.7
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.
|
@@ -777,7 +777,8 @@ async function toJpeg(node, options = {}) {
|
|
|
777
777
|
function handleFileNames(imageOptions, filenames) {
|
|
778
778
|
let proposedFilename = imageOptions.label;
|
|
779
779
|
if (imageOptions.includeScaleInLabel) proposedFilename += `_@${imageOptions.scale}x`;
|
|
780
|
-
|
|
780
|
+
const extension = `.${imageOptions.format}`;
|
|
781
|
+
proposedFilename += extension;
|
|
781
782
|
if (!filenames.includes(proposedFilename)) {
|
|
782
783
|
filenames.push(proposedFilename);
|
|
783
784
|
return proposedFilename;
|
|
@@ -787,18 +788,19 @@ function handleFileNames(imageOptions, filenames) {
|
|
|
787
788
|
if (match) {
|
|
788
789
|
const baseFilename = proposedFilename.replace(numberPattern, "");
|
|
789
790
|
let counter = parseInt(match[1], 10);
|
|
790
|
-
while (filenames.includes(`${baseFilename}-${counter}`)) {
|
|
791
|
+
while (filenames.includes(`${baseFilename}-${counter}${extension}`)) {
|
|
791
792
|
counter++;
|
|
792
793
|
}
|
|
793
|
-
const newFilename = `${baseFilename}-${counter}`;
|
|
794
|
+
const newFilename = `${baseFilename}-${counter}${extension}`;
|
|
794
795
|
filenames.push(newFilename);
|
|
795
796
|
return newFilename;
|
|
796
797
|
} else {
|
|
798
|
+
const baseFilename = proposedFilename.replace(extension, "");
|
|
797
799
|
let counter = 2;
|
|
798
|
-
while (filenames.includes(`${
|
|
800
|
+
while (filenames.includes(`${baseFilename}-${counter}${extension}`)) {
|
|
799
801
|
counter++;
|
|
800
802
|
}
|
|
801
|
-
const newFilename = `${
|
|
803
|
+
const newFilename = `${baseFilename}-${counter}${extension}`;
|
|
802
804
|
filenames.push(newFilename);
|
|
803
805
|
return newFilename;
|
|
804
806
|
}
|
|
@@ -782,7 +782,8 @@
|
|
|
782
782
|
function handleFileNames(imageOptions, filenames) {
|
|
783
783
|
let proposedFilename = imageOptions.label;
|
|
784
784
|
if (imageOptions.includeScaleInLabel) proposedFilename += `_@${imageOptions.scale}x`;
|
|
785
|
-
|
|
785
|
+
const extension = `.${imageOptions.format}`;
|
|
786
|
+
proposedFilename += extension;
|
|
786
787
|
if (!filenames.includes(proposedFilename)) {
|
|
787
788
|
filenames.push(proposedFilename);
|
|
788
789
|
return proposedFilename;
|
|
@@ -792,18 +793,19 @@
|
|
|
792
793
|
if (match) {
|
|
793
794
|
const baseFilename = proposedFilename.replace(numberPattern, "");
|
|
794
795
|
let counter = parseInt(match[1], 10);
|
|
795
|
-
while (filenames.includes(`${baseFilename}-${counter}`)) {
|
|
796
|
+
while (filenames.includes(`${baseFilename}-${counter}${extension}`)) {
|
|
796
797
|
counter++;
|
|
797
798
|
}
|
|
798
|
-
const newFilename = `${baseFilename}-${counter}`;
|
|
799
|
+
const newFilename = `${baseFilename}-${counter}${extension}`;
|
|
799
800
|
filenames.push(newFilename);
|
|
800
801
|
return newFilename;
|
|
801
802
|
} else {
|
|
803
|
+
const baseFilename = proposedFilename.replace(extension, "");
|
|
802
804
|
let counter = 2;
|
|
803
|
-
while (filenames.includes(`${
|
|
805
|
+
while (filenames.includes(`${baseFilename}-${counter}${extension}`)) {
|
|
804
806
|
counter++;
|
|
805
807
|
}
|
|
806
|
-
const newFilename = `${
|
|
808
|
+
const newFilename = `${baseFilename}-${counter}${extension}`;
|
|
807
809
|
filenames.push(newFilename);
|
|
808
810
|
return newFilename;
|
|
809
811
|
}
|
package/package.json
CHANGED
|
@@ -9,12 +9,13 @@ import { ImageOptions, Label } from "../types";
|
|
|
9
9
|
* If it doesn't, the function will start with "-2" and increment the number until a unique filename is found.
|
|
10
10
|
*/
|
|
11
11
|
export function handleFileNames(imageOptions: ImageOptions, filenames: string[]): Label {
|
|
12
|
-
// Finish
|
|
12
|
+
// Finish altering filenames before checking for uniqueness
|
|
13
13
|
let proposedFilename = imageOptions.label;
|
|
14
14
|
// Add scale to filename if includeScaleInLabel is true
|
|
15
15
|
if (imageOptions.includeScaleInLabel) proposedFilename += `_@${imageOptions.scale}x`;
|
|
16
16
|
// Add format to filename last
|
|
17
|
-
|
|
17
|
+
const extension = `.${imageOptions.format}`;
|
|
18
|
+
proposedFilename += extension;
|
|
18
19
|
|
|
19
20
|
// If filename is unique, add it to array and return as-is
|
|
20
21
|
if (!filenames.includes(proposedFilename)) {
|
|
@@ -31,21 +32,22 @@ export function handleFileNames(imageOptions: ImageOptions, filenames: string[])
|
|
|
31
32
|
const baseFilename = proposedFilename.replace(numberPattern, "");
|
|
32
33
|
let counter = parseInt(match[1], 10);
|
|
33
34
|
|
|
34
|
-
while (filenames.includes(`${baseFilename}-${counter}`)) {
|
|
35
|
+
while (filenames.includes(`${baseFilename}-${counter}${extension}`)) {
|
|
35
36
|
counter++;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
const newFilename = `${baseFilename}-${counter}`;
|
|
39
|
+
const newFilename = `${baseFilename}-${counter}${extension}`;
|
|
39
40
|
filenames.push(newFilename);
|
|
40
41
|
return newFilename;
|
|
41
42
|
} else {
|
|
42
|
-
// File doesn't end with -n, start with -
|
|
43
|
+
// File doesn't end with -n, start with -2 and increment if needed
|
|
44
|
+
const baseFilename = proposedFilename.replace(extension, "");
|
|
43
45
|
let counter = 2;
|
|
44
|
-
while (filenames.includes(`${
|
|
46
|
+
while (filenames.includes(`${baseFilename}-${counter}${extension}`)) {
|
|
45
47
|
counter++;
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
const newFilename = `${
|
|
50
|
+
const newFilename = `${baseFilename}-${counter}${extension}`;
|
|
49
51
|
filenames.push(newFilename);
|
|
50
52
|
return newFilename;
|
|
51
53
|
}
|