Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/cli/src/utils/craftAudit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ describe("readingWords", () => {
expect(readingWords("a tooth can’t get in")).toBe(5);
expect(readingWords("it's 'quoted'")).toBe(2);
});

it("counts a number with a thousands separator or a decimal point as one word", () => {
expect(readingWords("1,080")).toBe(1);
expect(readingWords("3.5%")).toBe(1);
expect(readingWords("$1,200.50 saved")).toBe(2);
expect(readingWords("1,080억 달러")).toBe(2);
expect(readingWords("one, two. 3 left")).toBe(4);
expect(readingWords("12/40")).toBe(2);
expect(readingWords("売上1,080億")).toBe(3);
});
});

describe("lineFloorSec", () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/utils/craftAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ const CRAFT_THRESHOLDS = {

const T = CRAFT_THRESHOLDS;
const ZERO_BBOX: CheckBbox = { x: 0, y: 0, width: 0, height: 0 };
const WORD_RUNS = /[\p{L}\p{M}\p{N}%$]+(?:['’][\p{L}\p{M}\p{N}]+)*/gu;
const WORD_CHARS = "[\\p{L}\\p{M}\\p{N}%$]+";
const CONTRACTION_TAIL = "['’][\\p{L}\\p{M}\\p{N}]+";
const DIGIT_SEPARATOR_TAIL = `(?<=\\p{N})[.,](?=\\p{N})${WORD_CHARS}`;
const WORD_RUNS = new RegExp(`${WORD_CHARS}(?:${CONTRACTION_TAIL}|${DIGIT_SEPARATOR_TAIL})*`, "gu");
// Chinese and Japanese have no spaces; a dictionary segmenter counts their words like an English line's.
const WORD_SEGMENTER = new Intl.Segmenter("ja", { granularity: "word" });
const UNSPACED_SCRIPT =
Expand Down
Loading