Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

別パッケージ化 #5

Open
github-actions bot opened this issue Nov 28, 2023 · 0 comments
Open

別パッケージ化 #5

github-actions bot opened this issue Nov 28, 2023 · 0 comments
Assignees
Labels

Comments

@github-actions
Copy link
Contributor

import childProcess from "child_process";
import * as deepl from "deepl-node";
import { env } from "~/env";

/* c8 ignore start */

// TODO 別パッケージ化
export const say = (p: { text: string }) =>
  childProcess.exec(`say -v Samantha "${p.text}"`);

// TODO 別パッケージ化
const translator = new deepl.Translator(env.DEEPL_API_KEY);
export const translateText = (
  ...p: Parameters<typeof translator.translateText<string>>
) => translator.translateText(...p);

// TODO 別パッケージ化
const regExp = new RegExp(/^[a-zA-Z0-9!-/:-@¥[-`{-~ ]*$/);
const maybeEnglish = (p: { text: string }) => regExp.test(p.text);

// TODO 別パッケージ化
export const cmdA = () =>
  childProcess.exec(
    `osascript -e 'tell application "System Events" to keystroke "a" using {command down}'`,
  );
/* c8 ignore stop */

export const getTranslateTextParam = (p: { text: string }) => {
  const [sourceLang, targetLang] = maybeEnglish({
    text: p.text,
  })
    ? (["en", "ja"] as const)
    : (["ja", "en-US"] as const);

  return {
    sourceLang,
    targetLang,
  };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant