feat: filter figure parts (exclude shoes, waist, dedupe head)
CI / check (push) Successful in 34s
CI / release (push) Skipped
CI / deploy (push) Successful in 1m3s

- 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:
openhands committed 2026-08-09 19:50:24 +02:00
1 parent 7a2c0fd4d4
commit 2f708bcf11
2 files changed
+68 -8

No files matched your search

+24 -4
View File
@@ -43,12 +43,25 @@ describe("convertFigurePart", () => {
});
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 =
"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.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", () => {
@@ -62,8 +75,15 @@ describe("convertFigureString", () => {
});
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";
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",
);
});
});
+44 -4
View File
@@ -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"
* -> "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;
const {
excludeShoes = true,
excludeWaist = true,
dedupeHead = true,
} = options;
const parts = figure.split(".");
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.
* Handles both old and new format input.
*/
export function getNewFormatFigure(look: string): string {
return convertFigureString(look);
export function getNewFormatFigure(
look: string,
options?: ConvertFigureOptions,
): string {
return convertFigureString(look, options);
}