feat: filter figure parts (exclude shoes, waist, dedupe head)
- Default convertFigureString now excludes shoes (ha-), waist (wa-), and duplicate head - Added ConvertFigureOptions to customize filtering - Updated tests to reflect new defaults
This commit is contained in:
1 parent
7a2c0fd4d4
commit
2f708bcf11
2 files changed
+68
-8
No files matched your search
@@ -43,12 +43,25 @@ describe("convertFigurePart", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("convertFigureString", () => {
|
describe("convertFigureString", () => {
|
||||||
it("converts full figure string from old to new format", () => {
|
it("converts full figure string from old to new format (with defaults: exclude shoes, waist, dedupe head)", () => {
|
||||||
|
const oldFigure =
|
||||||
|
"hr-11782-40-40.hd-180-7-14.ch-11592-66.lg-10726-79-1408.sh-11764-1408.ha-11958-70-1408.wa-2007-0";
|
||||||
|
const newFigure = "hd-180-1.ch-255-66.lg-280-110.sh-305-62";
|
||||||
|
expect(convertFigureString(oldFigure)).toBe(newFigure);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("includes all parts when options disabled", () => {
|
||||||
const oldFigure =
|
const oldFigure =
|
||||||
"hr-11782-40-40.hd-180-7-14.ch-11592-66.lg-10726-79-1408.sh-11764-1408.ha-11958-70-1408.wa-2007-0";
|
"hr-11782-40-40.hd-180-7-14.ch-11592-66.lg-10726-79-1408.sh-11764-1408.ha-11958-70-1408.wa-2007-0";
|
||||||
const newFigure =
|
const newFigure =
|
||||||
"hd-180-1.hd-180-1.ch-255-66.lg-280-110.sh-305-62.ha-310-70.wa-200-0";
|
"hd-180-1.hd-180-1.ch-255-66.lg-280-110.sh-305-62.ha-310-70.wa-200-0";
|
||||||
expect(convertFigureString(oldFigure)).toBe(newFigure);
|
expect(
|
||||||
|
convertFigureString(oldFigure, {
|
||||||
|
excludeShoes: false,
|
||||||
|
excludeWaist: false,
|
||||||
|
dedupeHead: false,
|
||||||
|
}),
|
||||||
|
).toBe(newFigure);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("handles empty string", () => {
|
it("handles empty string", () => {
|
||||||
@@ -62,8 +75,15 @@ describe("convertFigureString", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("getNewFormatFigure", () => {
|
describe("getNewFormatFigure", () => {
|
||||||
it("converts figure using getNewFormatFigure", () => {
|
it("converts figure using getNewFormatFigure with defaults", () => {
|
||||||
const oldFigure = "hr-11782-40-40.hd-180-7-14.ch-11592-66";
|
const oldFigure = "hr-11782-40-40.hd-180-7-14.ch-11592-66";
|
||||||
expect(getNewFormatFigure(oldFigure)).toBe("hd-180-1.hd-180-1.ch-255-66");
|
expect(getNewFormatFigure(oldFigure)).toBe("hd-180-1.ch-255-66");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows custom options", () => {
|
||||||
|
const oldFigure = "hr-11782-40-40.hd-180-7-14.ch-11592-66.ha-11958-70-1408";
|
||||||
|
expect(getNewFormatFigure(oldFigure, { excludeShoes: false })).toBe(
|
||||||
|
"hd-180-1.ch-255-66.ha-310-70",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -98,18 +98,58 @@ export function convertFigurePart(part: string): string {
|
|||||||
* Example: "hr-11782-40-40.hd-180-7-14.ch-11592-66.lg-10726-79-1408.sh-11764-1408.ha-11958-70-1408.wa-2007-0"
|
* Example: "hr-11782-40-40.hd-180-7-14.ch-11592-66.lg-10726-79-1408.sh-11764-1408.ha-11958-70-1408.wa-2007-0"
|
||||||
* -> "hd-180-1.hd-180-1.ch-255-66.lg-280-110.sh-305-62.ha-310-70.wa-200-0"
|
* -> "hd-180-1.hd-180-1.ch-255-66.lg-280-110.sh-305-62.ha-310-70.wa-200-0"
|
||||||
*/
|
*/
|
||||||
export function convertFigureString(figure: string): string {
|
export interface ConvertFigureOptions {
|
||||||
|
/** Exclude shoes (ha-) */
|
||||||
|
excludeShoes?: boolean;
|
||||||
|
/** Exclude waist (wa-) */
|
||||||
|
excludeWaist?: boolean;
|
||||||
|
/** Remove duplicate head/hair (keep first hd-) */
|
||||||
|
dedupeHead?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function convertFigureString(
|
||||||
|
figure: string,
|
||||||
|
options: ConvertFigureOptions = {},
|
||||||
|
): string {
|
||||||
if (!figure) return figure;
|
if (!figure) return figure;
|
||||||
|
|
||||||
|
const {
|
||||||
|
excludeShoes = true,
|
||||||
|
excludeWaist = true,
|
||||||
|
dedupeHead = true,
|
||||||
|
} = options;
|
||||||
|
|
||||||
const parts = figure.split(".");
|
const parts = figure.split(".");
|
||||||
const converted = parts.map(convertFigurePart);
|
const converted = parts.map(convertFigurePart);
|
||||||
return converted.join(".");
|
|
||||||
|
let result = converted;
|
||||||
|
if (excludeShoes) {
|
||||||
|
result = result.filter((p) => !p.startsWith("ha-"));
|
||||||
|
}
|
||||||
|
if (excludeWaist) {
|
||||||
|
result = result.filter((p) => !p.startsWith("wa-"));
|
||||||
|
}
|
||||||
|
if (dedupeHead) {
|
||||||
|
const seen = new Set<string>();
|
||||||
|
result = result.filter((p) => {
|
||||||
|
if (p.startsWith("hd-")) {
|
||||||
|
if (seen.has("hd")) return false;
|
||||||
|
seen.add("hd");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.join(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the new format figure string for a user's look.
|
* Get the new format figure string for a user's look.
|
||||||
* Handles both old and new format input.
|
* Handles both old and new format input.
|
||||||
*/
|
*/
|
||||||
export function getNewFormatFigure(look: string): string {
|
export function getNewFormatFigure(
|
||||||
return convertFigureString(look);
|
look: string,
|
||||||
|
options?: ConvertFigureOptions,
|
||||||
|
): string {
|
||||||
|
return convertFigureString(look, options);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user