Skip to content

Commit

Permalink
Merge pull request #65 from Ubugeeei/64-fix-codege-fail
Browse files Browse the repository at this point in the history
fix: #64 📌 codegen fails when the number of strokes is 1
  • Loading branch information
ubugeeei authored Oct 19, 2023
2 parents b736d1b + de301cf commit 4978a35
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/tools/src/cmd/codegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ ${cjs ? `module.exports.${exportName}` : `export const ${exportName}`}${
type XML = {
kanji: {
unicode: string;
stroke: Array<{ point: Array<{ "@_x": string; "@_y": string }> }>;
stroke:
| { point: Array<{ "@_x": string; "@_y": string }> } // NOTE: stroke is object when the number of strokes is 1
| Array<{ point: Array<{ "@_x": string; "@_y": string }> }>;
};
};

Expand All @@ -84,7 +86,8 @@ const parse = (xml: string): TecackDataset => {
const jsonObj = parser.parse(xml) as XML;
const { kanji } = jsonObj;
const { unicode, stroke } = kanji;
const tuple_d: Array<TecackStroke> = stroke.map(({ point }) =>

const tuple_d: Array<TecackStroke> = (Array.isArray(stroke) ? stroke : [stroke]).map(({ point }) =>
point.map((it): Position => [Number(it["@_x"]), Number(it["@_y"])]),
);
return [unicode, tuple_d.length, tuple_d];
Expand Down

0 comments on commit 4978a35

Please sign in to comment.