Move getFileExtension to skinparserutils

This commit is contained in:
Jordan Eldredge 2019-04-29 07:03:59 -07:00
parent 3547256e5a
commit 8b49b5fa6a
5 changed files with 24 additions and 23 deletions

View file

@ -1,7 +1,7 @@
import SKIN_SPRITES from "./skinSprites";
import regionParser from "./regionParser";
import { LETTERS, DEFAULT_SKIN } from "./constants";
import { parseViscolors, parseIni, getFileExtension, objectMap } from "./utils";
import { parseViscolors, parseIni, objectMap } from "./utils";
import * as SkinParserUtils from "./skinParserUtils";
const shallowMerge = objs =>
@ -65,7 +65,8 @@ async function genImgFromFilename(zip, fileName) {
return null;
}
const mimeType = `image/${getFileExtension(file.name) || "*"}`;
const mimeType = `image/${SkinParserUtils.getFileExtension(file.name) ||
"*"}`;
// The spec for createImageBitmap() says the browser should try to sniff the
// mime type, but it looks like Firefox does not. So we specify it here
// explicitly.

View file

@ -1,6 +1,11 @@
import JSZip from "jszip";
import { Sprite } from "./skinSprites";
export const getFileExtension = (fileName: string): string | null => {
const matches = /\.([a-z]{3,4})$/i.exec(fileName);
return matches ? matches[1].toLowerCase() : null;
};
export async function getFileFromZip(
zip: JSZip,
fileName: string,

View file

@ -0,0 +1,16 @@
import * as SkinParserUtils from "./skinParserUtils";
describe("getFileExtension", () => {
it("can get bmp", () => {
expect(SkinParserUtils.getFileExtension("foo.bmp")).toBe("bmp");
});
it("can match four char extension", () => {
expect(SkinParserUtils.getFileExtension("foo.html")).toBe("html");
});
it("converts to lower case", () => {
expect(SkinParserUtils.getFileExtension("foo.BMP")).toBe("bmp");
});
it("returns null if a match is not found", () => {
expect(SkinParserUtils.getFileExtension("foo")).toBe(null);
});
});

View file

@ -11,7 +11,6 @@ import {
segment,
moveSelected,
spliceIn,
getFileExtension,
makeCachingFilterFunction,
replaceAtIndex,
} from "./utils";
@ -50,21 +49,6 @@ describe("getTimeStr", () => {
});
});
describe("getFileExtension", () => {
it("can get bmp", () => {
expect(getFileExtension("foo.bmp")).toBe("bmp");
});
it("can match four char extension", () => {
expect(getFileExtension("foo.html")).toBe("html");
});
it("converts to lower case", () => {
expect(getFileExtension("foo.BMP")).toBe("bmp");
});
it("returns null if a match is not found", () => {
expect(getFileExtension("foo")).toBe(null);
});
});
describe("clamp", () => {
it("respects the max value", () => {
const actual = clamp(101, 0, 100);

View file

@ -75,11 +75,6 @@ export const getTimeStr = (
].join("");
};
export const getFileExtension = (fileName: string): string | null => {
const matches = /\.([a-z]{3,4})$/i.exec(fileName);
return matches ? matches[1].toLowerCase() : null;
};
export const parseViscolors = (text: string): string[] => {
const entries = text.split("\n");
const regex = /^\s*(\d+)\s*,?\s*(\d+)\s*,?\s*(\d+)/;