From 183215a3619e4e5f09a00921ac06a44e1afeea39 Mon Sep 17 00:00:00 2001 From: Stefan Vukovic Date: Mon, 5 Feb 2024 12:30:06 +0100 Subject: [PATCH] rename transform to process --- ext/js/language/ja/text-preprocessors.js | 16 ++++++++-------- ext/js/language/text-preprocessors.js | 4 ++-- ext/js/language/translator.js | 4 ++-- test/data/anki-note-builder-test-results.json | 2 ++ types/ext/language.d.ts | 2 +- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/ext/js/language/ja/text-preprocessors.js b/ext/js/language/ja/text-preprocessors.js index 9f0341cf87..c3853bc15a 100755 --- a/ext/js/language/ja/text-preprocessors.js +++ b/ext/js/language/ja/text-preprocessors.js @@ -20,7 +20,7 @@ import {convertAlphabeticToKana} from './japanese-wanakana.js'; import {collapseEmphaticSequences, convertHalfWidthKanaToFullWidth, convertHiraganaToKatakana, convertKatakanaToHiragana, convertNumericToFullWidth} from './japanese.js'; /** @type {import('language').TextPreprocessor<[collapseEmphatic: boolean, collapseEmphaticFull: boolean]>}*/ -const collapseEmphaticSequencesTransform = { +const collapseEmphaticSequencesPrerocessor = { id: 'collapseEmphaticSequences', name: 'Collapse emphatic character sequences', description: 'すっっごーーい → すっごーい / すごい', @@ -29,7 +29,7 @@ const collapseEmphaticSequencesTransform = { ['true', 'Collapse into single character', [[false, false], [true, false]]], ['full', 'Remove all characters', [[false, false], [true, false], [true, true]]] ], - transform: (str, setting, sourceMap) => { + process: (str, setting, sourceMap) => { const [collapseEmphatic, collapseEmphaticFull] = setting; if (collapseEmphatic) { str = collapseEmphaticSequences(str, collapseEmphaticFull, sourceMap); @@ -45,35 +45,35 @@ export const textPreprocessors = [ name: 'Convert half width characters to full width', description: 'ヨミチャン → ヨミチャン', options: basicTextPreprocessorOptions, - transform: (str, setting, sourceMap) => setting ? convertHalfWidthKanaToFullWidth(str, sourceMap) : str + process: (str, setting, sourceMap) => setting ? convertHalfWidthKanaToFullWidth(str, sourceMap) : str }, { id: 'convertNumericCharacters', name: 'Convert numeric characters to full width', description: '1234 → 1234', options: basicTextPreprocessorOptions, - transform: (str, setting) => setting ? convertNumericToFullWidth(str) : str + process: (str, setting) => setting ? convertNumericToFullWidth(str) : str }, { id: 'convertAlphabeticCharacters', name: 'Convert alphabetic characters to hiragana', description: 'yomichan → よみちゃん', options: basicTextPreprocessorOptions, - transform: (str, setting, sourceMap) => setting ? convertAlphabeticToKana(str, sourceMap) : str + process: (str, setting, sourceMap) => setting ? convertAlphabeticToKana(str, sourceMap) : str }, { id: 'convertHiraganaToKatakana', name: 'Convert hiragana to katakana', description: 'よみちゃん → ヨミチャン', options: basicTextPreprocessorOptions, - transform: (str, setting) => setting ? convertHiraganaToKatakana(str) : str + process: (str, setting) => setting ? convertHiraganaToKatakana(str) : str }, { id: 'convertKatakanaToHiragana', name: 'Convert katakana to hiragana', description: 'ヨミチャン → よみちゃん', options: basicTextPreprocessorOptions, - transform: (str, setting) => setting ? convertKatakanaToHiragana(str) : str + process: (str, setting) => setting ? convertKatakanaToHiragana(str) : str }, - collapseEmphaticSequencesTransform + collapseEmphaticSequencesPrerocessor ]; diff --git a/ext/js/language/text-preprocessors.js b/ext/js/language/text-preprocessors.js index daf43abdc2..5ab57618b3 100755 --- a/ext/js/language/text-preprocessors.js +++ b/ext/js/language/text-preprocessors.js @@ -28,7 +28,7 @@ export const decapitalize = { name: 'Decapitalize text', description: 'CAPITALIZED TEXT → capitalized text', options: basicTextPreprocessorOptions, - transform: (str, setting) => setting ? str.toLowerCase() : str + process: (str, setting) => setting ? str.toLowerCase() : str }; /** @type {import('language').TextPreprocessor} */ @@ -37,6 +37,6 @@ export const capitalizeFirstLetter = { name: 'Capitalize first letter', description: 'lowercase text → Lowercase text', options: basicTextPreprocessorOptions, - transform: (str, setting) => setting ? str.charAt(0).toUpperCase() + str.slice(1) : str + process: (str, setting) => setting ? str.charAt(0).toUpperCase() + str.slice(1) : str }; diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js index f8d156b657..a02c6f79ae 100644 --- a/ext/js/language/translator.js +++ b/ext/js/language/translator.js @@ -449,9 +449,9 @@ export class Translator { } for (const {preprocessor} of textPreprocessors.values()) { - const {id, transform} = preprocessor; + const {id, process} = preprocessor; const setting = arrayVariant.get(id); - text2 = transform(text2, setting, sourceMap); + text2 = process(text2, setting, sourceMap); } for ( diff --git a/test/data/anki-note-builder-test-results.json b/test/data/anki-note-builder-test-results.json index cf6f0e45a5..85b71faa52 100644 --- a/test/data/anki-note-builder-test-results.json +++ b/test/data/anki-note-builder-test-results.json @@ -3731,6 +3731,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "English", "screenshot": "", @@ -3771,6 +3772,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "language", "screenshot": "", diff --git a/types/ext/language.d.ts b/types/ext/language.d.ts index 79aed18d8d..0effec80eb 100644 --- a/types/ext/language.d.ts +++ b/types/ext/language.d.ts @@ -28,7 +28,7 @@ export type TextPreprocessor = { name: string; description: string; options: TextPreprocessorOption[]; - transform: (str: string, setting: T, sourceMap?: TextSourceMap) => string; + process: (str: string, setting: T, sourceMap?: TextSourceMap) => string; }; export type Language = {