Skip to content

Commit

Permalink
Merge branch 'feature/main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
souhait0614 committed Jun 20, 2024
2 parents 206a3cc + 756a2ee commit d72cb04
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type {
ConverterConvertResultDetail,
ConverterConvertUsingPlugin,
ConverterOption,
ConvertFunction,
Plugin,
PluginConvertFunction,
} from "./types.ts";
import { defaultConverterOption } from "./constants.ts";

Expand Down Expand Up @@ -104,7 +104,7 @@ export class Converter<
} else {
tempPlugins[name as TPluginIDs] = {
convertFunctions: (extendConvertFunction?.(convertFunctions) ??
convertFunctions) as ConvertFunction[],
convertFunctions) as PluginConvertFunction<undefined>[],
};
}
},
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@
*/

export * from "./Converter.ts";
export type * from "./types.ts";
export type {
ConverterConvertOrder,
ConverterConvertResult,
ConverterConvertResultDetail,
ConverterOption,
Plugin,
PluginConvertFunction,
} from "./types.ts";
18 changes: 12 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { Promisable } from "type-fest";

export type ConvertFunction = (text: string) => Promisable<string>;
export type ConvertFunctionWithOption<
TOption extends object,
> = (text: string, option: Partial<TOption>) => Promisable<string>;
/** Pluginの文字列変換関数 */
export type PluginConvertFunction<
TOption extends object | undefined,
> = TOption extends object
? (text: string, option: TOption) => Promisable<string>
: (text: string) => Promisable<string>;

/**
* 文字列を加工して返却する関数やオプションの型
Expand All @@ -25,13 +27,14 @@ export type Plugin<
TOption extends object | undefined,
> = TOption extends object ? {
defaultOption: Required<TOption>;
convertFunctions: ConvertFunctionWithOption<TOption>[];
convertFunctions: PluginConvertFunction<TOption>[];
}
: {
defaultOption?: never;
convertFunctions: ConvertFunction[];
convertFunctions: PluginConvertFunction<undefined>[];
};

/** Converter本体のオプション */
export interface ConverterOption {
interruptWithPluginError?: boolean;
// TODO: エラー出力の制御オプションの追加
Expand All @@ -55,6 +58,7 @@ export type ConverterConvertUsingPlugin<
};
}[TPluginIDs];

/** Converter.convertで指定したPluginとPluginが使用したオプションの値 */
export type ConverterConvertOrder<
TPlugins extends Record<
string,
Expand Down Expand Up @@ -83,6 +87,7 @@ export type ConverterConvertOrderName<
: TUsingPlugin extends Extract<keyof TPlugins, string> ? TUsingPlugin
: never;

/** Converter.convertで指定したPluginごとの変換結果 */
export type ConverterConvertResultDetail<
TPlugins extends Record<
string,
Expand All @@ -99,6 +104,7 @@ export type ConverterConvertResultDetail<
convertedText: string;
};

/** Converter.convertの返り値 */
export interface ConverterConvertResult<
TPlugins extends Record<
string,
Expand Down

0 comments on commit d72cb04

Please sign in to comment.