Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
Util rename (#1389)
Browse files Browse the repository at this point in the history
* Rename MediaUtility to MediaUtil for consistency

* Update variable names

* Rename media-utility.js to media-util.js

* Rename ProfileConditions to ProfileConditionsUtil

* Rename variables

* Move profile-conditions.js to profile-conditions-util.js

* Rename test-profile-conditions.js to test-profile-conditions-util.js
  • Loading branch information
toasted-nutbread authored Feb 14, 2021
1 parent 0117df6 commit 5268c5d
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@
"ext/js/language/dictionary-database.js",
"ext/js/data/json-schema.js",
"ext/js/comm/mecab.js",
"ext/js/media/media-utility.js",
"ext/js/media/media-util.js",
"ext/js/data/options-util.js",
"ext/js/data/permissions-util.js",
"ext/js/background/profile-conditions.js",
"ext/js/background/profile-conditions-util.js",
"ext/js/background/request-builder.js",
"ext/js/dom/simple-dom-parser.js",
"ext/js/templates/template-patcher.js",
Expand Down
4 changes: 2 additions & 2 deletions ext/background.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
<script src="/js/language/dictionary-database.js"></script>
<script src="/js/data/json-schema.js"></script>
<script src="/js/comm/mecab.js"></script>
<script src="/js/media/media-utility.js"></script>
<script src="/js/media/media-util.js"></script>
<script src="/js/data/options-util.js"></script>
<script src="/js/data/permissions-util.js"></script>
<script src="/js/background/profile-conditions.js"></script>
<script src="/js/background/profile-conditions-util.js"></script>
<script src="/js/background/request-builder.js"></script>
<script src="/js/dom/native-simple-dom-parser.js"></script>
<script src="/js/templates/template-patcher.js"></script>
Expand Down
16 changes: 8 additions & 8 deletions ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
* JapaneseUtil
* JsonSchemaValidator
* Mecab
* MediaUtility
* MediaUtil
* ObjectPropertyAccessor
* OptionsUtil
* PermissionsUtil
* ProfileConditions
* ProfileConditionsUtil
* RequestBuilder
* Translator
* wanakana
Expand All @@ -46,13 +46,13 @@ class Backend {
});
this._anki = new AnkiConnect();
this._mecab = new Mecab();
this._mediaUtility = new MediaUtility();
this._mediaUtil = new MediaUtil();
this._clipboardReader = new ClipboardReader({
// eslint-disable-next-line no-undef
document: (typeof document === 'object' && document !== null ? document : null),
pasteTargetSelector: '#clipboard-paste-target',
imagePasteTargetSelector: '#clipboard-image-paste-target',
mediaUtility: this._mediaUtility
mediaUtil: this._mediaUtil
});
this._clipboardMonitor = new ClipboardMonitor({
japaneseUtil: this._japaneseUtil,
Expand All @@ -61,7 +61,7 @@ class Backend {
this._options = null;
this._profileConditionsSchemaValidator = new JsonSchemaValidator();
this._profileConditionsSchemaCache = [];
this._profileConditionsUtil = new ProfileConditions();
this._profileConditionsUtil = new ProfileConditionsUtil();
this._defaultAnkiFieldTemplates = null;
this._requestBuilder = new RequestBuilder();
this._audioDownloader = new AudioDownloader({
Expand Down Expand Up @@ -1707,7 +1707,7 @@ class Backend {
return null;
}

let extension = this._mediaUtility.getFileExtensionFromAudioMediaType(contentType);
let extension = this._mediaUtil.getFileExtensionFromAudioMediaType(contentType);
if (extension === null) { extension = '.mp3'; }
let fileName = this._generateAnkiNoteMediaFileName('yomichan_audio', extension, timestamp, definitionDetails);
fileName = fileName.replace(/\]/g, '');
Expand All @@ -1721,7 +1721,7 @@ class Backend {
const dataUrl = await this._getScreenshot(tabId, frameId, format, quality);

const {mediaType, data} = this._getDataUrlInfo(dataUrl);
const extension = this._mediaUtility.getFileExtensionFromImageMediaType(mediaType);
const extension = this._mediaUtil.getFileExtensionFromImageMediaType(mediaType);
if (extension === null) {
throw new Error('Unknown media type for screenshot image');
}
Expand All @@ -1739,7 +1739,7 @@ class Backend {
}

const {mediaType, data} = this._getDataUrlInfo(dataUrl);
const extension = this._mediaUtility.getFileExtensionFromImageMediaType(mediaType);
const extension = this._mediaUtil.getFileExtensionFromImageMediaType(mediaType);
if (extension === null) {
throw new Error('Unknown media type for clipboard image');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* Utility class to help processing profile conditions.
*/
class ProfileConditions {
class ProfileConditionsUtil {
/**
* Creates a new instance.
*/
Expand Down
8 changes: 4 additions & 4 deletions ext/js/comm/clipboard-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class ClipboardReader {
* @param pasteTargetSelector The selector for the paste target element.
* @param imagePasteTargetSelector The selector for the image paste target element.
*/
constructor({document=null, pasteTargetSelector=null, imagePasteTargetSelector=null, mediaUtility=null}) {
constructor({document=null, pasteTargetSelector=null, imagePasteTargetSelector=null, mediaUtil=null}) {
this._document = document;
this._browser = null;
this._pasteTarget = null;
this._pasteTargetSelector = pasteTargetSelector;
this._imagePasteTarget = null;
this._imagePasteTargetSelector = imagePasteTargetSelector;
this._mediaUtility = mediaUtility;
this._mediaUtil = mediaUtil;
}

/**
Expand Down Expand Up @@ -107,7 +107,7 @@ class ClipboardReader {
// See browser-specific notes in getText
if (
this._isFirefox() &&
this._mediaUtility !== null &&
this._mediaUtil !== null &&
typeof navigator.clipboard !== 'undefined' &&
typeof navigator.clipboard.read === 'function'
) {
Expand All @@ -120,7 +120,7 @@ class ClipboardReader {
}

for (const file of files) {
if (this._mediaUtility.getFileExtensionFromImageMediaType(file.type) !== null) {
if (this._mediaUtil.getFileExtensionFromImageMediaType(file.type) !== null) {
return await this._readFileAsDataURL(file);
}
}
Expand Down
6 changes: 3 additions & 3 deletions ext/js/language/dictionary-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
/* global
* JSZip
* JsonSchemaValidator
* MediaUtility
* MediaUtil
*/

class DictionaryImporter {
constructor() {
this._schemas = new Map();
this._jsonSchemaValidator = new JsonSchemaValidator();
this._mediaUtility = new MediaUtility();
this._mediaUtil = new MediaUtil();
}

async importDictionary(dictionaryDatabase, archiveSource, details, onProgress) {
Expand Down Expand Up @@ -325,7 +325,7 @@ class DictionaryImporter {
}

const content = await file.async('base64');
const mediaType = this._mediaUtility.getImageMediaTypeFromFileName(path);
const mediaType = this._mediaUtil.getImageMediaTypeFromFileName(path);
if (mediaType === null) {
throw new Error(`Could not determine media type for image at path ${JSON.stringify(path)} for ${errorSource}`);
}
Expand Down
4 changes: 2 additions & 2 deletions ext/js/media/media-utility.js → ext/js/media/media-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/

/**
* MediaUtility is a class containing helper methods related to media processing.
* MediaUtil is a class containing helper methods related to media processing.
*/
class MediaUtility {
class MediaUtil {
/**
* Gets the file extension of a file path. URL search queries and hash
* fragments are not handled.
Expand Down
2 changes: 1 addition & 1 deletion ext/settings-old.html
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ <h3>Support Development</h3>
<script src="/js/language/dictionary-database.js"></script>
<script src="/js/language/dictionary-importer.js"></script>
<script src="/js/data/json-schema.js"></script>
<script src="/js/media/media-utility.js"></script>
<script src="/js/media/media-util.js"></script>
<script src="/js/data/permissions-util.js"></script>
<script src="/js/templates/template-patcher.js"></script>
<script src="/js/templates/template-renderer-proxy.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion ext/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -3218,7 +3218,7 @@ <h2></h2>
<script src="/js/language/dictionary-database.js"></script>
<script src="/js/language/dictionary-importer.js"></script>
<script src="/js/data/json-schema.js"></script>
<script src="/js/media/media-utility.js"></script>
<script src="/js/media/media-util.js"></script>
<script src="/js/data/permissions-util.js"></script>
<script src="/js/templates/template-patcher.js"></script>
<script src="/js/templates/template-renderer-proxy.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions ext/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ self.importScripts(
'/js/language/dictionary-database.js',
'/js/data/json-schema.js',
'/js/comm/mecab.js',
'/js/media/media-utility.js',
'/js/media/media-util.js',
'/js/data/options-util.js',
'/js/data/permissions-util.js',
'/js/background/profile-conditions.js',
'/js/background/profile-conditions-util.js',
'/js/background/request-builder.js',
'/js/dom/simple-dom-parser.js',
'/js/templates/template-patcher.js',
Expand Down
2 changes: 1 addition & 1 deletion ext/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ <h2>Basic customization</h2>
<script src="/js/language/dictionary-database.js"></script>
<script src="/js/language/dictionary-importer.js"></script>
<script src="/js/data/json-schema.js"></script>
<script src="/js/media/media-utility.js"></script>
<script src="/js/media/media-util.js"></script>
<script src="/js/data/permissions-util.js"></script>

<script src="/js/settings/dictionary-controller.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion test/test-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ vm.execute([
'js/core.js',
'js/general/cache-map.js',
'js/data/json-schema.js',
'js/media/media-utility.js',
'js/media/media-util.js',
'js/language/dictionary-importer.js',
'js/data/database.js',
'js/language/dictionary-database.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ vm.execute([
'js/core.js',
'js/general/cache-map.js',
'js/data/json-schema.js',
'js/background/profile-conditions.js'
'js/background/profile-conditions-util.js'
]);
const [JsonSchemaValidator, ProfileConditions] = vm.get(['JsonSchemaValidator', 'ProfileConditions']);
const [JsonSchemaValidator, ProfileConditionsUtil] = vm.get(['JsonSchemaValidator', 'ProfileConditionsUtil']);


function schemaValidate(value, schema) {
Expand Down Expand Up @@ -63,8 +63,8 @@ function testNormalizeContext() {
];

for (const {context, expected} of data) {
const profileConditions = new ProfileConditions();
const actual = profileConditions.normalizeContext(context);
const profileConditionsUtil = new ProfileConditionsUtil();
const actual = profileConditionsUtil.normalizeContext(context);
vm.assert.deepStrictEqual(actual, expected);
}
}
Expand Down Expand Up @@ -818,14 +818,14 @@ function testSchemas() {
];

for (const {conditionGroups, expectedSchema, inputs} of data) {
const profileConditions = new ProfileConditions();
const schema = profileConditions.createSchema(conditionGroups);
const profileConditionsUtil = new ProfileConditionsUtil();
const schema = profileConditionsUtil.createSchema(conditionGroups);
if (typeof expectedSchema !== 'undefined') {
vm.assert.deepStrictEqual(schema, expectedSchema);
}
if (Array.isArray(inputs)) {
for (const {expected, context} of inputs) {
const normalizedContext = profileConditions.normalizeContext(context);
const normalizedContext = profileConditionsUtil.normalizeContext(context);
const actual = schemaValidate(normalizedContext, schema);
assert.strictEqual(actual, expected);
}
Expand Down
2 changes: 1 addition & 1 deletion test/test-translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function createVM() {
'js/general/cache-map.js',
'js/language/japanese-util.js',
'js/data/json-schema.js',
'js/media/media-utility.js',
'js/media/media-util.js',
'js/language/dictionary-importer.js',
'js/data/database.js',
'js/language/dictionary-database.js',
Expand Down

0 comments on commit 5268c5d

Please sign in to comment.