Skip to content

Commit afb34fd

Browse files
committed
lint fix
1 parent d7df106 commit afb34fd

2 files changed

Lines changed: 85 additions & 55 deletions

File tree

src/processors/nuvoice/helpers.ts

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
export type NuVoiceRecordType = 'v' | 'd' | 'm' | 'x' | 'X' | 'P' | 'H' | 'A' | 'n' | 'N' | 'S' | 'E' | 'G' | 'a' | 'C' | 'D' | 'U' | 'V' | 'p' | 'k' | 'q';
1+
export type NuVoiceRecordType =
2+
| 'v'
3+
| 'd'
4+
| 'm'
5+
| 'x'
6+
| 'X'
7+
| 'P'
8+
| 'H'
9+
| 'A'
10+
| 'n'
11+
| 'N'
12+
| 'S'
13+
| 'E'
14+
| 'G'
15+
| 'a'
16+
| 'C'
17+
| 'D'
18+
| 'U'
19+
| 'V'
20+
| 'p'
21+
| 'k'
22+
| 'q';
223

324
export interface NuVoiceBinaryRecordBase {
425
type: NuVoiceRecordType;
@@ -185,7 +206,7 @@ export function latin1ToBytes(text: string): Uint8Array {
185206

186207
export function computeNuVoiceChecksum(bodyBytes: Uint8Array): number {
187208
const sum = bodyBytes.reduce((total, value) => total + value, 0);
188-
return (~sum) & 0xff;
209+
return ~sum & 0xff;
189210
}
190211

191212
function isPrintableAscii(bytes: Uint8Array): boolean {
@@ -341,7 +362,7 @@ export function parseNuVoiceDocument(content: string): NuVoiceDocument {
341362
const records: NuVoiceRecord[] = [];
342363
for (const line of lines) {
343364
if (line.length === 0) continue;
344-
365+
345366
try {
346367
switch (line[0]) {
347368
case 'v':
@@ -382,7 +403,9 @@ export function parseNuVoiceDocument(content: string): NuVoiceDocument {
382403
break;
383404
}
384405
} catch (error) {
385-
console.warn(`Error parsing NuVoice record: ${(error as Error).message}, line: ${line.slice(0, 50)}...`);
406+
console.warn(
407+
`Error parsing NuVoice record: ${(error as Error).message}, line: ${line.slice(0, 50)}...`
408+
);
386409
}
387410
}
388411

@@ -559,22 +582,26 @@ export function listNuVoiceTextEntries(document: NuVoiceDocument): NuVoiceTextEn
559582
});
560583
}
561584
dictionaryIndex += 1;
562-
} else if (record.type === 'm' && (record as NuVoiceMemoryRecord).textSegment) {
585+
} else if (record.type === 'm') {
563586
const memRecord = record as NuVoiceMemoryRecord;
564-
entries.push({
565-
source: memRecord.textSegment!.text,
566-
table: 'memory',
567-
column: 'TEXT',
568-
id: `memory:${memRecord.addressHex}`,
569-
});
570-
} else if (record.type === 'x' && (record as NuVoiceLayoutRecord).textSegment) {
587+
if (memRecord.textSegment) {
588+
entries.push({
589+
source: memRecord.textSegment.text,
590+
table: 'memory',
591+
column: 'TEXT',
592+
id: `memory:${memRecord.addressHex}`,
593+
});
594+
}
595+
} else if (record.type === 'x') {
571596
const layoutRecord = record as NuVoiceLayoutRecord;
572-
entries.push({
573-
source: layoutRecord.textSegment!.text,
574-
table: 'layout',
575-
column: 'TEXT',
576-
id: `layout:${layoutRecord.addressHex}`,
577-
});
597+
if (layoutRecord.textSegment) {
598+
entries.push({
599+
source: layoutRecord.textSegment.text,
600+
table: 'layout',
601+
column: 'TEXT',
602+
id: `layout:${layoutRecord.addressHex}`,
603+
});
604+
}
578605
} else if ('bodyBytes' in record) {
579606
// Try to extract text from other binary records
580607
const textSegment = parseTextSegment(record.bodyBytes);

src/processors/nuvoiceProcessor.ts

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import {
22
BaseProcessor,
3+
ExtractedString,
34
ExtractStringsResult,
4-
ProcessorOptions,
55
SourceString,
66
TranslatedString,
7+
VocabLocation,
78
} from '../core/baseProcessor';
8-
import { AACTree, AACButton, AACPage, AACSemanticAction, AACSemanticCategory, AACSemanticIntent } from '../core/treeStructure';
9+
import {
10+
AACTree,
11+
AACButton,
12+
AACPage,
13+
AACSemanticCategory,
14+
AACSemanticIntent,
15+
} from '../core/treeStructure';
916
import { detectCasing } from '../core/stringCasing';
1017
import { encodeText, ProcessorInput } from '../utils/io';
1118
import {
@@ -16,11 +23,6 @@ import {
1623
NuVoiceHeaderRecord,
1724
NuVoiceLayoutRecord,
1825
NuVoiceMemoryRecord,
19-
NuVoicePageRecord,
20-
NuVoiceActionRecord,
21-
NuVoiceNavigationRecord,
22-
NuVoiceGridRecord,
23-
NuVoiceCellRecord,
2426
parseNuVoiceDocument,
2527
parseTextSegment,
2628
serializeNuVoiceDocument,
@@ -47,8 +49,11 @@ class NuVoiceProcessor extends BaseProcessor {
4749

4850
tree.metadata = {
4951
format: 'nuvoice',
50-
version: (document.records.find((record) => record.type === 'v') as NuVoiceHeaderRecord)?.version,
51-
name: (document.records.find((record) => record.type === 'v') as NuVoiceHeaderRecord)?.product || 'NuVoice MTI',
52+
version: (document.records.find((record) => record.type === 'v') as NuVoiceHeaderRecord)
53+
?.version,
54+
name:
55+
(document.records.find((record) => record.type === 'v') as NuVoiceHeaderRecord)?.product ||
56+
'NuVoice MTI',
5257
recordCounts,
5358
invalidChecksumCount: document.records.filter(
5459
(record) => record.type !== 'v' && 'checksumValid' in record && !record.checksumValid
@@ -67,10 +72,12 @@ class NuVoiceProcessor extends BaseProcessor {
6772
(record): record is NuVoiceDictionaryRecord => record.type === 'd'
6873
);
6974
const memoryRecords = document.records.filter(
70-
(record): record is NuVoiceMemoryRecord => record.type === 'm' && 'textSegment' in record && record.textSegment !== null
75+
(record): record is NuVoiceMemoryRecord =>
76+
record.type === 'm' && 'textSegment' in record && record.textSegment !== null
7177
);
7278
const layoutRecords = document.records.filter(
73-
(record): record is NuVoiceLayoutRecord => record.type === 'x' && 'textSegment' in record && record.textSegment !== null
79+
(record): record is NuVoiceLayoutRecord =>
80+
record.type === 'x' && 'textSegment' in record && record.textSegment !== null
7481
);
7582

7683
// Dictionary page
@@ -207,9 +214,6 @@ class NuVoiceProcessor extends BaseProcessor {
207214
const navigationRecords = document.records.filter(
208215
(record) => record.type === 'n' && 'bodyBytes' in record
209216
);
210-
const gridRecords = document.records.filter(
211-
(record) => record.type === 'G' && 'bodyBytes' in record
212-
);
213217
const cellRecords = document.records.filter(
214218
(record) => record.type === 'C' && 'bodyBytes' in record
215219
);
@@ -241,10 +245,8 @@ class NuVoiceProcessor extends BaseProcessor {
241245
);
242246

243247
// Try to find associated cells for this page
244-
const pageCells = cellRecords.filter(cell => {
245-
// Simple heuristic: include all cells for now
246-
return true;
247-
});
248+
// Simple heuristic: include all cells for now.
249+
const pageCells = cellRecords;
248250

249251
pageCells.forEach((cell, cellIndex) => {
250252
const cellBinary = cell as NuVoiceBinaryRecordBase;
@@ -276,7 +278,7 @@ class NuVoiceProcessor extends BaseProcessor {
276278
type: 'NAVIGATE',
277279
semanticAction: {
278280
category: AACSemanticCategory.NAVIGATION,
279-
intent: AACSemanticIntent.NAVIGATE_TO,
281+
intent: AACSemanticIntent.NAVIGATE_TO,
280282
parameters: { pageId: `page-${index}` },
281283
},
282284
})
@@ -372,7 +374,9 @@ class NuVoiceProcessor extends BaseProcessor {
372374

373375
// Handle remaining unknown record types
374376
const otherRecords = document.records.filter(
375-
(record) => !['v', 'd', 'm', 'x', 'X', 'P', 'A', 'n', 'C'].includes(record.type) && 'bodyBytes' in record
377+
(record) =>
378+
!['v', 'd', 'm', 'x', 'X', 'P', 'A', 'n', 'C'].includes(record.type) &&
379+
'bodyBytes' in record
376380
);
377381

378382
if (otherRecords.length > 0) {
@@ -384,7 +388,7 @@ class NuVoiceProcessor extends BaseProcessor {
384388

385389
// Group by record type for better organization
386390
const recordsByType: Record<string, typeof otherRecords> = {};
387-
otherRecords.forEach(record => {
391+
otherRecords.forEach((record) => {
388392
if (!recordsByType[record.type]) {
389393
recordsByType[record.type] = [];
390394
}
@@ -454,16 +458,17 @@ class NuVoiceProcessor extends BaseProcessor {
454458
if (record.type === 'd') {
455459
const dictRecord = record as NuVoiceDictionaryRecord;
456460
dictRecord.word = translations.get(dictRecord.word) ?? dictRecord.word;
457-
dictRecord.pronunciation = translations.get(dictRecord.pronunciation) ?? dictRecord.pronunciation;
461+
dictRecord.pronunciation =
462+
translations.get(dictRecord.pronunciation) ?? dictRecord.pronunciation;
458463
} else if (record.type === 'm' && 'textSegment' in record && record.textSegment) {
459464
const nextText = translations.get(record.textSegment.text);
460465
if (nextText !== undefined) {
461-
setNuVoiceMemoryText(record as NuVoiceMemoryRecord, nextText);
466+
setNuVoiceMemoryText(record, nextText);
462467
}
463468
} else if (record.type === 'x' && 'textSegment' in record && record.textSegment) {
464469
const nextText = translations.get(record.textSegment.text);
465470
if (nextText !== undefined) {
466-
setNuVoiceLayoutText(record as NuVoiceLayoutRecord, nextText);
471+
setNuVoiceLayoutText(record, nextText);
467472
}
468473
} else if ('bodyBytes' in record) {
469474
// Try to update text in other binary records (P, A, n, C, etc.)
@@ -477,7 +482,11 @@ class NuVoiceProcessor extends BaseProcessor {
477482
const newTextBytes = latin1ToBytes(nextText);
478483
if (newTextBytes.length <= record.bodyBytes.length) {
479484
// Replace the text segment in place
480-
const textStart = binaryRecord.bodyBytes.length - textSegment.suffixBytes.length - (textSegment.hasNullTerminator ? 1 : 0) - textSegment.text.length;
485+
const textStart =
486+
binaryRecord.bodyBytes.length -
487+
textSegment.suffixBytes.length -
488+
(textSegment.hasNullTerminator ? 1 : 0) -
489+
textSegment.text.length;
481490
binaryRecord.bodyBytes.set(newTextBytes, textStart);
482491
}
483492
}
@@ -490,9 +499,11 @@ class NuVoiceProcessor extends BaseProcessor {
490499
return encodeText(serialized);
491500
}
492501

493-
async saveFromTree(_tree: AACTree, _outputPath: string): Promise<void> {
494-
throw new Error(
495-
'NuVoice MTI saveFromTree is not supported yet; use processTexts on an existing .mti file.'
502+
saveFromTree(_tree: AACTree, _outputPath: string): Promise<void> {
503+
return Promise.reject(
504+
new Error(
505+
'NuVoice MTI saveFromTree is not supported yet; use processTexts on an existing .mti file.'
506+
)
496507
);
497508
}
498509

@@ -543,15 +554,7 @@ class NuVoiceProcessor extends BaseProcessor {
543554
return this.generateTranslatedDownloadGeneric(filePath, translatedStrings, sourceStrings);
544555
}
545556

546-
private buildExtractedEntry(
547-
source: string,
548-
vocabLocation: {
549-
table: string;
550-
id: string;
551-
column: string;
552-
casing: ReturnType<typeof detectCasing>;
553-
}
554-
) {
557+
private buildExtractedEntry(source: string, vocabLocation: VocabLocation): ExtractedString {
555558
return {
556559
string: source,
557560
vocabPlacementMeta: {

0 commit comments

Comments
 (0)