{{
- mapUndefinedPipe(
+ mapNullablePipe(
engineInfos.get(selectedInfo.engine),
(v) => v.characterInfos,
- (v) => mapUndefinedPipe(selectedInfo, (i) => v.get(i.character)),
+ (v) => mapNullablePipe(selectedInfo, (i) => v.get(i.character)),
(v) => v.metas.speakerName
)
}}
@@ -73,7 +73,7 @@ import { computed, ref } from "vue";
import { useStore } from "@/store";
import { useMarkdownIt } from "@/plugins/markdownItPlugin";
import { EngineId, SpeakerId } from "@/type/preload";
-import { mapUndefinedPipe } from "@/helpers/map";
+import { mapNullablePipe } from "@/helpers/map";
type DetailKey = { engine: EngineId; character: SpeakerId };
diff --git a/src/helpers/SelectionHelperForQInput.ts b/src/helpers/SelectionHelperForQInput.ts
index 18fb20dee6..c1b28edd66 100644
--- a/src/helpers/SelectionHelperForQInput.ts
+++ b/src/helpers/SelectionHelperForQInput.ts
@@ -11,7 +11,7 @@ export class SelectionHelperForQInput {
// this.start が number | null なので null も受け付ける
setCursorPosition(index: number | null) {
- if (index === null) return;
+ if (index == undefined) return;
this.nativeEl.selectionStart = this.nativeEl.selectionEnd = index;
}
@@ -50,7 +50,7 @@ export class SelectionHelperForQInput {
get isEmpty() {
const start = this.nativeEl.selectionStart;
const end = this.nativeEl.selectionEnd;
- return start === null || end === null || start === end;
+ return start == undefined || end == undefined || start === end;
}
private get nativeEl() {
diff --git a/src/helpers/map.ts b/src/helpers/map.ts
index 3b2d170b87..9770c7773a 100644
--- a/src/helpers/map.ts
+++ b/src/helpers/map.ts
@@ -1,36 +1,36 @@
-export function mapUndefinedPipe
(
+export function mapNullablePipe(
source: T | undefined,
fn1: (_: NonNullable) => U1 | undefined
): U1 | undefined;
-export function mapUndefinedPipe(
+export function mapNullablePipe(
source: T | undefined,
fn1: (_: NonNullable) => U1 | undefined,
fn2: (_: NonNullable) => U2 | undefined
): U2 | undefined;
-export function mapUndefinedPipe(
+export function mapNullablePipe(
source: T | undefined,
fn1: (_: NonNullable) => U1 | undefined,
fn2: (_: NonNullable) => U2 | undefined,
fn3: (_: NonNullable) => U3 | undefined
): U3 | undefined;
/**
- * 一連の関数を実行する。途中でundefinedを返すとその後undefinedを返す。
+ * 一連の関数を実行する。途中でundefinedかnullを返すとその後undefinedを返す。
*/
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-explicit-any
-export function mapUndefinedPipe(source: any, ...fn: Function[]) {
+export function mapNullablePipe(source: any, ...fn: Function[]) {
return fn.reduce((prev, curr) => {
- if (prev === undefined) {
+ if (prev == undefined) {
return undefined;
}
return curr(prev);
}, source);
}
-export const undefinedToDefault = (
+export const nullableToDefault = (
defaultValue: T,
maybeValue: T | undefined
): T => {
- if (maybeValue === undefined) {
+ if (maybeValue == undefined) {
return defaultValue;
}
return maybeValue;
diff --git a/src/helpers/previewSliderHelper.ts b/src/helpers/previewSliderHelper.ts
index fff7ae0106..bebb497cf6 100644
--- a/src/helpers/previewSliderHelper.ts
+++ b/src/helpers/previewSliderHelper.ts
@@ -112,7 +112,7 @@ export const previewSliderHelper = (props: Props): PreviewSliderHelper => {
previewValue.value = value;
};
const changePreviewValue = async () => {
- if (previewValue.value === null)
+ if (previewValue.value == null)
throw new Error("previewValue.value === null");
if (modelValue.value !== previewValue.value && props.onChange) {
await props.onChange(previewValue.value);
@@ -128,7 +128,7 @@ export const previewSliderHelper = (props: Props): PreviewSliderHelper => {
};
// start awaiting
const fireChange = () => {
- if (awaitingChange !== null) awaitingChange.cancel();
+ if (awaitingChange != null) awaitingChange.cancel();
isAwaiting.value = true;
awaitingChange = new CancelableFinary(changePreviewValue(), endAwaiting);
};
@@ -165,7 +165,7 @@ export const previewSliderHelper = (props: Props): PreviewSliderHelper => {
);
// This function is called when the q-slider fire onWheel.
const onWheel = (event: Events["onWheel"]) => {
- if (disableScroll.value || disable.value || currentValue.value === null)
+ if (disableScroll.value || disable.value || currentValue.value == null)
return;
event.preventDefault();
const deltaY = event.deltaY;
diff --git a/src/infrastructures/EngineConnector.ts b/src/infrastructures/EngineConnector.ts
index 55f4d4e8a7..7ddede8273 100644
--- a/src/infrastructures/EngineConnector.ts
+++ b/src/infrastructures/EngineConnector.ts
@@ -11,7 +11,7 @@ const OpenAPIEngineConnectorFactoryImpl = (): IEngineConnectorFactory => {
return {
instance: (host: string) => {
const cached = instanceMapper[host];
- if (cached !== undefined) {
+ if (cached != undefined) {
return cached;
}
const api = new DefaultApi(new Configuration({ basePath: host }));
diff --git a/src/store/audioPlayer.ts b/src/store/audioPlayer.ts
index 966a6f1429..7785b2b814 100644
--- a/src/store/audioPlayer.ts
+++ b/src/store/audioPlayer.ts
@@ -23,7 +23,7 @@ export const audioPlayerStoreState: AudioPlayerStoreState = {
export const audioPlayerStore = createPartialStore({
ACTIVE_AUDIO_ELEM_CURRENT_TIME: {
getter: (state) => {
- return state._activeAudioKey !== undefined
+ return state._activeAudioKey != undefined
? getAudioElement().currentTime
: undefined;
},
@@ -61,7 +61,7 @@ export const audioPlayerStore = createPartialStore({
) {
const audioElement = getAudioElement();
- if (offset !== undefined) {
+ if (offset != undefined) {
audioElement.currentTime = offset;
}
diff --git a/src/store/dictionary.ts b/src/store/dictionary.ts
index c6a3108c14..d5e035520f 100644
--- a/src/store/dictionary.ts
+++ b/src/store/dictionary.ts
@@ -67,7 +67,7 @@ export const dictionaryStore = createPartialStore({
// 同じ単語IDで登録するために、1つのエンジンで登録したあと全エンジンに同期する。
const engineId: EngineId | undefined = state.engineIds[0];
- if (engineId === undefined)
+ if (engineId == undefined)
throw new Error(`No such engine registered: index == 0`);
await dispatch("INSTANTIATE_ENGINE_CONNECTOR", {
engineId,
diff --git a/src/store/engine.ts b/src/store/engine.ts
index b20a5cc61c..b41c042f89 100644
--- a/src/store/engine.ts
+++ b/src/store/engine.ts
@@ -148,7 +148,7 @@ export const engineStore = createPartialStore({
IS_ENGINE_READY: {
getter: (state) => (engineId) => {
const engineState: EngineState | undefined = state.engineStates[engineId];
- if (engineState === undefined)
+ if (engineState == undefined)
throw new Error(`No such engineState set: engineId == ${engineId}`);
return engineState === "READY";
@@ -159,12 +159,12 @@ export const engineStore = createPartialStore({
action: createUILockAction(
async ({ state, commit, dispatch }, { engineId }) => {
let engineState: EngineState | undefined = state.engineStates[engineId];
- if (engineState === undefined)
+ if (engineState == undefined)
throw new Error(`No such engineState set: engineId == ${engineId}`);
for (let i = 0; i < 100; i++) {
engineState = state.engineStates[engineId]; // FIXME: explicit undefined
- if (engineState === undefined)
+ if (engineState == undefined)
throw new Error(`No such engineState set: engineId == ${engineId}`);
if (engineState === "FAILED_STARTING") {
@@ -268,7 +268,7 @@ export const engineStore = createPartialStore({
DETECTED_ENGINE_ERROR: {
action({ state, commit }, { engineId }) {
const engineState: EngineState | undefined = state.engineStates[engineId];
- if (engineState === undefined)
+ if (engineState == undefined)
throw new Error(`No such engineState set: engineId == ${engineId}`);
switch (engineState) {
diff --git a/src/store/index.ts b/src/store/index.ts
index eca0e6dbba..271108925b 100644
--- a/src/store/index.ts
+++ b/src/store/index.ts
@@ -194,7 +194,7 @@ export const indexStore = createPartialStore({
const defaultStyleId = defaultStyleIds.find(
(styleId) => styleId.speakerUuid == speakerUuid
);
- if (defaultStyleId === undefined) {
+ if (defaultStyleId == undefined) {
return true;
}
@@ -244,7 +244,7 @@ export const indexStore = createPartialStore({
audioItem.voice.styleId
);
- if (characterInfo === undefined)
+ if (characterInfo == undefined)
throw new Error("assert characterInfo !== undefined");
const speakerUuid = characterInfo.metas.speakerUuid;
diff --git a/src/store/preset.ts b/src/store/preset.ts
index 97fadd75fe..98817ee04f 100644
--- a/src/store/preset.ts
+++ b/src/store/preset.ts
@@ -134,9 +134,9 @@ export const presetStore = createPartialStore({
const presetConfig = await window.electron.getSetting("presets");
if (
- presetConfig === undefined ||
- presetConfig.items === undefined ||
- presetConfig.keys === undefined
+ presetConfig == undefined ||
+ presetConfig.items == undefined ||
+ presetConfig.keys == undefined
)
return;
commit("SET_PRESET_ITEMS", {
diff --git a/src/store/project.ts b/src/store/project.ts
index 3c3053ee13..9152f7ebcd 100755
--- a/src/store/project.ts
+++ b/src/store/project.ts
@@ -175,7 +175,7 @@ export const projectStore = createPartialStore({
// set phoneme length
// 0.7 未満のプロジェクトファイルは styleId ではなく characterIndex なので、ここだけ characterIndex とした
- if (audioItem.characterIndex === undefined)
+ if (audioItem.characterIndex == undefined)
throw new Error("audioItem.characterIndex === undefined");
await context
.dispatch("FETCH_MORA_DATA", {
@@ -227,7 +227,7 @@ export const projectStore = createPartialStore({
) {
for (const audioItemsKey in projectData.audioItems) {
const audioItem = projectData.audioItems[audioItemsKey];
- if (audioItem.speaker !== null) {
+ if (audioItem.speaker != null) {
audioItem.styleId = audioItem.speaker;
delete audioItem.speaker;
}
@@ -239,7 +239,7 @@ export const projectStore = createPartialStore({
) {
for (const audioItemsKey in projectData.audioItems) {
const audioItem = projectData.audioItems[audioItemsKey];
- if (audioItem.engineId === undefined) {
+ if (audioItem.engineId == undefined) {
audioItem.engineId = engineId;
}
}
diff --git a/src/store/proxy.ts b/src/store/proxy.ts
index b10de3d7e3..26861d2931 100644
--- a/src/store/proxy.ts
+++ b/src/store/proxy.ts
@@ -15,7 +15,7 @@ const proxyStoreCreator = (_engineFactory: IEngineConnectorFactory) => {
action({ state }, payload) {
const engineId = payload.engineId;
const engineInfo: EngineInfo | undefined = state.engineInfos[engineId];
- if (engineInfo === undefined)
+ if (engineInfo == undefined)
return Promise.reject(
new Error(`No such engineInfo registered: engineId == ${engineId}`)
);
diff --git a/src/store/utility.ts b/src/store/utility.ts
index 0c5d4ce5dc..6d1d0385de 100644
--- a/src/store/utility.ts
+++ b/src/store/utility.ts
@@ -145,7 +145,7 @@ function replaceTag(
): string {
const result = template.replace(/\$(.+?)\$/g, (match, p1) => {
const replaceTagId = replaceTagStringToTagId[p1];
- if (replaceTagId === undefined) {
+ if (replaceTagId == undefined) {
return match;
}
return replacer[replaceTagId] ?? "";
diff --git a/src/type/result.ts b/src/type/result.ts
index 49b9da9b77..1b2f2b2bf4 100644
--- a/src/type/result.ts
+++ b/src/type/result.ts
@@ -78,7 +78,7 @@ export const failure: Failure = (
error: codeOrError,
};
} else if (codeOrError == undefined || typeof codeOrError === "string") {
- if (error === undefined) {
+ if (error == undefined) {
throw new Error("Error must be specified");
}
return { ok: false as const, code: codeOrError, error };
diff --git a/tests/unit/lib/map.spec.ts b/tests/unit/lib/map.spec.ts
index dd5c93a1ad..57ef246c48 100644
--- a/tests/unit/lib/map.spec.ts
+++ b/tests/unit/lib/map.spec.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
-import { mapUndefinedPipe, undefinedToDefault } from "@/helpers/map";
+import { mapNullablePipe, nullableToDefault } from "@/helpers/map";
type DummyType = {
outerValue?: {
@@ -19,7 +19,7 @@ describe("mapUndefinedPipe", () => {
};
const map = new Map([[key, value]]);
expect(
- mapUndefinedPipe(
+ mapNullablePipe(
map.get(key),
(v) => v.outerValue,
(v) => v.innerValue
@@ -36,7 +36,7 @@ describe("mapUndefinedPipe", () => {
};
const map = new Map([[key, value]]);
expect(
- mapUndefinedPipe(
+ mapNullablePipe(
map.get(key),
(v) => v.outerValue,
(v) => v.innerValue
@@ -48,16 +48,11 @@ describe("mapUndefinedPipe", () => {
describe("undefinedToDefault", () => {
it("値がある時はそのまま返す", () => {
const actualValue = "value";
- expect(undefinedToDefault("test", actualValue)).toEqual(actualValue);
+ expect(nullableToDefault("test", actualValue)).toEqual(actualValue);
});
it("値がない時はdefaultValueを返す", () => {
const defaultValue = "test";
- expect(undefinedToDefault(defaultValue, undefined)).toEqual(defaultValue);
- });
-
- it("undefinedのみを値がない状態とみなす", () => {
- const defaultValue = "test";
- expect(undefinedToDefault(defaultValue, null)).toBeNull();
+ expect(nullableToDefault(defaultValue, undefined)).toEqual(defaultValue);
});
});