@chr33s/pdf-codepoints 5.0.1 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,64 +0,0 @@
1
- import { Buffer } from "node:buffer";
2
- import { mkdir, readdir, stat, writeFile } from "node:fs/promises";
3
- import { dirname, join, relative, resolve } from "node:path";
4
- import { fileURLToPath } from "node:url";
5
-
6
- const unicodeVersion = process.env.UNICODE_VERSION ?? "12.0.0";
7
- const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
8
- const dataDir = join(packageRoot, "data");
9
-
10
- async function* walk(dir: string): AsyncGenerator<string> {
11
- const entries = await readdir(dir, { withFileTypes: true });
12
- for (const entry of entries) {
13
- const entryPath = join(dir, entry.name);
14
- if (entry.isDirectory()) {
15
- for await (const child of walk(entryPath)) {
16
- yield child;
17
- }
18
- } else {
19
- yield entryPath;
20
- }
21
- }
22
- }
23
-
24
- async function ensureDir(path: string): Promise<void> {
25
- await mkdir(path, { recursive: true });
26
- }
27
-
28
- async function downloadFile(source: string, destination: string): Promise<void> {
29
- const response = await fetch(source);
30
- if (!response.ok) {
31
- throw new Error(`Failed to download ${source}: ${response.status} ${response.statusText}`);
32
- }
33
-
34
- const arrayBuffer = await response.arrayBuffer();
35
- await ensureDir(dirname(destination));
36
- await writeFile(destination, Buffer.from(arrayBuffer));
37
- }
38
-
39
- async function main(): Promise<void> {
40
- console.log(`Fetching Unicode data files (version ${unicodeVersion})...`);
41
-
42
- for await (const absolutePath of walk(dataDir)) {
43
- if (!absolutePath.endsWith(".txt")) continue;
44
-
45
- const relativePath = relative(dataDir, absolutePath).split("\\").join("/");
46
- const url = `https://www.unicode.org/Public/${unicodeVersion}/ucd/${relativePath}`;
47
-
48
- const stats = await stat(absolutePath).catch(() => null);
49
- const previousSize = stats?.size ?? 0;
50
-
51
- await downloadFile(url, absolutePath);
52
-
53
- const newStats = await stat(absolutePath);
54
- const sizeChange = newStats.size - previousSize;
55
- const changeLabel =
56
- sizeChange === 0 ? "unchanged" : sizeChange > 0 ? `+${sizeChange}` : `${sizeChange}`;
57
- console.log(`Downloaded ${relativePath} (${newStats.size} bytes, ${changeLabel})`);
58
- }
59
- }
60
-
61
- main().catch((error) => {
62
- console.error(error);
63
- process.exitCode = 1;
64
- });
@@ -1,77 +0,0 @@
1
- import { beforeAll, describe, expect, test } from "vitest";
2
-
3
- import parser, { type CodePointTable } from "../src/parser.js";
4
-
5
- let codePoints: CodePointTable;
6
-
7
- beforeAll(() => {
8
- codePoints = parser();
9
- });
10
-
11
- describe("parser", () => {
12
- test("loads metadata for basic Latin letters", () => {
13
- const capitalA = codePoints[0x0041];
14
- const smallA = codePoints[0x0061];
15
-
16
- expect(capitalA).toBeDefined();
17
- expect(capitalA?.name).toBe("LATIN CAPITAL LETTER A");
18
- expect(capitalA?.category).toBe("Lu");
19
- expect(capitalA?.block).toBe("Basic Latin");
20
- expect(capitalA?.script).toBe("Latin");
21
- expect(capitalA?.eastAsianWidth).toBe("Na");
22
- expect(capitalA?.lowercase).toEqual([0x0061]);
23
-
24
- expect(smallA).toBeDefined();
25
- expect(smallA?.name).toBe("LATIN SMALL LETTER A");
26
- expect(smallA?.category).toBe("Ll");
27
- expect(smallA?.block).toBe("Basic Latin");
28
- expect(smallA?.uppercase).toEqual([0x0041]);
29
- });
30
-
31
- test("marks compatibility decompositions and canonical compositions", () => {
32
- const noBreakSpace = codePoints[0x00a0];
33
- const combiningDiaeresis = codePoints[0x0308];
34
-
35
- expect(noBreakSpace).toBeDefined();
36
- expect(noBreakSpace?.isCompat).toBe(true);
37
- expect(noBreakSpace?.decomposition).toEqual([0x0020]);
38
-
39
- expect(combiningDiaeresis).toBeDefined();
40
- expect(combiningDiaeresis?.isCompat).toBe(false);
41
- expect(combiningDiaeresis?.compositions[0x0041]).toBe(0x00c4);
42
- });
43
-
44
- test("applies derived metadata from supplemental files", () => {
45
- const combiningAcute = codePoints[0x0301];
46
- const aegeanSixtyThousand = codePoints[0x10130];
47
-
48
- expect(combiningAcute).toBeDefined();
49
- expect(combiningAcute?.combiningClass).toBe(230);
50
- expect(combiningAcute?.combiningClassName).toBe("Above");
51
-
52
- expect(aegeanSixtyThousand).toBeDefined();
53
- expect(aegeanSixtyThousand?.numeric).toBe("60000");
54
- });
55
-
56
- test("records normalization quick-check and conditional casing data", () => {
57
- const dottedCapitalI = codePoints[0x0130];
58
-
59
- expect(dottedCapitalI).toBeDefined();
60
- expect(dottedCapitalI?.NFD_QC).toBe(1);
61
- expect(dottedCapitalI?.NFKD_QC).toBe(1);
62
- expect(dottedCapitalI?.caseConditions).not.toBeNull();
63
- expect(dottedCapitalI?.caseConditions).toEqual(expect.arrayContaining(["az"]));
64
- });
65
-
66
- test("fills in range entries and Arabic joining metadata", () => {
67
- const cjkExtensionA = codePoints[0x3401];
68
- const arabicBeh = codePoints[0x0628];
69
-
70
- expect(cjkExtensionA).toBeDefined();
71
- expect(cjkExtensionA?.code).toBe(0x3401);
72
-
73
- expect(arabicBeh).toBeDefined();
74
- expect(arabicBeh?.joiningType).toBe("Dual_Joining");
75
- expect(arabicBeh?.joiningGroup).toBe("BEH");
76
- });
77
- });
package/tsconfig.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "dist",
6
- "declarationDir": "dist"
7
- },
8
- "include": ["src/**/*"],
9
- "exclude": ["dist", "node_modules"]
10
- }
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "noEmit": true,
5
- "rootDir": "."
6
- },
7
- "include": [
8
- "**/*.ts",
9
- ],
10
- "exclude": [
11
- "dist",
12
- "node_modules"
13
- ]
14
- }
package/vitest.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
-
3
- export default defineConfig({
4
- test: {
5
- environment: "node",
6
- include: ["test/**/*.test.ts"],
7
- },
8
- });